Is it safe to put a Supabase anon key in a public web page?
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.