Skip to content

fix(db): only the service role may write provenance claims or move vote counts - #523

Open
nadernik wants to merge 1 commit into
devfrom
fix/revoke-open-writer-functions
Open

nadernik wants to merge 1 commit into
devfrom
fix/revoke-open-writer-functions

Conversation

@nadernik

Copy link
Copy Markdown
Collaborator

In production today, anyone with the site's public key can call three SECURITY DEFINER functions that have no caller check:

  • record_field_provenance (13 arguments) writes a provenance claim at any grade on any cell. A claim at a verified grade makes enforce_field_provenance refuse later machine updates of that cell.
  • increment_vote_count / decrement_vote_count move any suggestion's vote count with triggers off, so nothing is audited.

The only callers are migrations and two SECURITY DEFINER functions (confirm_species_candidate, provenance_mark_verified), which run as the owner. Nothing in src/ or supabase/functions/ calls them, and no trigger does. So only service_role keeps EXECUTE.

This is the function-grant part of 20261118120000_privacy_round_two in #520, taken ahead of that file's column changes, which have to wait for the front end. Re-running either file is harmless.

Checked (read-only, 2026-11-19): data_audit_log has no anon write outside access_requests, and field_provenance has no unattributed claim outside the August backfills and imports. I found no sign that either function was misused.

To apply: SQL editor, project vpexxhfpvghlejljwpvt. The last statement should show anon = false and authenticated = false for all three.

Refs #520

…te counts

record_field_provenance (13 arguments) and increment/decrement_vote_count are SECURITY DEFINER with
no caller check, and the default privileges let anon run them. Their only callers run as the owner.
This is the function-grant part of #520's privacy_round_two, ahead of its column changes.

Refs #520
@github-actions github-actions Bot added the spec:C Danger layer — Spec Kit + sign-off required label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Triage: Class C → spec:C

Touches a danger layer. Requires Spec Kit artifacts (spec/plan/tasks/qa-itinerary), a Constitution Check, and human sign-off. Never auto-merges.

Blast radius: HIGH

  • migration: Schema/RLS/view migration — applied MANUALLY to production and hard to reverse. RLS policy and CREATE OR REPLACE VIEW changes live here too.

Complexity: LOW

  • 1 files, 29 lines — within Class-A limits.

Files that set the class:

  • supabase/migrations/20261119150000_revoke_open_writer_functions.sql → migration (hard)

Deterministic classifier — computed from the diff, not from the issue text. Change the rules in scripts/triage/classify.mjs (itself a Class-C path).

@github-actions

Copy link
Copy Markdown
Contributor

🛑 Class C — this touches a danger layer

Per the constitution (Development Workflow) danger-layer changes are spec-driven. Before this can merge, a maintainer must:

  1. Create the Spec Kit artifacts in bbqs-agent/specs/<NNN-feature>/ — spec.md, plan.md (with a Constitution Check), tasks.md, qa-itinerary.md.
  2. Point bbqs-agent/.specify/feature.json at that directory.
  3. Run the Find → Fix → Test → Verify-Live loop, incl. the sandbox QA workflow.
  4. Add the spec-signoff label to this PR to release the triage/spec-gate check.

This gate is here because a small-looking diff to supabase/migrations/20261119150000_revoke_open_writer_functions.sql reaches far beyond the file it edits.

@nadernik

Copy link
Copy Markdown
Collaborator Author

Applied 2026-11-19 by @nadernik in the SQL editor. Checked afterwards from the CLI: all three functions now grant EXECUTE only to postgres and service_role, so anon and authenticated both read false. 43 SECURITY DEFINER functions are still callable by anon; the rest of round two in #520 covers those.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spec:C Danger layer — Spec Kit + sign-off required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant