T09 · Insecure Skill Coding Practices
- Location
scripts/pmu_quality_check.py:419- Finding
Spreadsheet Formula Injection in Exported Flagged-Row Reports
- Content
View full analysis
pd.DataFrame: """Load CSV and rename columns to standard names.""" df = pd.read_csv(csv_path) ``` ```python # Export flagged rows flagged = build_flagged_df(df, all_results) if output_dir: os.makedirs(output_dir, exist_ok=True) out_path = Path(output_dir) / (Path(csv_path).stem + "_flagged.csv") else: out_path = Path(csv_path).with_name(Path(csv_path).stem + "_flagged.csv") if len(flagged) > 0: flagged.to_csv(out_path, index=False) ``` ### Technical Analysis The application reads attacker-controlled CSV fields and copies their original values into the generated flagged-row report. Before calling `DataFrame.to_csv`, it does not neutralize text beginning with spreadsheet formula prefixes such as `=`, `+`, `-`, or `@`. CSV itself does not execute code, but common spreadsheet applications can interpret such cells as formulas when a user opens the generated report. A malicious input value such as an external-reference or hyperlink formula could initiate network requests, disclose information through formula arguments, or deceive the report reviewer into taking an unsafe action. The exact behavior depends on the spreadsheet software and its security configuration. Only rows carrying at least one quality flag are exported, but an attacker can deliberately trigger a flag by including a missing or out-of-range measurement in the same row. ### Attack Path 1. An attacker supplies a PMU CSV containing a formula-like string in a field preserved by the checker. 2. The attacker ensures that the row is flagged, for example by leaving another field empty or providing an out-of-range frequency. 3. The operator runs `pmu_quality_check.py` against the malicious CSV. 4. `build_flagged_df ...[truncated 793 chars]- Remediation
View remediation
