Skip to content

0013 — `authenticated` holds table-wide SELECT on two no-RLS tables the policies subquery

Status: candidate Opened: 2026-09-10 · Area: platform (client-role ACL floor, RLS) Reopen trigger: PostgREST or any other connection running as authenticated/anon being exposed; or a third policyReads grant appearing in the rendered client_role_acl migration; or the next ADR-0056/ADR-0019 security sweep.

Studio’s RLS advisor flags exactly two public tables (2026-09-10): assessment_item_version and qualification_definition. They are the only tables where a client role holds a grant AND RLS is off. The grant is derived, not accidental: client_role_acl (packages/db/src/migration-sql/client-role-acl.ts, the policyReads block) grants authenticated SELECT because a policy on another table subqueries them, and Postgres evaluates a policy’s subquery as the querying role —

  • entity_image’s admin policy resolves an achievement’s organization through qualification_definition (packages/db/src/schema/entity-image.ts);
  • item_parameter_set’s admin-manage policy resolves the owning organization two hops out through assessment_item_version → offering (itemVersionOrganizationExpression, packages/db/src/schema/cat-pool.ts).

assessment_item_version is the answer-key store: payload carries the correct responses and qti_source_xml carries them too. Every other reader gets keys stripped by the sync proxy’s row transform (packages/db/src/schema/qti-key-withholding.ts); a table-wide SELECT grant hands the role the raw rows. The exposure is LATENT today — nothing connects as authenticated, PostgREST is not deployed, and the apply function’s role switch executes only its generated DML — which is why this is parked rather than fixed (see the runbook’s “Why it is safe”, docs/runbooks/migrations.md).

When the trigger fires, replace the two direct subqueries with SECURITY DEFINER helpers — the pattern already used by fn_offering_allows_membership_insert and fn_person_pnp_proxy_allowed: one returning an item version’s organization, one returning a qualification definition’s organization. The policies call the helpers; the ACL floor then derives EXECUTE on the helpers instead of SELECT on the tables, and both tables end up like the other no-RLS tables (nothing in front of them for client roles). Each helper lands in its own custom migration (bun run db:generate --custom --name <snake_name>, docs/runbooks/migrations.md) appended before the schema migration that rewrites the two policies (a policy resolves its functions at CREATE POLICY time; plpgsql body so the relation resolves at first call), and the ACL floor is re-emitted last as always. In migration-drift.test.ts the helper migrations join POSTURE_SOURCE_MIGRATION_NAMES and the schema migration joins DRIZZLE_SCHEMA_MIGRATION_NAMES. Enabling RLS on the two tables with matching SELECT policies would also satisfy the advisor, but puts a policy on the answer-key table where none is otherwise needed — the helper route is preferred.