Build a personal website from 0
Will AI Leak Your API Keys to GitHub? 2026 Pre-Launch Check
AI-built sites usually leak keys through GitHub commits or browser JavaScript. Which values are secret, a pre-launch checklist, and what to do after a leak.
Kelvin Wang · · 16 min read
Key points
- The Supabase publishable key, the Stripe publishable key and the Firebase web config are meant to be in the browser. What protects you is RLS or Security Rules, not hiding them.
- Before launch, check three places: git history (including files you deleted), the front-end files your build produces, and how your host stores environment variables.
- If a key leaks, revoke and replace it at the provider first, then deal with git history. Deleting the commit does nothing about copies already taken.
- Don't paste keys into a chat. Write the rules into your project instruction file, mark .env as off-limits to your AI tool, and keep what you can outside the project folder.
The moment your site talks to a database, an AI service or a payment provider, the code needs keys. When you tell an AI tool to “hook this up”, it puts the key somewhere, and you may not know where: in .env, pasted straight into a component, or behind a NEXT_PUBLIC_ prefix that ships it to every visitor’s browser. Whether you use Claude Code, Cursor, Codex, v0 or Lovable, the places to check are the same.
My site is Astro on Cloudflare Workers with a Supabase database, and most of its code was written by Claude Code. Several checks below (steps 2, 3 and 6) were run on this site’s repo and live pages; the results are in the matching sections.
Which values are secret, and which are public by design?
Sort your values into two groups first. Get it wrong and you either ship a secret to the browser, or spend an afternoon worrying about a key that was always meant to be public.
| Value | OK in front-end code or a public repo? | Why |
|---|---|---|
| AI service API keys (OpenAI, Anthropic, Gemini and so on) | No | Others spend your quota; you pay |
Database connection strings (postgres://user:password@…) | No | It is the database login |
| Supabase secret key (legacy equivalent: service_role) | No | Bypasses every RLS policy [4] |
Stripe secret (sk_) and restricted (rk_) keys | No | Only publishable keys are safe to expose [5] |
| OAuth client secrets, webhook signing secrets | No | Let someone act as your app or forge notifications |
| Deploy hook URLs, cloud platform tokens | No | Whoever has it can trigger deploys or act on your account |
| Supabase publishable key (legacy equivalent: anon) | Yes | Public by design; RLS decides what it can reach [4] |
Stripe publishable key (pk_) | Yes | Cannot charge or read account data [5] |
| The apiKey in a Firebase web config | Yes | Only identifies the project; Security Rules protect the data [6] |
“Public” comes with a condition. Supabase’s docs say anyone can read a publishable key from code you ship, so treat it as public; what it can reach is decided entirely by RLS (Row Level Security, the per-table rules that decide who can read and write)4. Firebase says the same: its API key identifies the project, Security Rules protect the data, and you shouldn’t rely on restricting or hiding the key6. Firebase adds one trap: don’t enable the Gemini API on that key, because a Gemini key has to stay secret6.
A public key plus missing permissions means a database open to everyone. In 2025 a researcher scanned 1,645 projects built with Lovable and found 170 of them, 303 endpoints in all, with inadequate RLS, so unauthenticated visitors could read or write tables such as users and transactions2. The researcher first suspected a leaked key; it turned out the key was public by design and RLS was the problem, and the exposed endpoints included a function called get_gemini_api_key3. It was filed as CVE-2025-48757, which Lovable disputes on the grounds that each customer is responsible for protecting their own app’s data2. However the blame is split, the takeaway for you is the same: a publishable key in the browser is fine, and every table needs RLS.
On this site, the JavaScript the login page downloads contains a key starting with sb_publishable_, as expected, and no sb_secret_. Going the other way, its .env.example lists a deploy hook URL. It looks like ordinary config, but anyone holding it can trigger a redeploy of the site, so production keeps it as a Cloudflare secret and the local value lives only in a .env that never enters git.
How do keys usually leak?
GitGuardian counts leaked secrets on public GitHub every year. Their report published in March 2026, covering 2025, has these numbers1:
- 28.65 million. New hardcoded secrets added to public GitHub commits in 2025, up 34%, the largest single-year jump they have recorded.
- 1,275,105 AI service secrets, up 81% year over year.
- 24,008 in MCP configuration files. MCP is the setup that connects AI tools to outside services. The report notes that many MCP setup guides tell you to put API keys straight into config files or command-line arguments.
- Over 64% still valid. Of the secrets confirmed valid in 2022, more than 64% still worked when retested in January 2026.
The actual routes are roughly these:
.envgets committed. No.gitignoreentry, or the wrong one (ignoring.envbut not.env.localor.env.production).- The key is hardcoded. The AI pastes it into a component or config file to “get it working first”, and nobody moves it back into an environment variable.
- It gets a public prefix. Variables starting with
NEXT_PUBLIC_,VITE_orPUBLIC_are written into the browser’s JavaScript at build time161718. Give a secret that prefix and the feature works, and the key goes public with it. - Build output gets committed or published. Folders such as
dist/,.next/orout/end up in the repo with the values already substituted in. - The AI tool writes the value somewhere else. A test file, a debugging
console.log, an example config, a README, an MCP config file. - Screenshots and posts. You post an error screenshot in a forum, issue or chat, and
.envor a dashboard key is in the frame. - The repo is public. You synced or exported a project from an AI site builder to GitHub without checking its visibility, or made a private repo public without remembering what’s in its history.
A private repo isn’t safe by default either. The same report says internal repositories are roughly six times more likely to contain hardcoded secrets than public ones1: people get careless when they think nobody is looking. A private repo can be made public one day, gain collaborators, or be opened to third-party tools.
A pre-launch secrets checklist
You can run each step yourself, or hand the whole list to your AI tool and have it report on each item (without printing any key values).
-
Make sure
.gitignoreexcludes every.envfile. My site added these two lines on the day the repo was created. They exclude every file starting with.envand keep only an.env.examplewith no real values:.env* !.env.examplegit check-ignore -v .env.localconfirms a file really is ignored and shows which rule matched. If you develop with Cloudflare’s wrangler, ignore the local.dev.varstoo12. -
Check whether
.envwas ever committed. Even if it’s ignored now, an old committed version stays in history:git log --all --name-only --format= -- ':(glob)**/.env*' | sort -uThis lists every .env-style file that ever appeared in history; if all you see is
.env.example, nothing leaked this way. Run on this site’s repo, it prints only.env.example. -
Search all of history for key prefixes.
git log -Sfinds commits that added or removed a piece of text20, including in files that no longer exist:git log --all -p -S 'sk_live_'Swap
sk_live_for the prefixes of the services you use, for example Stripe’ssk_live_andrk_live_, Supabase’ssb_secret_, orservice_role,postgresql://andpostgres://(connection strings come in both spellings). Searching this site’s repo forsb_secret_turns up only article sentences explaining what a secret key starts with, no real keys. Read what you find; much of it will be documentation or examples. -
Run a scanner. A manual search only finds the prefixes you think of; scanners ship with patterns for hundreds of key formats. Two common open-source ones: gitleaks (
gitleaks git -v .scans the whole git history,gitleaks dir -v .scans the current files)10, and TruffleHog (trufflehog git file://. --results=verifiedlists only keys it has tested and confirmed still work)11. The gitleaks README says it is feature complete and future releases will be security patches only10. Both can run as a pre-commit hook, so every commit gets scanned. -
Confirm GitHub secret scanning and push protection. Secret scanning runs automatically and free on public repositories and covers the full history of every branch; private repositories need paid GitHub Secret Protection (on an organization’s Team or Enterprise plan). When it finds a partner provider’s key, GitHub notifies that provider, which may revoke it7. Push protection blocks a push that contains a key. User-level push protection is on by default but only covers pushes to public repositories; repository-level push protection is off until you enable it. It only recognises certain key formats, and anyone with write access can choose to bypass it8, so treat it as the last line, not the only one.
-
Check what the browser receives. Run a production build locally and search the output folder:
npm run build grep -rE 'sk_live_|sb_secret_|service_role|postgres(ql)?://' dist/The folder depends on the framework:
dist/for Astro and Vite,.next/orout/for Next.js. After launch, open the live site, use the browser developer tools’ search across all sources (Cmd+Option+F on macOS, Ctrl+Shift+F elsewhere) for the same strings, and check the Network tab for request headers carrying keys they shouldn’t. This site’s login page was checked this way: only the publishable key turns up. -
Review every variable with a public prefix. List all
NEXT_PUBLIC_,VITE_andPUBLIC_variables in the project and ask of each one: is it fine for every visitor to see this? If not, the feature needs to call the service from the server instead. The prefix rules and the build-time substitution are covered with a full table in the deploy-failures post. -
Turn on RLS for every Supabase table. Supabase’s docs say a table in an exposed schema without RLS can be read and written by any role with access19. The dashboard’s Advisors include a Security Advisor, and one of its checks (
rls_disabled_in_public) lists tables in the public schema with RLS off21. -
Store secrets as secrets on your host. Vercel splits environment variables into Config and Secret; a Secret is write-only once saved13. On Cloudflare Workers,
npx wrangler secret put <NAME>stores one, and the value is hidden in both the dashboard and wrangler afterwards12. Don’t put secrets in files that go into git, such aswrangler.jsoncorvercel.json. -
Check the repository’s visibility. Look at the repo settings on GitHub and confirm Public or Private, especially for repos an AI site builder created for you.
A key has leaked. What do I do first?
Order matters: make the key useless first, then deal with git history. GitHub’s own guide makes revoking or rotating the secret the first step; once the key no longer works, rewriting history may not be needed at all9.
- Revoke the old key at the provider and create a new one. Stripe calls it rotating: the old key is revoked and a replacement issued. You can let the old key keep working for a few days while you switch over; for a leak, set the expiration to Now so it dies immediately5. Supabase’s docs say to rotate a leaked key as soon as you fix the cause: don’t put the new key back where the old one leaked from, such as front-end code or a file in the repo, or it leaks again. They also recommend a separate key for each backend component, so a leak means replacing just one4.
- Put the new key into your host and redeploy. Most hosts only apply a changed variable to a new deployment.
- Check usage, billing and request logs. Stripe shows request logs per key5; AI services have usage pages. Look for anything you don’t recognise during the exposure window, and contact the provider if you find it.
- Make sure the hole is closed. Run the checklist above across the whole project and look for other keys stored the same way.
- Only then decide whether to clean git history.
Why isn’t deleting the commit enough? If you remove the line locally and push again, the old commit is still in history for anyone who scrolls back. Even if you rewrite history and force-push, GitHub’s docs list places the data survives9:
- Forks. If someone forked the repo, the fork still has it.
- Other people’s clones. You can’t clean those for them.
- Cached views and pull requests on GitHub. Old commits stay reachable by their hash. Removing them fully means contacting GitHub Support, which only helps when rotating the credential can’t mitigate the risk.
Rewriting history has costs of its own: every later commit hash changes, signatures are stripped, and a collaborator’s stale clone can push the key straight back9. GitHub recommends git-filter-repo (2.47 or later, with --sensitive-data-removal) for the job9. For most personal sites, once the key is revoked, a dead string left in history is a small risk; whether to clean it depends on what else that history contains, such as real user data.
The post on what breaks after launch has a shorter version of this order, plus how to limit damage when a hosting platform itself is breached. For a real platform-side leak, see the Zeabur breakdown:
Go deeper What Breaks After You Launch an AI-Built Site: Failed Deploys, Leaked Keys, Database Permissions Where keys live, which ones can be public, and limiting the damage when a platform is breached. Go deeper Zeabur Breached Twice in Two Months, Then Shut Down (Part 1): From One NextChat Bug to an AWS Root Key How an attacker went from one user's deployed app to every project's environment variables on the platform.How do I stop AI tools from writing keys into my code?
AI tools can read the files in your project, see whatever you paste to them, and write into code as they see fit. What you can do is keep keys out of their reach, then back that up with rules and checks.
-
Don’t paste keys into the chat. When you ask for an integration, give the variable name (“use
STRIPE_SECRET_KEY, the value is in.env”) and fill in the value yourself. Whatever you paste can turn up in the code, tests or docs it writes. -
Write the rules into your project instruction file. Claude Code’s
CLAUDE.md, Codex’sAGENTS.mdand Cursor rules set to always apply are read at the start of every session. My site’sCLAUDE.mdrequires RLS on every table; another instruction file in the repo, maintained and synced by the SEO monitoring project, says the SEO credential must never appear in the repo, instruction files, PRs, conversations or logs. A few lines along these lines will do:- Secrets live only in .env (never committed) and the host's secret store. Never in code, tests or config files. - Never add NEXT_PUBLIC_ / VITE_ / PUBLIC_ to a secret; if the front end needs it, call it from the server. - Never print or log the value of any environment variable. - Run gitleaks (or whichever scanner we use) before committing; if it finds anything, stop and tell me. -
Make
.envunreadable to your AI tool. In Claude Code, addRead(./.env)andRead(./.env.*)underpermissions.denyin settings14; in Cursor, use a.cursorignoreat the project root15. Neither is a guarantee: Cursor’s docs say the Agent can still reach ignored files through the terminal or MCP tools15. -
Keep what you can outside the project folder. The credential my site uses to read SEO data lives in a config folder under my home directory on this machine, not in the repo. The launcher script checks that only my user can read the file (permissions 0600), refuses to run otherwise, and never prints the value. An AI tool working inside the repo won’t read, edit or commit it by accident.
-
Don’t hardcode keys in MCP configs. Use environment variables or the tool’s own credential handling. More than twenty thousand of the GitGuardian findings above came from MCP config files1.
-
Look at the diff before you commit.
git diff --stagedshows what’s about to go out, or let a pre-commit hook scan it. This is the step that gets skipped when an AI changes many files at once. -
One key per project, with a spending limit. A leak then means replacing one key, and the damage has a ceiling.
What does my own site do?
| Practice | How |
|---|---|
.env stays out of git | Every .env* file ignored since the repo's first day (2026-06-10), with only a value-free example committed; apart from that example, no .env-style file appears anywhere in history |
| Production secrets | Stored in Cloudflare with wrangler secret put, never in wrangler.jsonc |
| Only public values in the front end | The browser gets PUBLIC_ variables such as the Supabase URL and publishable key |
| Database permissions | CLAUDE.md requires RLS on every new table and spells out the condition to use |
| Social account tokens | Encrypted with AES-GCM before they're stored in the database; the encryption key is a Cloudflare secret |
| Test login state | The session file the end-to-end tests create is listed in .gitignore |
| SEO credential | Outside the repo, permissions 0600, never printed by the script |
None of this needs security expertise. Each line is a one-off setting or a rule in the instruction file, and the AI tool follows it every time it opens the project.
FAQ
Someone can see my Supabase anon key. Do I need to replace it?
No. The anon key (now the publishable key) is in every visitor’s browser by design4. What to check is whether every table has RLS on and its policies are right. The one to worry about is the secret key (formerly service_role), which bypasses RLS.
My repo is private. Is it fine to keep keys in it?
Lower risk, not no risk. A private repo can be made public, gain collaborators, or be opened to third-party tools and AI site builders, and anything committed stays in history. GitGuardian found internal repos roughly six times more likely than public ones to contain hardcoded secrets1. Keep secrets in .env and your host’s secret store, private repo or not.
I committed .env once and deleted it later. Do I still need to do anything?
Yes. The deleted file is still in git history. If the repo was ever public or shared, treat its secrets as leaked: rotate first, then decide on cleaning history. For a private repo only you have used, at least check whether any of those keys had more access than they needed, and replace those.
Can I delete the GitHub repo and recreate it instead of rotating?
No. Other people’s clones, forks and copies already picked up by scanners don’t disappear when you delete the repo9. The only thing that makes a leaked key useless is revoking it at the provider.
Sources
- 1. The State of Secrets Sprawl 2026
- 2. CVE-2025-48757
- 3. Statement on CVE-2025-48757
- 4. Understanding API keys
- 5. API keys
- 6. Learn about using and managing API keys for Firebase
- 7. About secret scanning
- 8. About push protection
- 9. Removing sensitive data from a repository
- 10. gitleaks README
- 11. TruffleHog README
- 12. Secrets
- 13. Config and Secret environment variables
- 14. Settings files and precedence
- 15. Ignore files
- 16. How to use environment variables in Next.js
- 17. Env Variables and Modes
- 18. Using environment variables
- 19. Row Level Security
- 20. git-log
- 21. Advisors
Kelvin Wang
Electrical engineer building tools with AI agents, sharing hands-on notes on engineering and investing.
More about me