<?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: Milo Kits</title>
    <description>The latest articles on DEV Community by Milo Kits (@milokits).</description>
    <link>https://dev.to/milokits</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%2F4206062%2F2fa3e6f5-829e-49f4-9bd2-87cec1910f69.png</url>
      <title>DEV Community: Milo Kits</title>
      <link>https://dev.to/milokits</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/milokits"/>
    <language>en</language>
    <item>
      <title>Is your API key in your JavaScript? VITE_ and NEXT_PUBLIC_ explained</title>
      <dc:creator>Milo Kits</dc:creator>
      <pubDate>Sun, 25 Oct 2026 06:39:46 +0000</pubDate>
      <link>https://dev.to/milokits/is-your-api-key-in-your-javascript-vite-and-nextpublic-explained-1k10</link>
      <guid>https://dev.to/milokits/is-your-api-key-in-your-javascript-vite-and-nextpublic-explained-1k10</guid>
      <description>&lt;p&gt;If your code reads an API key through a variable starting with &lt;code&gt;VITE_&lt;/code&gt;, &lt;code&gt;NEXT_PUBLIC_&lt;/code&gt; or &lt;code&gt;REACT_APP_&lt;/code&gt;, that key is in your public JavaScript and anyone can copy it. An environment variable keeps it out of your Git repo, not out of the browser: the build tool pastes the value into the bundle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the prefix matters
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vite&lt;/strong&gt; (Lovable, Bolt): &lt;code&gt;VITE_&lt;/code&gt; variables are exposed in client code, and the Vite docs say they shouldn't hold secrets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Next.js&lt;/strong&gt; (v0, many Cursor projects): &lt;code&gt;NEXT_PUBLIC_&lt;/code&gt; variables are inlined into the browser JavaScript at build time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create React App&lt;/strong&gt;: same for &lt;code&gt;REACT_APP_&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hardcoding a key in a component is the same problem. If the browser runs the code, the browser has the key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Safe in the browser vs secret
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Usually fine in frontend code&lt;/th&gt;
&lt;th&gt;Never in frontend code&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Supabase anon / &lt;code&gt;sb_publishable_&lt;/code&gt; key (with RLS)&lt;/td&gt;
&lt;td&gt;Supabase &lt;code&gt;service_role&lt;/code&gt; / &lt;code&gt;sb_secret_&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stripe &lt;code&gt;pk_live_...&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Stripe &lt;code&gt;sk_live_...&lt;/code&gt; or &lt;code&gt;rk_...&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firebase web config&lt;/td&gt;
&lt;td&gt;Firebase Admin service account JSON&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Map keys restricted by domain&lt;/td&gt;
&lt;td&gt;OpenAI, Anthropic, Gemini, Resend, Twilio, AWS keys, database URLs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Check your live site in two minutes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open your live site, then DevTools (F12) &amp;gt; Sources. Press Ctrl/Cmd+Shift+F to search all files.&lt;/li&gt;
&lt;li&gt;Search for: &lt;code&gt;sk-&lt;/code&gt;, &lt;code&gt;sk_live&lt;/code&gt;, &lt;code&gt;rk_live&lt;/code&gt;, &lt;code&gt;service_role&lt;/code&gt;, &lt;code&gt;sb_secret_&lt;/code&gt;, &lt;code&gt;AKIA&lt;/code&gt;, &lt;code&gt;re_&lt;/code&gt;, &lt;code&gt;SG.&lt;/code&gt;, &lt;code&gt;-----BEGIN&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In the Network tab: if the browser calls &lt;code&gt;api.openai.com&lt;/code&gt; directly, the key is in the browser.&lt;/li&gt;
&lt;li&gt;Locally, after &lt;code&gt;npm run build&lt;/code&gt;, search &lt;code&gt;dist/&lt;/code&gt; or &lt;code&gt;.next/&lt;/code&gt; for the same strings.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The fix: call the API from the server
&lt;/h2&gt;

&lt;p&gt;The browser calls your own endpoint (an API route, serverless function or Supabase Edge Function), and that endpoint calls the third-party API with a key from a server-only env var. Add a login check and a rate limit so it doesn't become a free proxy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;My [SERVICE] API key is exposed in my frontend (read from [VARIABLE] in [FILE]). Please: 1) create a server-side endpoint that reads the key from a server-only env var with no public prefix, 2) remove the key and the prefixed variable from all client code, 3) make the frontend call the new endpoint, require a logged-in user and add a per-user rate limit, 4) show me the diff and where to set the env var on my host.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Already leaked? In this order
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Rotate the key in the provider's dashboard.&lt;/li&gt;
&lt;li&gt;Set a spending limit or usage alert.&lt;/li&gt;
&lt;li&gt;Check the provider's usage logs.&lt;/li&gt;
&lt;li&gt;Deploy the server-side fix.&lt;/li&gt;
&lt;li&gt;If it was ever committed to Git, treat it as public even after deleting the file.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Free pre-launch checklist&lt;/strong&gt; (14 checks to run before you share your link): &lt;a href="https://milokits.com/checklist?ref=devto" rel="noopener noreferrer"&gt;https://milokits.com/checklist?ref=devto&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We make Milo's Launch Check, a passive outside-in check for AI-built apps that also looks for keys in your bundle. Launch week: Quick Check $19 instead of $29 until 1 November (code QUICK19): &lt;a href="https://milokits.com/?ref=devto#pricing" rel="noopener noreferrer"&gt;https://milokits.com/?ref=devto#pricing&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>How to test Supabase RLS with two accounts (10 minutes, no tools)</title>
      <dc:creator>Milo Kits</dc:creator>
      <pubDate>Sun, 25 Oct 2026 06:39:38 +0000</pubDate>
      <link>https://dev.to/milokits/how-to-test-supabase-rls-with-two-accounts-10-minutes-no-tools-c2l</link>
      <guid>https://dev.to/milokits/how-to-test-supabase-rls-with-two-accounts-10-minutes-no-tools-c2l</guid>
      <description>&lt;p&gt;To test Supabase Row Level Security (RLS), create two test users, add data as user A, then try to read and change it as user B and as a logged-out visitor. If B or a stranger gets A's rows, your policies are too loose. If A can't see their own rows, a policy is missing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Your own app, live or on staging with the same database rules.&lt;/li&gt;
&lt;li&gt;Two test accounts you create: A and B.&lt;/li&gt;
&lt;li&gt;Two browsers, or one normal and one private window.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Create data as user A
&lt;/h2&gt;

&lt;p&gt;Sign in as A and create one of everything your app stores: a project, a note, an upload. Open DevTools &amp;gt; Network, reload, and find the request to &lt;code&gt;/rest/v1/...&lt;/code&gt;. Note the table and the row id.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Try to read A's data as user B
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Change the ID in the URL.&lt;/strong&gt; Open A's page address with A's id. B should get an empty page or an error.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replay the request.&lt;/strong&gt; Right-click a similar &lt;code&gt;/rest/v1/&lt;/code&gt; request &amp;gt; Copy as fetch, paste it in the Console and change the filter to &lt;code&gt;id=eq.&amp;lt;A's id&amp;gt;&lt;/code&gt;. B should get &lt;code&gt;[]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ask for everything.&lt;/strong&gt; Replay without a user filter. B should only see B's rows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Try to change A's data as user B
&lt;/h2&gt;

&lt;p&gt;Replay an update or insert with A's &lt;code&gt;user_id&lt;/code&gt; in the body. It should fail or change 0 rows. If B can insert a row with A's &lt;code&gt;user_id&lt;/code&gt;, the insert policy is missing &lt;code&gt;with check (auth.uid() = user_id)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Repeat logged out
&lt;/h2&gt;

&lt;p&gt;Your public key is in the page, so a stranger can send the same request. Private tables should return &lt;code&gt;[]&lt;/code&gt; or a permission error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: The SQL editor way (optional)
&lt;/h2&gt;

&lt;p&gt;The SQL editor normally bypasses RLS, so a plain select proves nothing. Impersonate a user and roll back:&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;begin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;set&lt;/span&gt; &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="k"&gt;role&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;set&lt;/span&gt; &lt;span class="k"&gt;local&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;claims&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'{"sub": "USER_B_UUID", "role": "authenticated"}'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;select&lt;/span&gt; &lt;span class="o"&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="n"&gt;your_table&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="s1"&gt;'USER_A_UUID'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;-- expect 0 rows&lt;/span&gt;
&lt;span class="k"&gt;rollback&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6: What RLS doesn't cover by itself
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Views&lt;/strong&gt; run as their owner unless created with &lt;code&gt;security_invoker = true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;security definer functions&lt;/strong&gt; run with their owner's rights. Call them as B with A's id.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage&lt;/strong&gt; has its own policies. As B, open A's file URL. Private files should need a signed URL.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If a test fails
&lt;/h2&gt;

&lt;p&gt;Paste this into your AI coder:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I tested my Supabase app with two users. User B could [read / change] user A's rows in [TABLE / VIEW / FUNCTION / BUCKET]. Please: 1) show me the current policies, 2) rewrite them so each user can only select, insert, update and delete rows where user_id = auth.uid(), with a matching WITH CHECK, 3) set views to security_invoker = true and check auth.uid() inside any security definer function, 4) give me the SQL and the two-account test to confirm the fix. Don't run anything until I say so.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Only test apps you own, with test accounts you created.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Free pre-launch checklist&lt;/strong&gt; (14 checks to run before you share your link): &lt;a href="https://milokits.com/checklist?ref=devto" rel="noopener noreferrer"&gt;https://milokits.com/checklist?ref=devto&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We make Milo's Launch Check, a passive outside-in check for AI-built apps. It's launch week, so the Quick Check is $19 instead of $29 until 1 November (code QUICK19): &lt;a href="https://milokits.com/?ref=devto#pricing" rel="noopener noreferrer"&gt;https://milokits.com/?ref=devto#pricing&lt;/a&gt;&lt;/p&gt;

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