Home / Answers / AI in marketing

Is it safe to put a Supabase anon key in a public web page?

Short answer

Yes, if Row Level Security is on and your policies only allow what the page needs. The anon key is designed to be public. In the form I teach, the leads table has RLS enabled and one policy: the anon role can insert rows and nothing else. Visitors can submit the form but cannot read, edit or delete anyone's data. The service_role key must never go in a page.

Why the key being visible is fine

Every visitor can open your page source and see the anon key. That is expected. As I told the room in my Claude 101 masterclass, the anon key being visible in the page source is normal and safe: security comes from Row Level Security, not from hiding the key.

Row Level Security is a database setting. When it is on, every request is denied unless a policy allows it. So the question is never whether the key is hidden. It is what the policies let that key do.

The setup I teach

  • A table called leads with only the fields the form needs, such as name, email, message, intent and source
  • Row Level Security turned on for that table
  • One policy that lets the anon role insert rows
  • No select, update or delete policy for anon

With that setup, anyone can add a row by submitting the form, and nobody without your private access can read the list.

The key that must stay private

Supabase also gives you a service_role key. It skips every policy. If it ever lands in a web page, anyone can read, change or delete your whole database. Keep it in server side environment variables only, and never paste it into a prompt that writes front end code.

What to check before you go live

  • Open the table settings and confirm RLS is enabled
  • Try to read the table using the anon key and confirm it returns nothing
  • Submit a test lead and see it arrive in the table editor

If spam arrives

A public form will get some. Add a hidden honeypot field, Cloudflare Turnstile or hCaptcha, a check constraint on the email field or a rate limit. None of these require hiding the key.

Ask me directly

Working on this right now?

Tell me what you are trying to grow or what your event needs. I read every message myself and reply within 48 hours.

Or see how I work with teams: consulting, advising and talks and workshops.

Please add your name
Please enter a valid email
Add a short note so I can reply with context
Message received

Thank you, it is in my inbox.