Repository navigation
feat: add policy_on_anon_role lint (0035) - #217
Open
claude[bot] wants to merge 2 commits into
Open
claude[bot] wants to merge 2 commits into
claude[bot] wants to merge 2 commits into
Conversation
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
marked this pull request as ready for review
November 27, 2026 13:12
This branch has not been deployed
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.
Requested by Stojan Dimitrovski, Etienne Stalmans · Slack thread
Before: Nothing warned about RLS policies that apply to the
anonrole. A Storage policy likefor all using ((storage.foldername(name))[1] = auth.uid()::text)with noTOclause applies topublic, which includesanon. A JWT with noroleclaim, such as an OIDC ID token issued to an OAuth client, runs asanonin PostgREST and Storage, andauth.uid()still returns itssub, so that token got access.After: The advisor reports
0035_policy_on_anon_role(WARN, SECURITY) for permissive policies that apply toanon, and tells the user to useTO authenticatedor an explicit role check.Adds lint 0035
policy_on_anon_role, with docs, tests and a regeneratedsplinter.sql.How: A permissive policy is checked when its role list is
public(noTOclause orTO public) or names a role thatanonis a member of (pg_has_role(anon, role, 'usage'), which includes explicitTO anon). Restrictive policies are skipped because they only narrow access.INSERT,UPDATE,DELETEandALLpolicies that apply toanonare always flagged.SELECTpolicies are exempt only when theUSINGexpression is the literaltrue(with or without parentheses), the deliberate public-read pattern. Every otherSELECTpolicy that applies toanonis flagged, whether or not it usesauth.functions. That includesusing (published),col = constandcurrent_setting(...)expressions. Customers can dismiss findings that are intentional.storageandrealtimeare not excluded, as in 0003, sostorage.objectspolicies are covered. There is nopgrst.db_schemasfilter, because Storage and Realtime do not go through PostgREST. Known gaps are documented indocs/0035_policy_on_anon_role.md. Expressions are not analysed, so policies that already checkauth.role()but have noTOclause are still flagged. Table grants are not checked. Related but distinct: #28 (is_anonymousclaim on non-anonroles), #165 / #169 (IS NULLdisjunct) 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.objectsand resolution cases), as doqueries_are_unionableand0024. 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 becausepg_graphqlis not installed here, on Postgres 16 rather than the CI Postgres 15/17 images, and this PR does not touch them.splinter.sqlloads cleanly andbin/check_lints.pypasses.🤖 Generated with Claude Code
https://claude.ai/code/session_01PJZ249z1wSBX4dxK9x8jRR