T09 · Insecure Skill Coding Practices
- Location
scripts/kev_triage.py:96- Finding
CSV Formula Injection Through Untrusted Vulnerability Fields
- Content
View full analysis
dict: cve = str(vuln.get("cve", "UNKNOWN")) cvss = float(vuln.get("cvss", 5.0)) known_exploited = bool(vuln.get("known_exploited", False)) asset = str(vuln.get("asset", "unmapped")) criticality = asset_map.get(asset, "medium") ``` ```python with output_path.open("w", newline="", encoding="utf-8") as handle: writer = csv.DictWriter( handle, fieldnames=[ "priority", "cve", "asset", "cvss", "known_exploited", "criticality", "score", "recommended_due_days", ], ) writer.writeheader() writer.writerows(result["details"]["prioritized_vulnerabilities"]) ``` ### Technical Analysis The `cve` and `asset` fields are read from attacker-controlled JSON input and converted to strings without spreadsheet-specific neutralization. These values are subsequently passed directly to `csv.DictWriter`. CSV quoting only preserves the CSV structure; it does not prevent spreadsheet applications from interpreting cells beginning with characters such as `=`, `+`, `-`, or `@` as formulas. Consequently, an attacker who controls an input field can place a spreadsheet formula in the generated report. Exploitation depends on a user opening the CSV output in a formula-capable spreadsheet application. The Python script itself does not evaluate the formula. ### Attack Path 1. An attacker provides or modifies the triage JSON input. 2. The attacker sets a string field such as `asset` or `cve` to a spreadsheet formula beginning with `=`, `+`, `-`, or `@`. 3. An operator runs the sc ...[truncated 1011 chars]- Remediation
View remediation
object: if not isinstance(value, str): return value if value.lstrip().startswith(DANGEROUS_CSV_PREFIXES): return "'" + value return value rows = [ {key: spreadsheet_safe(value) for key, value in row.items()} for row in result["details"]["prioritized_vulnerabilities"] ] writer.writerows(rows) ``` ]]>
