<?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: LeakPatrol</title>
    <description>The latest articles on DEV Community by LeakPatrol (@leakpatrol).</description>
    <link>https://dev.to/leakpatrol</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%2F4192181%2Fd6874922-d45c-4a06-8094-57e9731cc3f7.png</url>
      <title>DEV Community: LeakPatrol</title>
      <link>https://dev.to/leakpatrol</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leakpatrol"/>
    <language>en</language>
    <item>
      <title>Is your Supabase anon key safe in the frontend? Yes. Here's what isn't.</title>
      <dc:creator>LeakPatrol</dc:creator>
      <pubDate>Sun, 18 Oct 2026 13:36:43 +0000</pubDate>
      <link>https://dev.to/leakpatrol/is-your-supabase-anon-key-safe-in-the-frontend-yes-heres-what-isnt-5919</link>
      <guid>https://dev.to/leakpatrol/is-your-supabase-anon-key-safe-in-the-frontend-yes-heres-what-isnt-5919</guid>
      <description>&lt;p&gt;If you've built an app with Lovable, Bolt, v0 or Cursor on top of Supabase, you've probably opened DevTools, seen a long &lt;code&gt;eyJ...&lt;/code&gt; key in your JavaScript, and felt your stomach drop.&lt;/p&gt;

&lt;p&gt;Good news first: &lt;strong&gt;that key is supposed to be there.&lt;/strong&gt; Here's what it actually does, and the four things that &lt;em&gt;do&lt;/em&gt; leak data in AI-built Supabase apps.&lt;/p&gt;

&lt;h2&gt;
  
  
  The anon key is public by design
&lt;/h2&gt;

&lt;p&gt;Supabase gives every project two kinds of key:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Key&lt;/th&gt;
&lt;th&gt;Starts with&lt;/th&gt;
&lt;th&gt;Where it belongs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;anon / publishable&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;eyJ...&lt;/code&gt; (role &lt;code&gt;anon&lt;/code&gt;) or &lt;code&gt;sb_publishable_&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;The browser. Fine to ship.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;service_role / secret&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;eyJ...&lt;/code&gt; (role &lt;code&gt;service_role&lt;/code&gt;) or &lt;code&gt;sb_secret_&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Only on a server. Never in the browser.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The anon key just identifies your project. On its own it grants nothing: what someone can do with it is decided entirely by your &lt;strong&gt;Row Level Security (RLS)&lt;/strong&gt; policies.&lt;/p&gt;

&lt;p&gt;That's also the catch. &lt;strong&gt;The anon key is safe only if RLS is doing its job.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Tables with RLS turned off
&lt;/h2&gt;

&lt;p&gt;With RLS off, anyone who copies your anon key out of your JavaScript can read, and often write, the whole table with a single request. No login needed.&lt;/p&gt;

&lt;p&gt;Check every table in the SQL editor:&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;tablename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rowsecurity&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pg_tables&lt;/span&gt;
&lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;schemaname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'public'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anything showing &lt;code&gt;false&lt;/code&gt; is open. Turn it on and add a policy that ties rows to their owner:&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;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;profiles&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="k"&gt;create&lt;/span&gt; &lt;span class="n"&gt;policy&lt;/span&gt; &lt;span class="nv"&gt;"Users read their own profile"&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;profiles&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;using&lt;/span&gt; &lt;span class="p"&gt;(&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Watch out for policies with &lt;code&gt;using (true)&lt;/code&gt;. They turn RLS on but let everyone through, which AI tools sometimes generate to "fix" a permissions error.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The service_role key in the browser
&lt;/h2&gt;

&lt;p&gt;The service_role (or &lt;code&gt;sb_secret_&lt;/code&gt;) key &lt;strong&gt;bypasses RLS completely&lt;/strong&gt;. If it's in your frontend, every table is open no matter how good your policies are.&lt;/p&gt;

&lt;p&gt;AI tools usually put it there by accident: a &lt;code&gt;VITE_SUPABASE_SERVICE_ROLE_KEY&lt;/code&gt; or &lt;code&gt;NEXT_PUBLIC_...&lt;/code&gt; variable, added to make an admin feature work. &lt;strong&gt;Anything prefixed &lt;code&gt;VITE_&lt;/code&gt;, &lt;code&gt;NEXT_PUBLIC_&lt;/code&gt; or &lt;code&gt;REACT_APP_&lt;/code&gt; is bundled into the JavaScript every visitor downloads.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you find it: rotate the key in Supabase (Settings → API) right away, then move the admin work into an Edge Function that reads the key from Supabase secrets.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Storage buckets
&lt;/h2&gt;

&lt;p&gt;Storage has its own policies, separate from your table RLS, and they're easy to forget. A "public" bucket means anyone with a file's URL can download it. Fine for avatars, not for invoices, ID photos or exports.&lt;/p&gt;

&lt;p&gt;In Storage, check which buckets are public, and give private ones policies on &lt;code&gt;storage.objects&lt;/code&gt;, just like tables.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Views and functions that skip RLS
&lt;/h2&gt;

&lt;p&gt;Two quieter ones:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Views&lt;/strong&gt; run with their creator's rights by default, so a view over a protected table can expose it. On Postgres 15+, create them with &lt;code&gt;with (security_invoker = on)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Functions marked &lt;code&gt;SECURITY DEFINER&lt;/code&gt;&lt;/strong&gt; also run with their owner's rights. If one is callable through the API, check it only returns what the caller should see.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The 2-minute check
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open your live app, then DevTools → Sources, and search for &lt;code&gt;service_role&lt;/code&gt;, &lt;code&gt;sb_secret_&lt;/code&gt;, &lt;code&gt;sk-&lt;/code&gt; and &lt;code&gt;sk_live&lt;/code&gt;. You should find none.&lt;/li&gt;
&lt;li&gt;Run the SQL above. Every table should show &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Look for &lt;code&gt;using (true)&lt;/code&gt; in your policies.&lt;/li&gt;
&lt;li&gt;Check which storage buckets are public.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you'd rather not do it by hand, I built &lt;a href="https://www.getleakpatrol.com/?ref=devto" rel="noopener noreferrer"&gt;LeakPatrol&lt;/a&gt;, a free read-only check that looks for leaked keys, a public &lt;code&gt;.env&lt;/code&gt; and missing security headers, and, once you prove you own the site, which Supabase tables can be read without logging in. Each finding comes with a prompt you can paste back into your AI tool to fix it.&lt;/p&gt;

&lt;p&gt;The anon key was never the problem. What you've built around it is what counts.&lt;/p&gt;

</description>
      <category>supabase</category>
      <category>security</category>
      <category>webdev</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
