T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/yotta_intel.py:435
- Finding
- CSV Formula Injection Through Attacker-Controlled IOC Context## Vulnerability Details **File Location**: `scripts/yotta_intel.py:333-344`, `scripts/yotta_intel.py:435-439` **Vulnerability Type**: CSV formula injection **Risk Level**: Medium ### Vulnerable Code ```python if entry is None: snippet = "" if 0 < idx <= len(orig_lines): snippet = orig_lines[idx - 1].strip() entry = { "type": ioc_type, "value": canonical, "defanged": defang_value(canonical, ioc_type), "count": 0, "first_line": idx, "snippet": snippet, } ``` ```python def build_csv(records): out = io.StringIO() w = csv.writer(out) w.writerow(["type", "value", "defanged", "count", "first_line", "snippet"]) for r in records: w.writerow([r["type"], r["value"], r["defanged"], r["count"], r["first_line"], r["snippet"]]) return out.getvalue() ``` ### Technical Analysis The tool processes potentially hostile threat reports, phishing messages, and logs. When an IOC is found, the complete original source line is copied into the `snippet` field. This attacker-controlled value is then written to CSV without neutralizing spreadsheet formula prefixes. The `csv.writer` function provides syntactically correct CSV quoting, but quoting does not prevent spreadsheet applications from interpreting cells beginning with characters such as `=`, `+`, `-`, or `@` as formulas. Leading whitespace and control characters can also be used to bypass simplistic prefix checks. Consequently, a CSV file generated from untrusted input may contain active formulas even though the output appears to be ordinary structured IOC data. ### Attack Path 1. An attacker creates a phishing message, threat report, or log line that begins with a spreadsheet formula and also contains a syntactically valid IOC. 2. A user runs: ```bash python3 scripts/yotta_intel.py extract --path hostile-report.txt --format csv --output iocs. ...[truncated 1205 chars]
- Remediation
- ## Remediation Suggestions - Sanitize every attacker-controlled CSV cell before passing it to `csv.writer`, especially `snippet`. - After accounting for leading spaces, tabs, and control characters, prefix cells beginning with `=`, `+`, `-`, or `@` with an apostrophe. - Consider applying neutralization to every string field rather than only `snippet`, preventing future regressions if other fields become attacker-controlled. - Provide a separate raw machine-import format, such as JSON, if preserving the exact source line is required. - Clearly document whether CSV output is safe for direct use in spreadsheet applications. - Add automated tests covering dangerous prefixes, leading whitespace, tabs, carriage returns, and quoted formulas. - Example hardening helper: ```python def safe_csv_cell(value): if not isinstance(value, str): return value probe = value.lstrip(" \t\r\n") if probe.startswith(("=", "+", "-", "@")): return "'" + value return value ```
