Abbi Labs

Guides

Pushed your .env file to GitHub? What to do now (and why deleting it isn't enough)

By Abbi Labs · Last updated 3 December 2026

Scan your app free and see what your live site exposes.

Abbi Labs checks whether your site serves /.env or /.git, secret keys in your JavaScript, Supabase tables readable with your public key, source maps, security headers, CORS, cookie flags and TLS. Read-only. No sign-up for the quick check.

No app handy?

Example result · our deliberately broken demo app

6 issues found: 3 critical, 1 high, 1 medium, 1 low

  • Critical: Stripe live secret key in public JavaScript
  • Critical: /.env file readable by anyone
  • High: Git repository exposed (/.git/HEAD)

The demo's problems are planted on purpose. Paste your own URL above to see yours.

No sign-up. Read-only public-resource and protocol metadata checks. No model prompts or tool execution. Scan only sites you own or are allowed to test.

Run on every deploy or use from Cursor / Claude Code via MCP →

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.

It usually goes like this. The AI builder connected your project to GitHub, or you ran git add . before adding a .gitignore, and the .env with your real keys went up with everything else. You noticed, deleted the file, maybe made the repo private. It feels fixed. It isn't, and the order you fix it in matters.

Sources for the facts below: Lovable's docs on Secrets and .env, GitHub's guide to removing sensitive data from a repository and its push protection docs, and git's documentation for gitignore and git rm.

Why deleting it doesn't help

So the only thing that makes a leaked key harmless is making the key itself useless. That's rotation.

Do this now, in this order

1. Rotate every secret that was in the file. Open the leaked .env and go down it line by line. For each secret, create a new one at the provider, put the new value where your app reads it (your host's environment variables, Supabase secrets), redeploy, then revoke the old one. Typical lines in an AI-built app:

Public values like the Supabase anon or publishable key and the Stripe publishable key are designed to be seen, so they don't need rotating for this. What protects you there is RLS, not secrecy (is the Supabase anon key safe?).

2. Check whether the old keys were used. While you rotate, look at each provider's usage, logs or billing for activity you don't recognise: model API spend, Stripe events, new Supabase users or rows you didn't create. If something looks wrong, you're dealing with an incident, not a tidy-up.

3. Stop tracking the file (not on Lovable, see below).

# keeps your local .env, removes it from git from now on
git rm --cached .env
echo ".env" >> .gitignore
echo ".env.*" >> .gitignore
echo "!.env.example" >> .gitignore
git add .gitignore
git commit -m "Stop tracking .env"
git push

Commit a .env.example with the variable names and placeholder values instead, so the next person (or the next AI session) knows what to set.

On Lovable, don't gitignore .env. Lovable's docs say it needs .env committed so the build-time VITE_ values are there for previews and published builds, and that gitignoring it breaks the preview (people on Reddit report a white screen). There the fix is different: keep only public VITE_ values in .env (the Supabase URL and publishable key), move every secret into Lovable's Secrets, which its docs describe as backend-only values for Edge Functions, and rotate anything secret that was ever in the file.

4. Decide about history. GitHub's own advice: once a secret is revoked or rotated and can't be used, you generally don't need to rewrite history. Rewriting means git-filter-repo, new commit hashes, a force push, broken diffs on old pull requests, and every clone needing to be redone, and it still doesn't reach forks. Do it only if the file held something you can't rotate, like customer data. If you do, follow GitHub's steps exactly; they use git-filter-repo --sensitive-data-removal --invert-paths --path .env.

Check yours in 3 minutes

  1. Is .env tracked right now? In your project folder:
    git ls-files | grep -i "\.env"
    Anything other than .env.example (with placeholders) is being pushed. On Lovable a tracked .env is expected, so open it instead and make sure it holds only VITE_ public values.
  2. Was it ever committed?
    git log --all --oneline -- .env .env.local .env.production
    Any output means it's in history. Then search history for key prefixes, for example git log --all -p -S "sk_live_", and repeat for service_role, sb_secret_, sk-proj-, sk-ant- and postgres://.
  3. Is the repo public, or was it ever? Check the repo's visibility in Settings. AI builders that sync to GitHub create the repo for you, so check what visibility it got.
  4. Is your live site serving it too? A different leak with the same file:
    curl -s -o /dev/null -w "%{http_code}\n" https://yourapp.com/.env
    A 200 with KEY=value lines in the body is bad. An HTML page with a 200 is usually your app's catch-all route and is fine. More in .env, .git and source maps.

Stop it happening again

Paste this into your AI builder

Our .env file with real keys was committed to GitHub.
1. List every variable in .env and mark which are secrets
   (server-only) and which are public by design.
2. Do not print any secret values.
3. Move every secret out of .env into server-side secrets
   (Lovable: Secrets; elsewhere: the host's environment settings).
   If this is NOT a Lovable project, also run git rm --cached on
   .env and any .env.local/.env.production, add .env and .env.*
   to .gitignore with an exception for .env.example, and create
   .env.example with placeholder values.
4. Confirm no secret is imported into browser code.
5. Give me a checklist of where to rotate each secret.
   Don't rewrite git history or force push.

What Abbi Labs checks

Honest scope: Abbi Labs scans your live site, not your GitHub repo, so it can't see your git history. Run the commands above for that. What it does check, in the free quick check with no sign-up: whether your site serves /.env, /.env.local, /.env.production or /.git/HEAD, and whether your home page JavaScript contains recognisable secret keys (Stripe live secret, OpenAI, Anthropic, AWS, GitHub, Slack, Resend and others, shown masked). That's the other way a .env leaks: through the deploy.

Scan your app free

FAQ

I deleted .env and pushed again. Am I safe?

No. Deleting the file removes it from the latest version only. Every earlier commit still contains it, and anyone can open those commits on GitHub if the repo is public. Treat every key that was in the file as known to someone else and rotate it.

Does adding .env to .gitignore remove it from GitHub?

No. Git's own docs say files already tracked aren't affected by .gitignore. You need git rm --cached .env to stop tracking it (your local copy stays), then commit. It still remains in older commits.

The repo is private now. Do I still need to rotate?

If it was ever public, yes. You can't know who cloned it or what scraped it while it was public, and making it private doesn't reach those copies. If it was always private, think about who had access, including collaborators and connected apps, and rotate anything you can't be sure about.

Do I need to rewrite git history?

Usually not, once every secret is rotated. GitHub's own guide says to revoke or rotate first, and that after that you generally don't need to rewrite history. Rewriting is for things you can't rotate, like personal data. It also changes commit hashes and needs a force push, and old commits can stay reachable on GitHub by their hash and in forks.

Which keys in my .env actually matter?

Anything secret: Supabase service_role or sb_secret_ keys, Stripe sk_live_ keys, OpenAI and Anthropic keys, database URLs with a password, SMTP and Resend keys, JWT signing secrets, webhook signing secrets. Values meant to be public, like the Supabase anon or publishable key or a Stripe publishable key, don't need rotating for this, although you should still check what the public key can read.

I use Lovable and it put .env in my repo. Is that a leak?

Not by itself. Lovable's docs say it keeps .env committed on purpose, so build-time VITE_ values like VITE_SUPABASE_URL and VITE_SUPABASE_PUBLISHABLE_KEY are there for previews and published builds, and those are public by design. Its docs also say not to add .env to .gitignore in a Lovable project, because that breaks the preview. The problem is a secret in that file: a service_role key, Stripe secret or AI provider key. Rotate it and move it to Lovable's Secrets, which are for backend values.

Will GitHub stop me pushing a secret?

Often. GitHub's push protection for users is on by default and blocks pushes of supported secret formats to public repositories. It only knows certain formats, it doesn't cover everything in a .env, and it can be bypassed, so don't rely on it alone.

Does Abbi Labs check my GitHub repo?

No. Abbi Labs scans your live site, not your repository. The free quick check (no sign-up) flags recognisable secret keys in your home page JavaScript and whether /.env, /.env.local, /.env.production or /.git/HEAD are served by your site. That catches the other way a .env leaks, through the deploy rather than the repo.

Related guides

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.