T09 · Insecure Skill Coding Practices
- Location
scripts/make_codebook.py:110- Finding
Spreadsheet Formula Injection in Generated TSV Files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/make_codebook.py:110-112
Vulnerability Type: Spreadsheet formula injection
Risk Level: MediumVulnerable Code
python with tsv_path.open("w", encoding="utf-8", newline="") as f: writer = csv.DictWriter(f, fieldnames=headers, delimiter="\t") writer.writeheader() writer.writerows(records)The
recordscollection contains attacker-controlled values read from the input CSV, includingitem_id,item_text, anddimension. These values are written directly tovariable_map.tsvwithout neutralizing spreadsheet formula prefixes.Technical Analysis
Spreadsheet applications may interpret cells beginning with
=,+,-, or@as formulas. An attacker able to provide questionnaire CSV content can place a spreadsheet formula in a textual field. The script preserves that content when generating the TSV.This is security-relevant because the skill explicitly produces analysis-ready files intended for use in spreadsheet software. CSV quoting does not neutralize formulas: a quoted cell can still be evaluated after the generated TSV is opened or imported into a spreadsheet application.
Exploitation depends on the victim opening the generated file in software that evaluates formulas and on that software's security settings. The precise effects vary by spreadsheet product and version.
Attack Path
- An attacker supplies or modifies the questionnaire input CSV.
- The attacker places a formula-leading payload in a field such as
item_text,item_id, ordimension. - A user runs
scripts/make_codebook.pyagainst that CSV. - The script copies the value into
variable_map.tsvwithout spreadsheet-safe escaping. - The user opens or imports the TSV in Excel or another formula-capable spreadsheet application.
- The application may evaluate the cell as a formula rather than display it as literal questionnaire text.
Impact Assessment
The script itself does not gain ...[truncated 560 chars]
- Remediation
View remediation
Remediation Suggestions
Implement a dedicated spreadsheet-safety function and apply it to every user-controlled textual value before writing TSV output. At minimum:
- Detect values whose first non-whitespace character is
=,+,-, or@. - Prefix such values with a single quote or another format-appropriate neutralization marker that the supported spreadsheet applications treat as literal text.
- Consider additional dangerous leading characters, including tabs, carriage returns, and line feeds, according to the import behavior of supported applications.
- Preserve the original data separately if exact round-trip fidelity is required.
- Document the escaping behavior so consumers understand that generated files are spreadsheet-safe representations.
- Add automated tests covering formula-leading values in every exported user-controlled field.
For example:
python def spreadsheet_safe(value: str) -> str: if value and value.lstrip().startswith(("=", "+", "-", "@")): return "'" + value return valueApply the protection while constructing export records or immediately before
writer.writerows(records). Do not rely solely on CSV/TSV quoting because quoting does not prevent spreadsheet formula evaluation.- Detect values whose first non-whitespace character is
