Bypassing CSV injection using new line charcter
The CSV escaping function could be bypassed by placing a newline character before a formula, so a value that should have been neutralised could still be treated as a spreadsheet formula. The reporter notes it did not work in practice because the checkout form handler strips newlines before the escaping function runs.
- Triaged in 18 days
- Fixed in 54 days
- Paid in 41 days
- Disclosed after 56 days
Summary by the program
white_walker reported that esc_csv() could be bypassed by using %0A-3+3+cmd|' /C calc'!D2 as the payload.
For example, the first_name parameter in the following request:
curl -ik 'https://2016.misc.wordcamp.dev/tickets/?tix_action=checkout#tix' -H 'Host: 2016.misc.wordcamp.dev' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:50.0) Gecko/20100101 Firefox/50.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://2016.misc.wordcamp.dev/tickets/?tix_action=attendee_info' -H 'Cookie: [redacted]' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' --data 'tix_tickets_selected%5B2415%5D=1&tix_attendee_info%5B1%5D%5Bticket_id%5D=2415&tix_attendee_info%5B1%5D%5Bfirst_name%5D=%0A-3%2B3%2Bcmd%7C%27+%2FC+calc%27%21D2&tix_attendee_info%5B1%5D%5Blast_name%5D=%0A,another&tix_attendee_info%5B1%5D%5Bemail%5D=ian.dunn%40foo.com&tix_receipt_email=1&tix_attendee_questions%5B1%5D%5B2472%5D=small&tix_attendee_questions%5B1%5D%5B2547%5D=&tix_attendee_questions%5B1%5D%5B2586%5D=&tix_attendee_questions%5B1%5D%5B43011%5D=Abkhazia&tix_attendee_questions%5B1%5D%5B43013%5D=Abkhazia'
That didn't work in practice, because the sanitization in form_checkout() strips newline characters, but it did reveal a bug in esc_csv() that could be exploited if it were ever called by a function that didn't strip newlines first.
Newlines being interpreted as cell delimiters may only happen with certain OS locales configured, or in certain versions of Excel.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the CSV escaping routine did not account for newline characters acting as cell delimiters, so a formula placed after a newline escaped the escaping logic.
Impact
The bypass did not work in practice because newlines were stripped earlier, but it could be exploited if the escaping function were ever called without that stripping, and only in some locales or spreadsheet versions.
What the attacker needed
A form field that reaches CSV export; newlines not stripped before escaping; spreadsheet opens the export
The fix
The escaping function should be fixed to handle newline characters as cell delimiters.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a website exports data to a spreadsheet file, a cell starting with a formula character can make the spreadsheet run a command on the user's computer. The site tried to block this by escaping such values, but the reporter found a way around the escaping by putting a line break first. In this case the normal form processing removed line breaks, so the trick could not actually be used there.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.