T09 · Insecure Skill Coding Practices
- Location
SKILL.md:182- Finding
Excel Formula Injection Sanitizer Can Be Bypassed with Leading Whitespace or Control Characters
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 182-184
Vulnerability Type: Incomplete input sanitization for spreadsheet formula injection
Risk Level: MediumVulnerable Code:
python if isinstance(value, str) and value and value[0] in '=+-@': return f"'{value}" return valueTechnical Analysis
The sanitizer examines only the first character of a string. An attacker can place whitespace or control characters, such as a tab, carriage return, or line feed, before a dangerous formula marker. If spreadsheet software strips, ignores, or normalizes that prefix during import, the resulting cell may still be interpreted as a formula.
The document also recommends using a tab as a protective prefix at lines 102 and 232. A tab is not a dependable security boundary because spreadsheet applications and import workflows differ in how they process leading control characters.
This issue applies when attacker-controlled values are exported to CSV and subsequently opened in spreadsheet software. Its exploitability and resulting behavior depend on the spreadsheet application, version, security configuration, and formula features available.
Attack Path
- An attacker submits a CSV field containing leading whitespace or a control character followed by a formula marker, such as a tab followed by
=. sanitize_for_excelchecks onlyvalue[0], which is the leading character rather than the formula marker.- The function returns the value without neutralizing it.
- The application writes the value to an exported CSV file.
- A user opens or imports the file in spreadsheet software.
- If the spreadsheet normalizes the leading character and recognizes the remaining value as a formula, it evaluates the attacker-controlled expression.
Impact Assessment
Successful exploitation can execute attacker-controlled spreadsheet formulas in the security context of the user opening the file. De ...[truncated 391 chars]
- An attacker submits a CSV field containing leading whitespace or a control character followed by a formula marker, such as a tab followed by
- Remediation
View remediation
Remediation Suggestions
- Treat all externally supplied cells as untrusted before CSV generation.
- Detect formula markers after accounting for all leading whitespace and control characters, rather than checking only
value[0]. - Reject unexpected control characters or apply a strict allowlist for fields that do not require them.
- Do not present a tab prefix as a universally reliable formula-injection defense.
- Use a spreadsheet-specific export library or format that can explicitly create text cells when spreadsheet output is the intended destination.
- If CSV must be used, define and test an escaping policy against every supported spreadsheet application and import workflow.
- Add regression tests for spaces, tabs, carriage returns, line feeds, Unicode whitespace, and each dangerous marker:
=,+,-, and@. - Consider rejecting formula-like values entirely in high-security exports instead of attempting to preserve them.
