Skip to content

fix(export_csv): neutralize CSV/formula injection in exported cells (CWE-1236)#83

Open
gadievron wants to merge 1 commit into
masterfrom
fix/export-csv-neutralize-csv-formula-injection-in-exported
Open

fix(export_csv): neutralize CSV/formula injection in exported cells (CWE-1236)#83
gadievron wants to merge 1 commit into
masterfrom
fix/export-csv-neutralize-csv-formula-injection-in-exported

Conversation

@gadievron
Copy link
Copy Markdown
Collaborator

export_csv() wrote the verbatim scanned source (unit_code) and LLM-derived text
columns into the CSV with no neutralization. A scanned snippet beginning with =,
+, -, @ (or a leading tab/CR) is treated as a formula by Excel / Google Sheets
when the analyst opens the export, enabling formula execution / data
exfiltration on the analyst's machine (OWASP CSV Injection / CWE-1236).

Add a _csv_safe() helper that prefixes any cell whose first character is a
formula trigger with a single quote, applied to every cell before writing.

The payload originates in the scanned (untrusted) source and only fires in a
downstream spreadsheet app -- it is not reachable from OpenAnt's own callers --
so this is output hardening / defense-in-depth, not an exploitable-now
vulnerability. It is a real producer-side output-sanitization gap (CWE-1236),
distinct from the "OpenAnt processing hostile input" class.

Tests: tests/test_export_csv_formula_injection.py (2 cases: _csv_safe
neutralizes =/+/-/@/tab/CR and leaves safe cells unchanged; export_csv
neutralizes a formula unit_code end-to-end). RED 2 failed -> GREEN 2 passed
(py3.11).

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

…CWE-1236)

export_csv() wrote the verbatim scanned source (unit_code) and LLM-derived text
columns into the CSV with no neutralization. A scanned snippet beginning with =,
+, -, @ (or a leading tab/CR) is treated as a formula by Excel / Google Sheets
when the analyst opens the export, enabling formula execution / data
exfiltration on the analyst's machine (OWASP CSV Injection / CWE-1236).

Add a _csv_safe() helper that prefixes any cell whose first character is a
formula trigger with a single quote, applied to every cell before writing.

The payload originates in the scanned (untrusted) source and only fires in a
downstream spreadsheet app -- it is not reachable from OpenAnt's own callers --
so this is output hardening / defense-in-depth, not an exploitable-now
vulnerability. It is a real producer-side output-sanitization gap (CWE-1236),
distinct from the "OpenAnt processing hostile input" class.

Tests: tests/test_export_csv_formula_injection.py (2 cases: _csv_safe
neutralizes =/+/-/@/tab/CR and leaves safe cells unchanged; export_csv
neutralizes a formula unit_code end-to-end). RED 2 failed -> GREEN 2 passed
(py3.11).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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