Skip to content

fix(rls): policy table matching ignored schema qualifiers - RLS WHERE injection never applied - #353

Open
AgoniJJ wants to merge 2 commits into
outerbase:mainfrom
AgoniJJ:rls-fix
Open

AgoniJJ wants to merge 2 commits into
outerbase:mainfrom
AgoniJJ:rls-fix

Conversation

@AgoniJJ

@AgoniJJ AgoniJJ commented Nov 15, 2026

Copy link
Copy Markdown

Fixes the failing RLS tests and a real security bug found while investigating them.

Security fix

loadPolicies stores policy tables as schema-qualified identifiers (public.users), while parsed query table refs are unqualified (users). tables.includes(targetTable) therefore never matched, so RLS WHERE injection never applied to any query - a full row-level-filter bypass. Action gating still worked, which is why most behavior looked fine.

Changes:

  • Compare table names ignoring schema qualifiers (baseTableName).
  • Recurse into derived tables (subqueries in FROM): previously crashed with Cannot read properties of undefined (reading includes); now policies apply inside subqueries too.
  • Load column refs unqualified so injected conditions render valid SQL.
  • Tests updated: per-action policy mocks for DELETE/UPDATE/INSERT (previously asserted on the query's own WHERE - false passes), mockConfig.role reset between describes (state leak), expectations match corrected behavior.

All 163 tests pass (20 files). Related to the test-coverage bounty (#71); follow-up to #352.

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