T09 · Insecure Skill Coding Practices
- Location
social_intel.py:381- Finding
Spreadsheet Formula Injection in CSV and Excel Exports
- Content
View full analysis
Vulnerability Details
File Location:
social_intel.py, lines 381-384 and 411-415
Vulnerability Type: Spreadsheet formula injection
Risk Level: MediumVulnerable Code
python with open(output_path, "w", newline="", encoding="utf-8-sig") as f: writer = csv.DictWriter(f, fieldnames=fieldnames, extrasaction="ignore") writer.writeheader() writer.writerows(notes)python for note in notes: row = [note.get(f, "") for f in fields] ws.append(row) # Set column widths ws.column_dimensions["J"].width = 50 ws.column_dimensions["K"].width = 40Technical Analysis
Social-media fields including
author,desc, andurlare controlled by remote content authors. The application writes these values directly into CSV and XLSX cells without neutralizing strings beginning with spreadsheet formula characters such as=,+,-, or@.When a generated report is opened, spreadsheet software may interpret an attacker-controlled value as a formula instead of plain text. XLSX values beginning with
=are particularly likely to be stored as formulas byopenpyxl. CSV behavior depends on the spreadsheet application used to open the file.Potential payloads can reference external resources, disclose spreadsheet values through outbound requests, track report viewers, or invoke dangerous legacy spreadsheet functionality. Actual code execution depends on the spreadsheet product, platform, security configuration, and user interaction.
Attack Path
- An attacker publishes a social-media post, profile name, description, or URL containing a malicious spreadsheet formula.
- A victim searches for content that includes the attacker's record.
- The Skill receives the malicious field through the TikHub MCP service.
- The victim invokes
--export csv,--export excel, or--export both. - The untrusted value is written to the report without sanitization.
- The victim opens the generated file in spreadsheet so ...[truncated 637 chars]
- Remediation
View remediation
Remediation Suggestions
- Sanitize every remotely sourced field before CSV or Excel export.
- Convert values to strings and prefix values beginning with
=,+,-, or@with an apostrophe. - For XLSX files, explicitly store untrusted values as text rather than formulas.
- Apply protection to every exported field, including author names, descriptions, identifiers, dates, and URLs.
- Consider rejecting control characters and normalizing leading whitespace before checking the first meaningful character.
- Add regression tests for payloads such as
=1+1,+SUM(1,1),-1+2, and@SUM(1,1). - Document that exported files contain third-party content and should be opened with external-link and macro protections enabled.
A centralized helper should be used by both exporters, for example:
python def safe_spreadsheet_value(value): text = "" if value is None else str(value) stripped = text.lstrip() if stripped.startswith(("=", "+", "-", "@")): return "'" + text return text
