When I finished writing an offline security scanner for AI-built web apps, I ran it against my own private production repository first.
It flagged two tracked helper scripts containing a Supabase service_role key.
That is the point of automated checks. You can understand row-level security thoroughly and still leave a setup script or migration helper in Git after a late debugging session.
Why a service_role key is completely different from an anon key
In Supabase, you work with two JWT keys:
-
anonkey: meant to be public in your browser bundle. Every query made with it is restricted by your Row-Level Security (RLS) policies. -
service_rolekey: bypasses every RLS policy on every table. Whoever holds it can read, update and delete your entire database.
You can check which one you are looking at by decoding the middle segment of the JWT (base64url). The payload includes "role": "anon" or "role": "service_role".
Where this key leaks in AI-built apps
In projects built quickly with Lovable, Bolt, Cursor or Claude Code, the service_role key shows up in three predictable places:
- One-off seed or fix scripts committed during troubleshooting, where the key was pasted inline instead of read from an environment variable.
- Front-end environment variables prefixed with
VITE_orNEXT_PUBLIC_, which the bundler copies directly into the shipped JavaScript. - Server routes that fail to separate admin and user clients, accidentally exposing an admin query behind an unauthenticated endpoint.
A 60-second check you can run right now
Before you launch, search both your repository and your built dist/ or .next/ output:
# 1. Check tracked files for service_role references or hardcoded JWTs git grep -n -E "service_role|eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" # 2. Check your built client bundle for leaked prefixes grep -rn -E "service_role|sk-proj-|sk_live_" dist/ .next/static/ 2>/dev/null If you want a broader offline pass across RLS policies, client bundles, CORS, raw-HTML sinks and agent tool permissions, my open-source scanner and three reproducible labs are on GitHub:
- Scanner and three labs, each with a self-test: https://github.com/mikebillnova-create/ai-app-security-check
- Sample audit report (12 confirmed findings before the fix, 0 after re-test): https://github.com/mikebillnova-create/ai-app-security-check/tree/main/examples/sample-report
What to do if you find one
Deleting the line from the file is only half the job:
- Rotate the key immediately in Supabase → Project Settings → API. Any key that ever sat in Git history or a public JS bundle counts as exposed.
- Move the call to a server-only environment variable (no
VITE_orNEXT_PUBLIC_prefix). - Re-run the check on the fresh build so "fixed" is verified on the exact artifact you deploy.
Building with Lovable, Bolt, Supabase, Next.js or AI agents and want a second pair of eyes before launch?
I run fixed-fee 48h Light Audits (€199) with copy-paste SQL/PR fixes and a free re-test within 14 days — €0 if I find nothing confirmed.
Free 25-point checklist and free public exposure check: https://ai-app-security.pages.dev/?utm_source=devto&utm_medium=social&utm_campaign=gpt-plan-0312
AI security assessments (OWASP Top 10 for LLM Applications 2026), automation and local AI: https://havendigital.pages.dev/security-assessment?utm_source=devto&utm_medium=social&utm_campaign=gpt-plan-0312


