Neutralize spreadsheet formula characters in CSV export - #916
Open
carfeii wants to merge 1 commit into
Open
Conversation
CsvExporter::serialize wrote the benchmarked command name and every --parameter-list/--parameter-scan value directly into CSV cells with no protection against spreadsheet formula interpretation. Excel, LibreOffice Calc, and Google Sheets all treat a cell beginning with =, +, -, or @ as a formula to evaluate on open, independent of the file's .csv extension. Since both the command string and any parameter value can be attacker-influenced (for example, a benchmark parameterized over externally-submitted names), an exported CSV given to someone else to review could execute an attacker-chosen formula the moment they open it. Add neutralize_formula, which prefixes a value with a single quote if it begins with a formula-triggering character (=, +, -, @, tab, or carriage return), and use it for both the command field and every parameter value. This is the standard mitigation for CWE-1236. See sharkdp#915.
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.
Fixes #915.
Summary
CsvExporter::serialize(src/export/csv.rs) writes the benchmarkedcommand name and every
--parameter-list/--parameter-scanvaluedirectly into CSV cells with no protection against spreadsheet formula
interpretation. Excel, LibreOffice Calc, and Google Sheets all treat a
cell beginning with
=,+,-, or@as a formula to evaluate onopen, independent of the file's
.csvextension. Since both the commandstring and any parameter value can be attacker-influenced (for example, a
benchmark parameterized over externally-submitted names in a CI job), an
exported CSV given to someone else to review could execute an
attacker-chosen formula the moment they open it. This is CWE-1236.
Fix
Adds
neutralize_formula, which prefixes a value with a single quote ifit begins with a formula-triggering character (
=,+,-,@, tab, orcarriage return), so spreadsheet applications display it as literal text
instead of evaluating it. Applied to both the command field and every
parameter value in
CsvExporter::serialize. This is the standardmitigation for CWE-1236.
Testing
cargo test --releasepasses in full across all suites (unit,common,execution_order_tests,integration_tests).test_csv_formula_injection_is_neutralized, asserting a commandstarting with
=and a parameter value starting with@are bothprefixed with a single quote in the exported CSV.
hyperfine --parameter-list payload '=1+1' --export-csv out.csv -- 'echo hi {payload}', confirmed the raw file contained the literal,unescaped text
=1+1, then converted it with LibreOffice Calc headless(
soffice --headless --calc --convert-to ods, then back to CSV) andconfirmed the cell evaluated to
2. Repeated the same steps againstthis branch: the raw file now contains
'=1+1, and the value survivesthe LibreOffice round-trip unchanged (still
'=1+1), confirming it isdisplayed as text rather than evaluated.