Skip to content

feat: add policy_on_anon_role lint (0035) - #217

Open
claude[bot] wants to merge 2 commits into
mainfrom
claude/lint-policy-on-anon-role
Open

claude[bot] wants to merge 2 commits into
mainfrom
claude/lint-policy-on-anon-role

Conversation

@claude

@claude claude Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Requested by Stojan Dimitrovski, Etienne Stalmans · Slack thread

Before: Nothing warned about RLS policies that apply to the anon role. A Storage policy like for all using ((storage.foldername(name))[1] = auth.uid()::text) with no TO clause applies to public, which includes anon. A JWT with no role claim, such as an OIDC ID token issued to an OAuth client, runs as anon in PostgREST and Storage, and auth.uid() still returns its sub, so that token got access.

After: The advisor reports 0035_policy_on_anon_role (WARN, SECURITY) for permissive policies that apply to anon, and tells the user to use TO authenticated or an explicit role check.

Adds lint 0035 policy_on_anon_role, with docs, tests and a regenerated splinter.sql.

How: A permissive policy is checked when its role list is public (no TO clause or TO public) or names a role that anon is a member of (pg_has_role(anon, role, 'usage'), which includes explicit TO anon). Restrictive policies are skipped because they only narrow access. INSERT, UPDATE, DELETE and ALL policies that apply to anon are always flagged. SELECT policies are exempt only when the USING expression is the literal true (with or without parentheses), the deliberate public-read pattern. Every other SELECT policy that applies to anon is flagged, whether or not it uses auth. functions. That includes using (published), col = const and current_setting(...) expressions. Customers can dismiss findings that are intentional. storage and realtime are not excluded, as in 0003, so storage.objects policies are covered. There is no pgrst.db_schemas filter, because Storage and Realtime do not go through PostgREST. Known gaps are documented in docs/0035_policy_on_anon_role.md. Expressions are not analysed, so policies that already check auth.role() but have no TO clause are still flagged. Table grants are not checked. Related but distinct: #28 (is_anonymous claim on non-anon roles), #165 / #169 (IS NULL disjunct) and 0024 (always-true policies). The number 0035 leaves 0031 to 0034 to the open lint PRs.

Tests: the new pg_regress test passes (negative, positive, role-membership, storage.objects and resolution cases), as do queries_are_unionable and 0024. I ran only these three tests after the latest change, and the full suite earlier, where everything passed except 0026/0027. Those two failed locally only because pg_graphql is not installed here, on Postgres 16 rather than the CI Postgres 15/17 images, and this PR does not touch them. splinter.sql loads cleanly and bin/check_lints.py passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PJZ249z1wSBX4dxK9x8jRR

Flag permissive RLS policies that apply to the anon role, directly or
through public.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJZ249z1wSBX4dxK9x8jRR
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJZ249z1wSBX4dxK9x8jRR
@hf
hf marked this pull request as ready for review November 27, 2026 13:12
@hf
hf requested a review from a team as a code owner November 27, 2026 13:12

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant