<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BuiltSafely</title>
    <description>The latest articles on DEV Community by BuiltSafely (@builtsafely).</description>
    <link>https://dev.to/builtsafely</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4189743%2F0dc1bdfc-bd03-4f50-a5e8-e47994abcffd.png</url>
      <title>DEV Community: BuiltSafely</title>
      <link>https://dev.to/builtsafely</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/builtsafely"/>
    <language>en</language>
    <item>
      <title>Securing a Lovable app before you publish: scans, Secrets and RLS</title>
      <dc:creator>BuiltSafely</dc:creator>
      <pubDate>Wed, 28 Oct 2026 14:10:05 +0000</pubDate>
      <link>https://dev.to/builtsafely-org/securing-a-lovable-app-before-you-publish-scans-secrets-and-rls-1gk1</link>
      <guid>https://dev.to/builtsafely-org/securing-a-lovable-app-before-you-publish-scans-secrets-and-rls-1gk1</guid>
      <description>&lt;p&gt;Shipping a Lovable app is fast, and the security tooling that comes with it is genuinely useful, but it only helps if you run it and read what it finds. This walkthrough covers the six things worth doing before real users sign up: both scans, secrets, database rules, leaked-password protection, sign-in methods and a focused review. Every step points to the Lovable doc it comes from, so you can check the current wording yourself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;AI disclosure:&lt;/strong&gt; This article was written with AI. An AI agent adapted it from our original guide, and every claim links to the official source it came from. Steps marked &lt;strong&gt;Verified&lt;/strong&gt; were run by us in a throwaway test environment; steps marked &lt;strong&gt;Docs-only&lt;/strong&gt; come from the official docs and were not run end to end.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Label for every step in this guide: Docs-only.&lt;/strong&gt; We wrote it from Lovable's public docs (last reviewed October 21, 2026) and did not run these steps end to end. Source overview: &lt;a href="https://docs.lovable.dev/features/security" rel="noopener noreferrer"&gt;Lovable docs: Security overview&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Lovable's own docs say its tools "do not replace a thorough security review" and that you are responsible for your app's security. Here's how to use them well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Copy this fix
&lt;/h2&gt;

&lt;p&gt;Run both security scans first, then paste this prompt into the project chat. Treat the answer as a to-do list to check, not a guarantee.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Review the authentication flow and every server-side function in my app. For each one,
tell me who can call it, what data it can read or change, and whether it checks the
caller's identity and role.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  1. Run both scans
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Quick scan&lt;/strong&gt; runs automatically when you open the publish dialog. It checks database access rules (for example, tables without row-level security, or rules that let everyone through), dependency vulnerabilities, and MCP servers exposed without authentication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep scan&lt;/strong&gt; doesn't run automatically. Run it from the project's Security view before you publish. It reviews your app code for access-control gaps, unauthenticated endpoints, injection, leaked secrets, payment/billing logic and auth weaknesses.&lt;/li&gt;
&lt;li&gt;Fix every &lt;strong&gt;Critical&lt;/strong&gt; finding. Read each &lt;strong&gt;Warning&lt;/strong&gt; and decide on purpose. Don't just ignore it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A scan is a starting point, not a sign-off.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Keep API keys in Secrets, and call APIs from server-side code
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Lovable's frontend runs in the browser, so secrets can't be stored safely there. Its docs recommend storing keys in &lt;strong&gt;Secrets&lt;/strong&gt; and making third-party API calls from server-side functions, which your frontend then calls.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manage secrets in &lt;strong&gt;More â†’ Settings â†’ Secrets&lt;/strong&gt; (&lt;a href="https://docs.lovable.dev/features/secrets" rel="noopener noreferrer"&gt;Lovable docs: Secrets&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Your server-side functions are listed in &lt;strong&gt;More â†’ Database â†’ Manage â†’ Edge functions&lt;/strong&gt; (&lt;a href="https://docs.lovable.dev/features/edge-functions" rel="noopener noreferrer"&gt;Lovable docs: Edge functions&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;If you pasted a key into chat, move it to Secrets and rotate it at the provider.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More on this: &lt;a href="https://builtsafely.com/fixes/secret-key-in-frontend-bundle/" rel="noopener noreferrer"&gt;Check what your build actually ships: secret keys in frontend env vars&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Review your RLS policies yourself
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Lovable's docs call misconfigured RLS "a common cause of data leaks". To review every policy, go to &lt;strong&gt;More â†’ Database&lt;/strong&gt;, select &lt;strong&gt;Manage&lt;/strong&gt;, then &lt;strong&gt;Policies&lt;/strong&gt;. Each row shows the policy name, the command it covers (&lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt; or &lt;code&gt;DELETE&lt;/code&gt;), who it applies to (such as signed-in &lt;code&gt;authenticated&lt;/code&gt; or &lt;code&gt;anon&lt;/code&gt; users), and whether it has a condition. Expand a row to read its SQL condition.&lt;/p&gt;

&lt;p&gt;The view is read-only, so to change a policy, ask Lovable in the project chat, then check the result in the view (&lt;a href="https://docs.lovable.dev/features/database-access" rel="noopener noreferrer"&gt;Lovable docs: Control who can access your app's data&lt;/a&gt;). Then read our &lt;a href="https://builtsafely.com/guides/supabase-rls/" rel="noopener noreferrer"&gt;Supabase RLS guide&lt;/a&gt; and test with two accounts.&lt;/p&gt;

&lt;p&gt;On the built-in backend you can also ask Lovable to &lt;strong&gt;rotate the database password&lt;/strong&gt;, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rotate my database password.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lovable asks you to confirm, doesn't show the new password, and your app keeps working. Any BI tool or script that someone connected with the old password stops working until it's updated. This applies only to the built-in backend, not to a connected Supabase project (same Lovable page).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check:&lt;/strong&gt; in &lt;strong&gt;More â†’ Database â†’ Manage â†’ Policies&lt;/strong&gt;, each policy's &lt;strong&gt;Applies to&lt;/strong&gt; and condition match who should see or change those rows.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Turn on leaked-password protection
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If your app uses email and password sign-in, turn on &lt;strong&gt;Password HIBP check&lt;/strong&gt; in &lt;strong&gt;More â†’ Users â†’ Settings â†’ Email&lt;/strong&gt;. It rejects passwords found in the Have I Been Pwned database of leaked passwords (&lt;a href="https://docs.lovable.dev/features/email-auth" rel="noopener noreferrer"&gt;Lovable docs: Email authentication&lt;/a&gt;). If you connected Supabase directly, use the Supabase equivalent.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Review your sign-in methods
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Unless you name the methods you want, Lovable's login pages for apps on the built-in backend (Cloud) include email and password, Google, and &lt;strong&gt;Sign in with Lovable&lt;/strong&gt; (&lt;a href="https://docs.lovable.dev/changelog" rel="noopener noreferrer"&gt;Lovable changelog, Oct 15, 2026&lt;/a&gt;). With Sign in with Lovable, "Any Lovable account can sign in," and your app receives the person's name, email address and profile picture (&lt;a href="https://docs.lovable.dev/features/lovable-auth" rel="noopener noreferrer"&gt;Lovable docs: Sign in with Lovable&lt;/a&gt;).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open &lt;strong&gt;More â†’ Users â†’ Settings&lt;/strong&gt;. The &lt;strong&gt;Sign in methods&lt;/strong&gt; list shows each method as &lt;strong&gt;Enabled&lt;/strong&gt; or &lt;strong&gt;Disabled&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Turn off any method you don't mean to offer.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Disable sign-up&lt;/strong&gt; if new people shouldn't be able to join (&lt;a href="https://docs.lovable.dev/features/authentication" rel="noopener noreferrer"&gt;Lovable docs: Users and authentication&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Keep at least one method enabled so existing users can get back in.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;OpenID Connect (OIDC) sign-in&lt;/strong&gt; lets your users sign in with your own identity provider, such as Auth0, Okta, Microsoft Entra ID or Keycloak. Your provider then decides who can sign in and applies its own password and MFA rules (&lt;a href="https://docs.lovable.dev/features/oidc-auth" rel="noopener noreferrer"&gt;Lovable docs: OIDC sign-in&lt;/a&gt;). Steps and limits, all from that page:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What it needs:&lt;/strong&gt; a project on the built-in backend (Cloud) with authentication on, edit access, and admin access to your OIDC provider. It's available on all plans. On Business and Enterprise workspaces, &lt;strong&gt;SAML SSO&lt;/strong&gt; must be allowed under &lt;strong&gt;App login methods&lt;/strong&gt;, because that one setting covers OIDC too. It isn't available for self-hosted backends.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set it up:&lt;/strong&gt; go to &lt;strong&gt;More â†’ Users â†’ Settings â†’ OIDC&lt;/strong&gt;, enable &lt;strong&gt;OIDC sign-in&lt;/strong&gt; and copy the &lt;strong&gt;Redirect URI&lt;/strong&gt;. Register a web application with your provider and add that redirect URI. Then enter the &lt;strong&gt;Issuer URL&lt;/strong&gt; (must start with &lt;code&gt;https://&lt;/code&gt;), &lt;strong&gt;Client ID&lt;/strong&gt; and &lt;strong&gt;Client secret&lt;/strong&gt; in the form and save. Lovable runs a build that adds the sign-in button, and that build uses credits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the client secret out of chat:&lt;/strong&gt; enter it in the OIDC form, not in the project chat. Lovable keeps it masked. To rotate it, enter the new secret and save.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test it:&lt;/strong&gt; open your sign-in page in a private window, use the new button, and confirm you come back signed in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know the limits:&lt;/strong&gt; one OIDC provider per project, and the scopes are fixed to &lt;code&gt;openid&lt;/code&gt;, &lt;code&gt;profile&lt;/code&gt; and &lt;code&gt;email&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If an app or website you didn't build on Lovable signs people in through Lovable, it uses an OAuth client that a workspace admin registers under &lt;strong&gt;Workspace settings â†’ API keys &amp;amp; OAuth â†’ OAuth clients&lt;/strong&gt;. A Web server client's secret is shown only once. Lovable says: "Do not put it in browser code, a public repository, or a prompt." Scopes that read or change projects and workspaces need a Business or Enterprise plan and verification by Lovable (&lt;a href="https://docs.lovable.dev/features/oauth-clients" rel="noopener noreferrer"&gt;Lovable docs: OAuth clients&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check:&lt;/strong&gt; your login page offers only the sign-in methods you chose, and every other method shows &lt;strong&gt;Disabled&lt;/strong&gt; in &lt;strong&gt;More â†’ Users â†’ Settings&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Ask for a focused review, then verify
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Use the prompt from &lt;strong&gt;Copy this fix&lt;/strong&gt; above. Conversational reviews use credits (per Lovable's docs). Treat the answer as a to-do list to check, not a guarantee.&lt;/p&gt;

&lt;p&gt;For apps handling sensitive data or payments, Lovable's docs suggest an additional professional security review. We agree.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/fixes/secret-key-in-frontend-bundle/" rel="noopener noreferrer"&gt;Check what your build actually ships: secret keys in frontend env vars&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/fixes/new-row-violates-rls/" rel="noopener noreferrer"&gt;new row violates row-level security policy (Supabase)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/guides/supabase-rls/" rel="noopener noreferrer"&gt;Supabase row-level security, explained for builders&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;This guide is educational and based on the vendor's public docs as of the review date. Platforms change: check the linked sources. Not a security audit. &lt;a href="https://builtsafely.com/disclaimer/" rel="noopener noreferrer"&gt;Disclaimer&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>webdev</category>
      <category>ai</category>
      <category>beginners</category>
    </item>
    <item>
      <title>infinite recursion detected in policy for relation (42P17)</title>
      <dc:creator>BuiltSafely</dc:creator>
      <pubDate>Tue, 27 Oct 2026 14:12:07 +0000</pubDate>
      <link>https://dev.to/builtsafely-org/infinite-recursion-detected-in-policy-for-relation-42p17-2c6f</link>
      <guid>https://dev.to/builtsafely-org/infinite-recursion-detected-in-policy-for-relation-42p17-2c6f</guid>
      <description>&lt;p&gt;If your Supabase queries suddenly fail with "infinite recursion detected in policy for relation", the cause is almost always a row-level security policy that ends up checking itself. The tempting shortcut is to switch RLS off, which removes the error by removing your access rules. Below is the fix we tested instead: move the lookup into a small private helper function and keep RLS on.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;AI disclosure:&lt;/strong&gt; This article was written with AI. An AI agent adapted it from our original guide, and every claim links to the official source it came from. Steps marked &lt;strong&gt;Verified&lt;/strong&gt; were run by us in a throwaway test environment; steps marked &lt;strong&gt;Docs-only&lt;/strong&gt; come from the official docs and were not run end to end.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Last checked October 19, 2026 Â· Educational, not an audit.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Verified:&lt;/strong&gt; we ran this in a throwaway local Postgres 17 database (not a full Supabase stack). Details under &lt;em&gt;What we tested&lt;/em&gt; below.&lt;/p&gt;

&lt;p&gt;Stop the policy from querying its own table (or a chain of tables that loops back). Move the lookup into a &lt;code&gt;SECURITY DEFINER&lt;/code&gt; function in a private schema, pin &lt;code&gt;search_path&lt;/code&gt;, then call that function from the policy. Keep RLS on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="k"&gt;schema&lt;/span&gt; &lt;span class="n"&gt;if&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="k"&gt;exists&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Look up the caller's team ids without re-entering the policy&lt;/span&gt;
&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="k"&gt;replace&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;my_team_ids&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;returns&lt;/span&gt; &lt;span class="k"&gt;setof&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;
&lt;span class="k"&gt;language&lt;/span&gt; &lt;span class="k"&gt;sql&lt;/span&gt;
&lt;span class="k"&gt;stable&lt;/span&gt;
&lt;span class="k"&gt;security&lt;/span&gt; &lt;span class="k"&gt;definer&lt;/span&gt;
&lt;span class="k"&gt;set&lt;/span&gt; &lt;span class="n"&gt;search_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
&lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;
  &lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;team_id&lt;/span&gt;
  &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;
  &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;revoke&lt;/span&gt; &lt;span class="k"&gt;all&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;my_team_ids&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;grant&lt;/span&gt; &lt;span class="k"&gt;usage&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;schema&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;authenticated&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;grant&lt;/span&gt; &lt;span class="k"&gt;execute&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;my_team_ids&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;authenticated&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;drop&lt;/span&gt; &lt;span class="n"&gt;policy&lt;/span&gt; &lt;span class="n"&gt;if&lt;/span&gt; &lt;span class="k"&gt;exists&lt;/span&gt; &lt;span class="nv"&gt;"members read their teams"&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;create&lt;/span&gt; &lt;span class="n"&gt;policy&lt;/span&gt; &lt;span class="nv"&gt;"members read their teams"&lt;/span&gt;
&lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;select&lt;/span&gt;
&lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;authenticated&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;team_id&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;my_team_ids&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;members&lt;/code&gt; and &lt;code&gt;team_id&lt;/code&gt; with your table and columns.&lt;/p&gt;

&lt;p&gt;That shape follows Supabase's security-definer guidance: run as the creator (which bypasses RLS on the lookup), pin &lt;code&gt;search_path = ''&lt;/code&gt;, schema-qualify names, and keep the function out of an exposed schema (&lt;a href="https://supabase.com/docs/guides/database/postgres/row-level-security" rel="noopener noreferrer"&gt;Supabase: RLS&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we tested (October 19, 2026):&lt;/strong&gt; on a throwaway local Postgres 17, a self-referencing &lt;code&gt;SELECT&lt;/code&gt; policy on &lt;code&gt;members&lt;/code&gt; raised &lt;code&gt;ERROR: infinite recursion detected in policy for relation "members"&lt;/code&gt;. After adding the private helper above (with a stand-in JWT claim for &lt;code&gt;auth.uid()&lt;/code&gt;), a user saw only their team's rows, and a second user saw both teams they belonged to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it happens
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Supabase's troubleshooting page says this error is "infinite recursion in your Row-Level Security (RLS) policies." It happens when a policy queries a table that has RLS, and that table's policies end up triggering the original policy again: either the same table, or another table that loops back (&lt;a href="https://supabase.com/docs/guides/troubleshooting/storage-error-database-schema-is-incompatible-when-uploading-files-988baa" rel="noopener noreferrer"&gt;Supabase troubleshooting: RLS policy causes infinite recursion&lt;/a&gt;). Postgres raises SQLSTATE &lt;code&gt;42P17&lt;/code&gt; and aborts the query (&lt;a href="https://www.postgresql.org/docs/current/errcodes-appendix.html" rel="noopener noreferrer"&gt;PostgreSQL error codes&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;A common pattern is "show every member of any team I belong to" written as a subquery on the same &lt;code&gt;members&lt;/code&gt; table. Evaluating the policy runs the subquery, which re-enters the policy.&lt;/p&gt;

&lt;h2&gt;
  
  
  What not to do
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't disable RLS to clear the error.&lt;/li&gt;
&lt;li&gt;Don't put a secret or &lt;code&gt;service_role&lt;/code&gt; key in the client to "bypass" it (&lt;a href="https://supabase.com/docs/guides/getting-started/api-keys" rel="noopener noreferrer"&gt;Supabase: API keys&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;Don't leave a &lt;code&gt;SECURITY DEFINER&lt;/code&gt; function in an exposed schema, and don't skip &lt;code&gt;set search_path = ''&lt;/code&gt;. Supabase warns both are risky (&lt;a href="https://supabase.com/docs/guides/database/postgres/row-level-security" rel="noopener noreferrer"&gt;Supabase: RLS&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Copy this fix: AI prompt
&lt;/h2&gt;

&lt;p&gt;Paste this into your AI coding tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My app hits: infinite recursion detected in policy for relation (42P17).
Find any RLS policy that queries its own table or forms a policy loop.
Propose a private SECURITY DEFINER helper with set search_path = '', revoke public execute, and a rewritten policy that calls it.
Do not disable RLS. Do not use a secret or service_role key in client code.
Show the SQL first and wait for my OK before applying anything.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to verify (two accounts)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Verified&lt;/strong&gt; in our local test with two stand-in users; run it against your own app too.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sign in as user A. Confirm you can read the rows you should (for example your team's members).&lt;/li&gt;
&lt;li&gt;Sign in as user B on another team. Confirm you see B's teams, not A's private rows.&lt;/li&gt;
&lt;li&gt;Sign out. Confirm signed-out requests get no private rows.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Related
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/guides/supabase-rls/" rel="noopener noreferrer"&gt;Our Supabase RLS guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/fixes/new-row-violates-rls/" rel="noopener noreferrer"&gt;new row violates row-level security policy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/fixes/supabase-empty-array-rls/" rel="noopener noreferrer"&gt;Empty array with RLS on&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Educational, not a security audit. Platforms change: check the linked sources. &lt;a href="https://builtsafely.com/disclaimer/" rel="noopener noreferrer"&gt;Disclaimer&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>supabase</category>
      <category>postgres</category>
      <category>security</category>
      <category>sql</category>
    </item>
    <item>
      <title>42501 permission denied for table</title>
      <dc:creator>BuiltSafely</dc:creator>
      <pubDate>Mon, 26 Oct 2026 14:22:00 +0000</pubDate>
      <link>https://dev.to/builtsafely-org/42501-permission-denied-for-table-2hhg</link>
      <guid>https://dev.to/builtsafely-org/42501-permission-denied-for-table-2hhg</guid>
      <description>&lt;p&gt;A 42501 "permission denied for table" error means the database role making the request was never granted access to that table, so Postgres stops before your row-level security policies even run. It often shows up after adding a table or running a migration, and some clients report it as a plain 401 or 403. The fix is a precise grant, not turning security off; here is how to find the missing privilege and add it safely.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;AI disclosure:&lt;/strong&gt; This article was written with AI. An AI agent adapted it from our original guide, and every claim links to the official source it came from. Steps marked &lt;strong&gt;Verified&lt;/strong&gt; were run by us in a throwaway test environment; steps marked &lt;strong&gt;Docs-only&lt;/strong&gt; come from the official docs and were not run end to end.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Last checked October 19, 2026 · Educational, not an audit.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Verified:&lt;/strong&gt; we ran this against a throwaway local Supabase Postgres 17 container (no real project). Details under &lt;em&gt;What we tested&lt;/em&gt; below.&lt;/p&gt;

&lt;p&gt;Grant the role the privilege it's missing, in a migration, and keep RLS on. The error's hint tells you which role and privilege it needs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Signed-in users manage their own notes; signed-out visitors get nothing&lt;/span&gt;
&lt;span class="k"&gt;grant&lt;/span&gt; &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;authenticated&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;alter&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt; &lt;span class="k"&gt;level&lt;/span&gt; &lt;span class="k"&gt;security&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- ...plus one policy per operation (see our RLS guide)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;notes&lt;/code&gt; with your table. Grant only what each role needs. Only grant to &lt;code&gt;anon&lt;/code&gt; for data that's meant to be public.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we tested (October 16, 2026):&lt;/strong&gt; without a grant, a signed-out read failed with &lt;code&gt;42501: permission denied for table notes&lt;/code&gt; and the hint "Grant the required privileges to the current role with: GRANT SELECT ON public.notes TO anon;". A public table with &lt;code&gt;grant select ... to anon&lt;/code&gt;, RLS on and a read-only policy returned its rows to &lt;code&gt;anon&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it happens
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only, except where marked&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Postgres checks grants before policies. Supabase's RLS guide says a missing grant "raises a &lt;code&gt;42501&lt;/code&gt; error before any policy runs", so check grants before you change policies (&lt;a href="https://supabase.com/docs/guides/database/postgres/row-level-security" rel="noopener noreferrer"&gt;Supabase: RLS&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;To see a table's grants (&lt;a href="https://supabase.com/docs/guides/troubleshooting/database-api-42501-errors" rel="noopener noreferrer"&gt;Supabase: 42501 errors&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="n"&gt;grantee&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;privilege_type&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;information_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;role_table_grants&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'notes'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Verified:&lt;/strong&gt; on the same test container, this listed the roles and privileges for the table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why you may see it more on tables created on or after October 30, 2026:&lt;/strong&gt; Supabase applies a changed default to all existing projects on that date. &lt;strong&gt;Existing tables keep their current grants and stay reachable.&lt;/strong&gt; Only tables created in &lt;code&gt;public&lt;/code&gt; after the change need an explicit grant before the Data API can see them. Direct Postgres connections are unaffected (&lt;a href="https://supabase.com/changelog/45329-breaking-change-tables-not-exposed-to-data-and-graphql-api-automatically" rel="noopener noreferrer"&gt;Supabase changelog&lt;/a&gt;). Our &lt;a href="https://builtsafely.com/guides/supabase-oct30-grants/" rel="noopener noreferrer"&gt;Oct 30 grants guide&lt;/a&gt; covers the migration pattern.&lt;/p&gt;

&lt;p&gt;Clients often surface 42501 as a 401 or 403, so read the response body for &lt;code&gt;permission denied for table&lt;/code&gt; (&lt;a href="https://supabase.com/docs/guides/troubleshooting/database-api-42501-errors" rel="noopener noreferrer"&gt;Supabase: 42501 errors&lt;/a&gt;). Not every 42501 is a missing grant: Supabase also lists restricted schemas, custom schemas without API grants, column-level restrictions, and RLS blocking an insert or update. If the message says "new row violates row-level security policy", see our &lt;a href="https://builtsafely.com/fixes/new-row-violates-rls/" rel="noopener noreferrer"&gt;RLS error fix&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you limited updates to certain columns on purpose, for example so users can't change their own role, a 42501 on those columns is that protection working. See &lt;a href="https://builtsafely.com/guides/editable-access-field/" rel="noopener noreferrer"&gt;Never let users edit the field your access rule trusts&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What not to do
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Docs-only&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't disable RLS.&lt;/li&gt;
&lt;li&gt;Don't grant everything to &lt;code&gt;anon&lt;/code&gt; without policies.&lt;/li&gt;
&lt;li&gt;Don't move the secret or &lt;code&gt;service_role&lt;/code&gt; key into the frontend (&lt;a href="https://supabase.com/docs/guides/getting-started/api-keys" rel="noopener noreferrer"&gt;Supabase: API keys&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Treat grant + enable RLS + policies as one unit in the same migration (&lt;a href="https://supabase.com/changelog/45329-breaking-change-tables-not-exposed-to-data-and-graphql-api-automatically" rel="noopener noreferrer"&gt;Supabase changelog&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Copy this fix
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Replace notes with your table. Signed-out visitors get nothing.&lt;/span&gt;
&lt;span class="k"&gt;grant&lt;/span&gt; &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;authenticated&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;alter&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="n"&gt;enable&lt;/span&gt; &lt;span class="k"&gt;row&lt;/span&gt; &lt;span class="k"&gt;level&lt;/span&gt; &lt;span class="k"&gt;security&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- ...plus one policy per operation (see our RLS guide)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Grant only what each role needs, and keep RLS on. Policy examples: &lt;a href="https://builtsafely.com/guides/supabase-rls/" rel="noopener noreferrer"&gt;Supabase row-level security, explained for builders&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/fixes/new-row-violates-rls/" rel="noopener noreferrer"&gt;new row violates row-level security policy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/guides/supabase-oct30-grants/" rel="noopener noreferrer"&gt;Supabase's Oct 30 change: new tables need a GRANT&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://builtsafely.com/fixes/infinite-recursion-policy/" rel="noopener noreferrer"&gt;infinite recursion detected in policy for relation (42P17)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Educational, not a security audit. Platforms change: check the linked sources. &lt;a href="https://builtsafely.com/disclaimer/" rel="noopener noreferrer"&gt;Disclaimer&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>supabase</category>
      <category>postgres</category>
      <category>security</category>
      <category>database</category>
    </item>
  </channel>
</rss>
