Escape spreadsheet formulas in CSV export - #918
Open
MsfPablo wants to merge 1 commit into
Open
Conversation
Command names and parameter values starting with '=', '+', '-', '@', tab or carriage return are interpreted as formulas by Excel, LibreOffice Calc and Google Sheets when the exported CSV is opened. Prefix such values with a single quote so they are displayed as literal text (CWE-1236). Closes 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.
--export-csvwrites the command name and every parameter value verbatim. Excel, LibreOffice Calc and Google Sheets evaluate a cell starting with=,+,-,@, tab or CR as a formula when the file is opened, so a benchmark parameterized over externally-supplied values produces a CSV that runs an attacker-chosen formula for whoever opens it (CWE-1236).This applies the standard mitigation: such values get a leading single quote so spreadsheets show them as literal text. Numeric columns are generated internally and are untouched, and values not starting with one of those characters are written exactly as before, so existing CSV consumers see no change.
Before:
After:
Verification (macOS, stable toolchain):
cargo test— 45 + 19 + 39 passed, 0 failedcargo fmt --check— cleancargo clippy --all-targets -- -D warnings— identical to themasterbaseline (4 pre-existing errors in unrelated files from newer lints:redundant reference in format!/println!/bail!, deprecatedcargo_bin); no new findings from this changehyperfine -w0 -r1 -L payload '=1+1,harmless' 'true' --export-csv -emits'=1+1and leavesharmlessunchangedA regression test covering
=,+,-,@and a non-formula value is included insrc/export/csv.rs.Disclosure: this change was written with AI assistance (Claude). I have reviewed the diff, and run the tests, formatter and linter myself against a baseline.