Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
6 Skipped Deployments
|
📝 WalkthroughWalkthroughThe Row Level Security guide now invokes a dedicated AI prompt. The prompt covers policy design, performance, grants, application-side filtering, security-definer lookups, and pgTAP testing. ChangesRow-level security AI prompt
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
apps/docs/data/ai-prompts.data.ts (1)
187-190: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTarget the intended roles, not only
anonandauthenticated.Keep an explicit
TOclause, but allow the actual role set. PostgreSQL also supports custom role names and explicitPUBLIC. Hard-coding these two Supabase roles can create policies that never apply to a valid custom role. (postgresql.org)Suggested wording
- and always scope it with `to authenticated` or `to anon` — never leave - the role unspecified. + and always scope it with `to <intended role(s)>`. Use `authenticated` or + `anon` for the corresponding Supabase Data API roles, and use custom roles + when the database schema defines them.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/docs/data/ai-prompts.data.ts` around lines 187 - 190, Update the policy-writing guidance in the prompt to require an explicit TO clause while allowing any intended PostgreSQL role, including custom roles and PUBLIC, rather than restricting it to anon or authenticated. Preserve the existing per-operation and using/with check guidance.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/docs/data/ai-prompts.data.ts`:
- Around line 212-215: Update the pgTAP testing guidance in the prompt to avoid
presenting tests.rls_enabled() as a base pgTAP function: either remove it and
use only policies_are() and results_eq(), or explicitly require
basejump-supabase_test_helpers before invoking tests.rls_enabled().
- Around line 202-205: Update the SECURITY DEFINER guidance in the prompt text
to require an explicit safe search_path for every helper, using an empty path
with schema-qualified references or a trusted schema followed by pg_temp. Keep
the existing private-schema, revoked-public-execution, and auth.uid()
requirements, and ensure the guidance covers protection against shadowed
unqualified objects.
- Around line 202-205: Update the security-definer guidance in the prompt
content near the RLS helper-function instruction to require granting USAGE on
the private schema and EXECUTE on each helper function to every role that
evaluates the policy after revoking EXECUTE from public. Preserve the existing
requirements for a non-exposed schema and verifying auth.uid() inside the
function.
- Around line 191-198: Update the RLS performance guidance in the prompt around
items 3 and 4: remove the claim that SELECT wrappers only help stable or
immutable functions, and state that uncorrelated scalar subqueries may execute
as InitPlans but must be used only when their result and evaluation frequency
are valid for authorization. Revise the indexing rule to recommend indexing
policy columns only when they lack an existing index, with workload-impact
validation before retaining each index.
- Around line 187-190: Update the operation checklist in the prompt text to
explicitly require checking the necessary SELECT policy when defining UPDATE or
DELETE policies, including read visibility for affected rows alongside USING and
WITH CHECK requirements.
---
Nitpick comments:
In `@apps/docs/data/ai-prompts.data.ts`:
- Around line 187-190: Update the policy-writing guidance in the prompt to
require an explicit TO clause while allowing any intended PostgreSQL role,
including custom roles and PUBLIC, rather than restricting it to anon or
authenticated. Preserve the existing per-operation and using/with check
guidance.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 962cc97e-c5b5-45e6-8e8b-074e9bb6fca6
📒 Files selected for processing (2)
apps/docs/content/guides/database/postgres/row-level-security.mdxapps/docs/data/ai-prompts.data.ts
Reworks the row-level-security AI prompt after verifying each rule against the docs and running a head-to-head eval of the old and new text. - Drop `revoke execute` from the security definer rule. Every function the docs revoke EXECUTE on is RPC- or hook-called; the one policy-called helper (public.authorize) is deliberately not revoked. Policy expressions run with the calling role's privileges, so revoking from `authenticated` breaks every query on the table. - Require `set search_path = ''` on security definer helpers, per functions.mdx and the function_search_path_mutable advisor lint. - Correct the `force row level security` claim: it subjects the table owner to RLS but not superusers or `bypassrls` roles, and it silently breaks definer helpers that read a forced lookup table as its owner. - Split the pgTAP helper functions out of the core pgTAP rule. tests.rls_enabled() and friends ship with basejump-supabase_test_helpers via dbdev, so the previous wording produced test files that failed on first run. Plain pgTAP is now the default path. - Note that a denied update or delete raises nothing rather than 42501, since `using` filters the rows out. - Drop the stable/immutable/volatile wording, unsupported by the docs. - Point REFERENCE at three page-level URLs instead of a single anchor, matching the convention of the other 16 entries. Co-Authored-By: Claude Opus 5 <[email protected]>
Executing a generated suite against a local stack surfaced this: rule 10 said to "assert that it changed no rows" for a denied update or delete without saying how, and the natural reading produced invalid SQL. ERROR: WITH clause containing a data-modifying statement must be at the top level A data-modifying CTE cannot be nested inside is(), so the generated file aborted after 15 of 27 assertions. Rule 10 now prescribes lives_ok() followed by results_eq() on the unchanged row, which avoids CTE placement entirely. Re-running with that pattern passes 31/31. Every policy the prompt generated was already correct: anon denial via 42501, member and admin visibility, insert with check, and column-grant blocking all passed. The defect was only in the assertion shape. Co-Authored-By: Claude Opus 5 <[email protected]>
Rule 9 said to "begin the file with create extension ..., wrap it in begin;", which is ambiguous about ordering. A generated file put the create extension before begin;, so the extension fell outside the transaction and was never rolled back. Harmless in practice, but the testing docs put begin; first, so spell the order out explicitly. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
I wonder if we actually need to add this prompt to the docs rather than tracking it in evals somewhere? The underlying issue is coding hardness task completion. If the instructions in the docs are off, adding a prompt won't help and if the prompt is right we should be able to trust our docs.
To illustrate, there's a gap between the RLS guide and the prompt I noticed:
- Rules 1–8 of the prompt restate the guide.
- Rules 9–11 (the pgTAP testing walkthrough) only appear as an external link in the guide but the prompt actually walks through the steps it seems. Is that essential info? If so, why include only in the prompt and not in the guide?
Note also that AiPrompt is deliberately excluded from the markdown-export pipeline, so adding one as-is likely doesn't actually make a difference. Which gets us back to the question whether these prompts actually belong in the docs.
From the RFC:
"This project should not add agent-facing prompts by default... the relevant gaps will be addressed with clearer guide-local runnable instructions rather than with extra layers outside the guide."
(And my apologies, it slipped by me that the issue mentions "quick start", which draws a similarity to the AI prompts we added to our framework quickstarts recently. Those are for humans. The coding harness issue we're trying to solve is for agents).
Closes DOCS-1258
I have read the CONTRIBUTING.md file.
YES
Problem
The Row Level Security guide documents solid RLS performance and security recommendations, but there's nothing on the page an AI coding agent can be handed directly to make it follow those recommendations when writing or reviewing policies. Framework quickstarts already solve this with a copy-pasteable
AiPromptcomponent — the RLS guide didn't have one.Solution
Added an
<AiPrompt id="row-level-security" />panel at the top of the RLS guide, using the same pattern as the framework quickstarts. It hands an agent a checklist covering three things:security definerfunction in a private schemaselect, index the columns policies reference, avoid joins inside policies, and mirror the filter in application queriessupabase test dbContent was built from the doc's own performance section, the
security-rls-basics.md/security-rls-performance.mdreferences insupabase/agent-skills, and the RLS module ofsupabase/supacademy. Where those sources disagreed with the Supabase docs, the docs won.Verified with evals rather than by inspection: the prompt's generated output was applied to a local stack and exercised with
supabase test db. Several rules were corrected so that output runs cleanly, and the final run passes 31/31.REFERENCEpoints at three page-level URLs instead of a single section anchor, matching every other entry inai-prompts.data.ts.Files changed:
apps/docs/data/ai-prompts.data.ts— newrow-level-securityprompt entryapps/docs/content/guides/database/postgres/row-level-security.mdx— added<AiPrompt id="row-level-security" />after frontmatterManual testing
/guides/database/postgres/row-level-securityon Preview.AiPromptpanel on e.g./guides/getting-started/quickstarts/nextjs.REFERENCEblock listing three.mdURLs.pnpm typecheck --filter=docsandpnpm formatand confirm both pass.Summary by CodeRabbit