fix(export_csv): neutralize CSV/formula injection in exported cells (CWE-1236)#83
Open
gadievron wants to merge 1 commit into
Open
Conversation
…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>
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.
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