T09 · Insecure Skill Coding Practices
- Location
tool.py:54- Finding
CSV Formula Injection Through Unsanitized JSON Values
- Content
View full analysis
Vulnerability Details
File Location:
tool.py, lines 54–57
Vulnerability Type: CSV formula injection
Risk Level: Mediumpython with open(csv_file, 'w', newline='', encoding='utf-8') as f: writer = csv.DictWriter(f, fieldnames=fieldnames) writer.writeheader() writer.writerows(flat_data)Technical Analysis
Values originating from the input JSON are written directly to CSV cells without neutralizing spreadsheet formula prefixes. Strings beginning with characters such as
=,+,-, or@may be interpreted as formulas when the generated file is opened in spreadsheet software. CSV quoting alone does not reliably prevent formula evaluation.This issue is particularly relevant because the skill explicitly presents its output as suitable for spreadsheets. Exploitation requires an attacker to control or influence at least one value in the source JSON and a user to open the generated CSV in spreadsheet software that evaluates the crafted expression.
Attack Path
- An attacker supplies or modifies a JSON input value so that it begins with a spreadsheet formula prefix, for example:
json { "name": "=HYPERLINK(\"https://attacker.example\",\"Open\")" } - The converter flattens the record without changing the malicious string.
writer.writerows(flat_data)writes the value unchanged into the output CSV.- A user opens the CSV in a spreadsheet application.
- If that application evaluates the cell as a formula, the attacker-controlled expression executes within the spreadsheet's formula environment.
Impact Assessment
The converter itself does not grant operating-system privileges, execute commands, or access the network. Impact occurs in the downstream spreadsheet application and depends on its features, security configuration, and user interaction.
Plausible effects include deceptive hyperlinks, external network requests that disclose con ...[truncated 270 chars]
- An attacker supplies or modifies a JSON input value so that it begins with a spreadsheet formula prefix, for example:
- Remediation
View remediation
Remediation Suggestions
Sanitize all string values before passing records to
csv.DictWriter. If the first non-whitespace character is=,+,-, or@, prefix the value with an apostrophe or apply another spreadsheet-safe encoding policy. Also account for leading tab, carriage-return, and line-feed characters that could bypass a simple first-character check.Enable this protection by default because the documented use case includes spreadsheets. If exact raw CSV preservation is required for trusted machine-to-machine workflows, provide an explicit opt-out and clearly document its security implications.
Add automated tests covering formula-prefixed values, leading whitespace and control characters, nested JSON values, and ordinary negative numeric values to avoid incorrect sanitization of genuine numbers.
