T09 · Insecure Skill Coding Practices
- Location
scripts/data-cleaner.py:81- Finding
Spreadsheet Formula Injection in Generated CSV Files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/data-cleaner.py:81,scripts/data-cleaner.py:120, andscripts/forecast-runner.py:247-254
Vulnerability Type: CSV/spreadsheet formula injection
Risk Level: MediumVulnerable Code
python df.to_csv(output_path, index=False, encoding='utf-8-sig')python out_df.to_csv(args.output, index=False, encoding='utf-8-sig')python results.append({ 'sku': sku, **result, }) out_df = pd.DataFrame(results) output_path = args.output or 'forecast_result.csv' out_df.to_csv(output_path, index=False, encoding='utf-8-sig')Technical Analysis
Values originating from user-supplied CSV or spreadsheet files are written to output CSV files without neutralizing spreadsheet formula prefixes. In particular, attacker-controlled SKU values and string columns preserved by the cleaning operation can begin with characters such as
=,+,-, or@.CSV itself does not distinguish formulas from text. When a generated file is opened in Excel, LibreOffice Calc, or another spreadsheet application, such values may be interpreted as formulas rather than displayed as literal text. The exact behavior and available formula capabilities depend on the spreadsheet application and its security configuration.
The cleaner preserves input columns and writes them at line 81. The outlier report propagates the input SKU into a new data frame before writing it at line 120. The batch forecaster similarly copies each input SKU into the result data frame before exporting it at lines 247-254.
Attack Path
- An attacker creates a sales CSV or spreadsheet containing a formula-prefixed value in the
skucolumn or another preserved string column. - A user runs the
clean,detect-outliers, orbatchcommand against that file. - The script copies the malicious value into an output CSV without escaping or type enforcement.
- The user or another re ...[truncated 840 chars]
- An attacker creates a sales CSV or spreadsheet containing a formula-prefixed value in the
- Remediation
View remediation
Remediation Suggestions
- Sanitize every string-valued cell before CSV export, not only the SKU column.
- Prefix cells beginning with
=,+,-, or@with a single quote or another application-appropriate escape. - Consider tab, carriage-return, and line-feed prefixes that may allow a dangerous character to become the effective first spreadsheet character.
- Prefer XLSX output with cells explicitly typed as text when the files are intended for spreadsheet consumption.
- Preserve an unsanitized internal representation for calculations and apply neutralization only at the export boundary.
- Add regression tests using values such as
=1+1,+SUM(1,1),-1+2, and@SUM(1,1)and verify that spreadsheet applications display them as literal text. - Document that generated CSV files may contain untrusted source data and should not be opened before neutralization.
