Skip to content

fix(database): compose jobstore SQL safely - #25116

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/jobstore-sqli-canonical-24042-recut
Nov 11, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/jobstore-sqli-canonical-24042-recut

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Canonical re-cut of #24042 on current main (72d5dfdc671a2ccb0ffbb983785e995d8bdaa507). Head: 6a634c9706cd4f84d20cc492be8662f8ef5dc1b4.

This replaces f-string interpolation at all 13 assigned composition sites with psycopg.sql identifiers, literals, and typed literal SQL fragments. Runtime values remain query parameters. A single public database.jobstore.connection.sql() accessor preserves the lazy-postgres-driver invariant, and _fenced_update now types its SQL fragments as LiteralString.

This is defense in depth, not a claim of a live exploit: the existing call paths already gate table/column choices through fixed allowlists, validated priorities/pools, or internal constants, as the reviewers of the overlapping PRs noted.

Failure-Class: none

Sites fixed

  • backend/database/jobstore/postgres_store.py:261 — due(): quote the selected due column in both predicate and ordering.
  • backend/database/jobstore/postgres_store.py:404 — control_candidates(): quote every priority/pool-derived column reference.
  • backend/database/jobstore/postgres_store.py:508 — typed read_doc(): compose the table identifier and lock suffix.
  • backend/database/jobstore/postgres_store.py:541 — write_doc(): quote the typed table identifier.
  • backend/database/jobstore/postgres_store.py:556 — delete_doc(): quote the typed table identifier.
  • backend/database/jobstore/postgres_store.py:569 — service_frontier_in(): quote the priority-derived column.
  • backend/database/jobstore/postgres_store.py:593 — purge_namespace(): quote every cleanup table identifier.
  • backend/database/jobstore/backfill.py:60 — postgres_keys(): quote the typed table identifier.
  • backend/database/jobstore/outbox_pg.py:169 — claim(): compose the fixed RETURNING column list.
  • backend/database/jobstore/outbox_pg.py:202 — claim_key(): compose the fixed RETURNING column list.
  • backend/database/jobstore/outbox_pg.py:255 — _fenced_update(): compose only LiteralString set/guard fragments; keep claim data bound.
  • backend/testing/pipeline_sim/postgres_store.py:35 — PgRows._all(): compose each typed table as Identifier and its projected name as Literal across the UNION ALL.
  • backend/testing/pipeline_sim/postgres_store.py:210 — simulator delete(): quote the typed table identifier.

backend/database/jobstore/connection.py:28 adds the single lazy psycopg.sql accessor. The two simulator hunks are folded in from #24015. None of #24042's unrelated commit_message.txt, test_sql.py, or .agent-brief/firestore-index-guard/tests.txt files are carried over.

Tests

New hermetic behavioral coverage exercises every site above with hostile identifiers/values, verifies parameter tuples never enter rendered statement text, checks the outbox produces real psycopg.sql.Composable statements, and imports every changed module in clean subprocesses where psycopg is explicitly unavailable.

Focused pytest runs (one process per file):

Test file Result
test_jobstore_sql_composition.py 18 passed
test_jobstore_backfill.py 11 passed
test_jobstore_dual_store.py 68 passed
test_jobstore_migrations.py 7 passed
test_jobstore_postgres_locking.py 10 passed
test_jobstore_projection_mirror.py 8 passed
test_jobstore_protocol_parity.py 69 passed
test_jobstore_shadow_seams.py 23 passed
test_jobstore_codec.py 2 passed
test_batch_pipeline_lock_jobstore.py 2 passed

Total: 218 passed. No full-suite or live-service run was used.

  • bash backend/scripts/typecheck.sh: 0 errors.
  • scripts/backend-python-format --check ...: 7 files unchanged.

Supersedes and follow-up

View guided diff Turn on auto-fix

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T12:46:41.587074Z 6a634c9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level
Git-on-my-level merged commit d7a7077 into main Nov 11, 2026
65 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/jobstore-sqli-canonical-24042-recut branch November 11, 2026 14:12
Git-on-my-level added a commit that referenced this pull request Nov 12, 2026
…3761) (#23806)

Fixes #23761

Restores the recovery-cancellation prerequisite tracked by SCA-1689.
Account deletion during recovery now durably cancels the prepared or
running recovery through the shared Store interface before paid work or
result upload on Firestore, Postgres, and the simulator.

The coordinator delegates to `cancel_fenced_recovery`; each adapter
rechecks the privacy fence and changes only the cancellation marker when
blocked. Firestore refreshes the shadow after commit. Main is merged
into the existing branch without rewriting its history, retaining the
SQL identifier hardening from #25116 and the newer privacy-defer
methods. The overlapping #23763 is already closed.

## Verification

Run from `backend/` under a loopback Firestore emulator, with a
throwaway local Postgres cluster and synthetic customer authority:

- `OMI_REQUIRE_STORE_BACKENDS=all .venv/bin/python -m pytest -v -rxX -p
no:cacheprovider
tests/integration/test_recovery_admission_conformance.py`: exit 0, 27
passed; all three adapters, no skips or xfails. PL-057/072/086 cover
cancellation before recovery and after download, restart/redelivery, no
paid calls or result uploads, and unrelated-owner progress. Only the
PL-072 strict xfails whose contract now passes were removed.
- `OMI_REQUIRE_STORE_BACKENDS=all .venv/bin/python -m pytest -q -rxX -p
no:cacheprovider tests/integration/test_store_conformance.py
tests/integration/test_recovery_custody_conformance.py`: exit 0, 267
passed, 6 adapter-specific not-applicable skips; every adapter
available.
- `backend/.venv/bin/python -m pytest -q -p no:cacheprovider
backend/tests/unit/test_batch_pipeline_scheduler.py`: exit 0, 62 passed.

This source repair books **$0/day**. Production serving parity,
cross-database privacy safety, physical erasure, reverse
migration/rollback, pooler readiness, deployment/readback,
production-fence decisions, and a full settled before/after day of
normalized net cost remain separate gates owned by the pipeline driver
and SCA-1683. Existing dark/staging selectors and production fences
remain in force.

## Product invariants affected

none

## Failure-Class

Failure-Class: none

## UI-Evidence

UI-Evidence: none -- internal recovery Store integration and conformance
evidence.
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