T09 · Insecure Skill Coding Practices
- Location
scripts/_shared.py:257- Finding
Spreadsheet Formula Injection Through Unsanitized Pricing Data
- Content
View full analysis
str: parts = [str(value).strip() for value in values if str(value or "").strip()] return "; ".join(dict.fromkeys(parts)) def feature_summary(item: dict[str, Any]) -> str: explicit = str(item.get("plan_summary", "")).strip() if explicit: return explicit features = item.get("features", []) if isinstance(features, list): return "; ".join(str(feature).strip() for feature in features if str(feature).strip()) if isinstance(features, str): return features.strip() return "" ``` The values are inserted into records without spreadsheet-specific sanitization: ```python expanded.append( { "vendor_key": item.get("vendor_key", ""), "region": item.get("region", ""), "product_name": item.get("product_name", ""), "model_name": item.get("model_name", ""), "price_dimension": price.get("price_dimension", ""), "source_price_amount": price.get("source_price_amount", ""), "currency": price.get("currency", ""), "unit_basis": price.get("unit_basis", ""), "original_price_text": price.get("original_price_text", ""), "notes": combine_notes(item.get("notes", ""), price.get("notes", "")), "source_url": price.get("source_url", "") or item.get("source_url", ""), } ) ``` CSV serialization preserves arbitrary strings as supplied: ```python def write_csv_rows(path: Path, rows: list[dict[str, Any]], fields: list[str]) -> None: path.parent.mkdir(parents=True, exist_ok=True) with path.open("w", encoding="utf-8", newline="") as handle: writer = ...[truncated 4014 chars]- Remediation
View remediation
Any: if not isinstance(value, str): return value if value.startswith(DANGEROUS_CELL_PREFIXES): return "'" + value return value ``` 2. Apply the function to every string field in `write_csv_rows`, not only fields currently known to contain remote text. 3. If the Feishu/Lark API supports explicit cell types, submit remote and descriptive fields as literal text rather than allowing automatic formula inference. 4. Sanitize both current and historical tables because previously collected values are copied into history and change records. 5. Validate extraction JSON before building. Reject or flag formula-like values in descriptive fields unless an operator explicitly approves them. 6. Add regression tests for values beginning with: - `=` - `+` - `-` - `@` - Tab - Carriage return - Leading whitespace followed by a dangerous prefix 7. Consider adding provenance metadata or review warnings when extraction fields contain formula syntax, URLs, or unexpected control characters. ]]>
