Repository navigation
security(export): neutralize formula injection in revenue report CSV … - #981
Merged
thlpkee20-wq merged 2 commits intoOct 22, 2026
Conversation
…export - Harden escapeCsvCell and sanitizeCsvCell by prepending a single quote to cells beginning with '=', '+', '-', '@', TAB, or CR before applying RFC-4180 quoting rules - Ensure numeric amount columns generated by the exporter remain numeric while user string fields are safely sanitized - Export escapeCsvCell, sanitizeCsvCell, and associated types for reuse - Add unit and regression tests in src/utils/reportExport.test.ts
|
@CiiscoTech-Hub Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
pr Closes #915
Pull Request Description
Title
security(export): neutralize formula injection in revenue report CSV export (CWE-1236)
Summary
Resolves spreadsheet formula injection (CSV injection, CWE-1236) in the revenue report exporter utility (src/utils/reportExport.ts). Previously, escapeCsvCell only quoted cells containing ", ,, \r, or \n. Free-text fields such as report notes were exported without prefix sanitization, allowing inputs starting with formula triggers (=, +, -, @, \t, \r) to execute when opened in spreadsheet software (Excel, Google Sheets).
Changes
Sanitize Dangerous Prefixes:
Hardened escapeCsvCell and exported sanitizeCsvCell: if a string field starts with =, +, -, @, \t (TAB), or \r (CR), it is prepended with a single quote ('), followed by RFC-4180 quoting rules.
Preserve Numeric Amount Columns:
Differentiated numeric amount columns generated by the exporter (such as "Gross revenue" and "Estimated payout") from user-provided string columns. Negative numbers emitted by code remain numeric and are not prefixed with ', while string/user-controlled fields starting with - or other dangerous prefixes are neutralised.
Added ToCsvOptions and EscapeCsvCellOptions interfaces so other CSV writers can configure and reuse escapeCsvCell and sanitizeCsvCell.
Automated & Regression Tests:
Added focused unit tests in src/utils/reportExport.test.ts:
Verified each dangerous prefix (=, +, -, @, \t, \r) is neutralized.
Verified plain text and quoted text behavior remain unchanged.
Verified numeric amount columns remain unchanged and retain valid negative numeric formatting.
Added regression test for CWE-1236 ensuring payload notes such as =HYPERLINK("http://example.invalid","click") are treated as literal text.
Verification
Ran Vitest suite on src/utils/reportExport.test.ts (17/17 tests passing).
Ran Vitest suite on src/components/RevenueReportForm.test.tsx (6/6 tests passing).
Ran ESLint on modified files with zero errors or warnings.