Repository navigation
Conversation
The app keeps reading through a public read policy. The monitors and triage keep writing with the service key. Anon and authenticated lose their write grants, so no other policy on the table can admit a write. A new workflow replays scripts/sql on Postgres 17 and tests each role. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 009 revokes every privilege on the table from PUBLIC, anon and authenticated, grants SELECT back to anon and authenticated and writes to service_role, and does the same for the table's sequences. - The access test seeds varied bills, compares each role's reads with the owner's, runs each statement with the request's role claim, checks table and sequence privileges, and covers PUBLIC write grants. - The SQL access workflow also runs on pushes to main and on Vitest and package changes, and fails when the database URL is missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A view writes its tables with its owner's privileges, so a write grant on an updatable view over processed_bills would let anon write the table past its policies. 009 now walks every view built on processed_bills, directly or through other views, revokes everything on it from PUBLIC, anon and authenticated, and grants SELECT to anon, authenticated and service_role. The sequence block's comment now says it covers the sequences the table owns (serial or identity) and why it leaves others alone. The access test finds the same views through information_schema, checks every privilege type on each for anon, authenticated and PUBLIC, and tries writes through a single-table view, a view on it and a CREATE OR REPLACE rewrite of pending_analysis. The suite's tests and hooks get explicit timeouts, since a busy machine can outlast Vitest's defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Writes with no grant insert an explicit id and expect permission denied for the table, so a sequence error can't stand in for that refusal. - The privilege report covers column privileges and column ACL entries on processed_bills and the sequences it owns, for PUBLIC as well as anon and authenticated, and for every privilege type the server knows. The PUBLIC scenario grants PUBLIC everything on the table, the sequence and pending_analysis, plus column grants, and checks the report after 009. - Every test runs on a bigserial id and on identity ids generated by default and always. The always-identity sequence has its own name. - The seed adds the ids and labels congress_monitor.py and openstates_monitor.py write, and the stray-grant test inserts such ids. - A fast-check property (fast-check 4.10.2, pinned) generates bills across the writers' id ranges, sources, matched_query values and nulls, and checks that each role reads exactly what the owner reads. It runs a fixed seed and a bounded number of runs, each in a transaction that rolls back. - The fixture's comment says where its columns come from, and the fixture drops created_at, which no writer writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Maintainers run scripts/sql by hand from this list, so 009 joins it, with the query that lists the policies on processed_bills to run first: turning on row level security brings any of them into force. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
009's view comment now names anon and authenticated as the roles left with SELECT alone, and says a new view takes its creator's default privileges. The seed and property comments stop crediting openstates_monitor.py with the 'openstates' source: it builds that value but never writes it, so the comments name 006, which lists it. Comments only; no behaviour changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…BLIC The service role's PUBLIC-only test now runs congress_monitor.py's upsert on bill_id alongside the update, insert and delete, so the invariant that it keeps every write the scripts use, upsert included, has a test in both grant states. The upsert lives in one constant both tests share. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… states Both service role tests now compare its read of processed_bills and pending_analysis with the owner's, with its own grants and with grants that came only through PUBLIC. That comparison covers the PUBLIC-only test's old pending_analysis row count, which goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
self-requested a review
November 6, 2026 13:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Every other migration that creates a table enables row level security on it.
scripts/sql/009_processed_bills_rls.sqldoes the same forprocessed_bills:processed_bills;research,reform_impacts,validation_metadataanddataset_hashesuse: public read and service write;PUBLIC,anonandauthenticated, then grantsSELECTback toanonandauthenticated, andSELECT, INSERT, UPDATE, DELETEtoservice_role;USAGE, SELECTon them toservice_roleonly;processed_bills, directly or through other views, from the same three, and grantsSELECTon it toanon,authenticatedandservice_role.By default PostgreSQL writes through a view with the view owner's privileges, and a table's owner bypasses the table's policies. So when one role owns both the table and an updatable view on it,
anoncan change rows past the policies with a write grant on that view.The app reads
processed_billsonly throughuseProcessedBillsinBillActivityFeed.jsx, with the anon key, and never writes it.refresh_bill_status.py,auto_triage.py,congress_monitor.py,openstates_monitor.pyand the/triage-billscommand write withSUPABASE_KEY, whichCLAUDE.mdnames as the service key.How to apply it
Maintainers run the
scripts/sqlfiles by hand in the Supabase dashboard, so merging changes nothing in the live database. The README's migration list now ends with 009. PostgreSQL ignores a table's policies until someone turns on row level security, so 009 also brings into force any policyprocessed_billsalready has. List them before running it:Once 009 runs, only a client with the service role key can write
processed_bills, so check thatSUPABASE_KEYholds that key wherever the writers run.Run 009 again after anyone creates a view on
processed_bills, or drops and recreates one, since PostgreSQL gives a new view its creator's default privileges. PostgreSQL keeps the grants 009 set through aCREATE OR REPLACE VIEW.Invariants
For each of
anonandauthenticated:processed_billsandpending_analysisrow and column that the table owner reads, whatever bills the writers store;SELECTonprocessed_billsand nothing else on the table, its columns or the sequences the table owns, so it can't insert, update, delete or truncate;SELECTand nothing else on every view built onprocessed_bills, directly or through other views, so it can't write the table through a view;TRUNCATE, so only the revoke stops it;PUBLICgrants of everything, 009 still closes writes. The role ends with the same privileges as on a table with neither.PUBLICends with no privilege on the table, its columns, its sequences or its views.service_rolekeeps every read and write the monitors and triage use, including the upsert onbill_id, even when its only grants came throughPUBLIC. A second run of 009 leavesanon,authenticatedandPUBLICwith the same reads and privileges.Tests
scripts/sql/access.test.jsbuilds a temporary database with Supabase's roles, default grants andauth.role(), replaysscripts/sqland seeds nine bills. The seed includes a federal bill, a skipped bill, a bill with no action date, and scores of 0 and null. It also has two ids incongress_monitor.py's range, with its twomatched_querylabels, and an id inopenstates_monitor.py's range with the'openstates'source that 006 lists. Each statement runs as the role, with the role claim a Data API request carries, so a policy that readsauth.role()sees what it would see on a real request.The tests then:
matched_querylabels, sources and nulls;anon;CREATE OR REPLACErewrite ofpending_analysisthat PostgreSQL can write through;anon,authenticatedandPUBLIC, on the table, its columns, its sequences and every view built on it;PUBLICgrants of everything, and after a second run of 009;service_rolekeeps the scripts' reads and writes, with its own grants and with grants that came only throughPUBLIC, and that every table inpublickeeps row level security.The privilege checks find the sequences through
pg_get_serial_sequenceand the views throughinformation_schema, independently of the catalog queries 009 runs. The property usesfast-check, now a dev dependency pinned to 4.10.2, with a fixed seed and 30 runs that each roll back. Every test runs on abigserialid and on identity ids generated by default and always, since nothing in the repo says how the live table numbers its rows.The new
SQL accessworkflow runs the tests onpostgres:17for pull requests and pushes tomainthat touchscripts/sql, the workflow, the Vitest config or setup,package.jsonorbun.lock. It setsTRACKER_TEST_POSTGRES_REQUIRED, so a missing database URL fails the job. WithoutTRACKER_TEST_POSTGRES_URL,bun run testskips these tests and runs the rest.On PostgreSQL 14.24 and 17.11, all 90 tests pass.
Limits
processed_billsdoesn't own, since such a sequence may number another table's rows.processed_bills, so the fixture builds it from the columns indocs/SUPABASE_MIGRATION.md, anidkey thatrefresh_bill_status.pyselects and updates by, and a uniquebill_idthatcongress_monitor.py's upserts conflict on.004_add_confidence_score.sql: itspending_analysishas columns that 005 drops, so PostgreSQL refuses to run both.Generated with Claude Code