Sample alert How it works Coverage PENTEST METHODOLOGY DOCS PRICING FAQ MCP CONTACT LOG IN SCAN MY APP →

GitHub says you exposed a secret: what to do

FIX / GITHUB SECRET ALERT / 9 MIN READ

If GitHub tells you that you exposed a secret, revoke the key at the provider first. Then update your app with a new key. Only then close the alert. Deleting the file or the commit does not stop anyone from using the key. A bot can copy the key within minutes of the push.

This guide shows how to read the alert and how to rotate each common key. It also shows when to clean the Git history and how to close the alert.

What does the GitHub secret alert mean?

It means that GitHub found text in your repository that looks like a credential. The credential can be an API key, a token, or a password. This includes a .env file that you committed by mistake.

GitHub names this feature secret scanning. When it finds a leak, GitHub creates an alert in the repository. The alert has details about the credential. Public repositories get secret scanning at no cost.

GitHub also works with service providers. This is the partner program. When GitHub finds a partner secret, it notifies the provider. The provider can then revoke the key. Some providers do this by themselves. Do not wait for it. You must check the key yourself.

You can see the problem in three places:

  • An email from GitHub. The email names the secret type and the repository.
  • A banner or an alert in the repository. Open the Security tab, then Secret scanning.
  • A block during a push. This is push protection. GitHub rejects the push and shows a message that names the secret type, the commits, the file path, and the line.

Lovable, Bolt, and similar tools sync your project to GitHub. They commit files that you never open. A key that you pasted into a chat can end up in a committed file. That is why people who do not write code also get these alerts.

Warning: Do not click a link in an email before you check it. A false email can imitate GitHub. Open github.com in a new tab and sign in there. Look for the alert in the repository.

How do I read the alert?

Open the alert. Write down four facts before you do anything else.

  1. The secret type. The alert names the provider, for example Supabase, OpenAI, Stripe, or Resend.
  2. The place. Note the file, the line, and the commit. The commit shows when the key entered the history.
  3. The repository visibility. Check if the repository is public or private. A public repository means that everyone saw the key.
  4. The validity. Some alerts show if the key is still active. Treat an active key as the highest risk.

GitHub also tells you how to judge the risk. Its guide on how to remediate a leaked secret says to revoke at once when the secret is active, public, or in production. If the key is only for tests and the repository is private, you can plan the rotation. For a non-technical owner, the safe rule is simple: rotate every key.

Also check the history for more keys. One alert often is not the only one. Run a search in your local copy:

git log --all -p -S "sk_live_" --oneline | head -50
git log --all --name-only --pretty=format: | grep -E "(^|/)\.env" | sort -u

The first command finds commits that added the text sk_live_. Replace it with the start of your key. The second command lists every .env file that ever existed in the history.

Why must I rotate first?

Rotation is the only action that makes the leaked key useless. All other actions leave the key valid.

Think about what happens when you delete the commit. The key stays in many places:

  • In clones of the repository on other computers.
  • In forks of a public repository. Bots can also copy a public key at once. You cannot remove all these copies. A revoked key is different. The provider rejects it, so the copies do nothing.

So use this order:

  1. Revoke or rotate the key at the provider.
  2. Put the new key in your app.
  3. Check the logs for use of the old key.
  4. Clean the history if you want to.
  5. Close the alert.

Do not use the order that feels natural, which is to delete the file first. That order leaves the key active while you work.

Caution: If your app is in use, a revoke makes the app fail until you put the new key in place. For a key that someone already uses, accept a short outage. For a key that nobody uses, create the new key first, update the app, then revoke the old key. GitHub gives the same advice.

How do I revoke the key for each provider?

Each provider has its own page. These are the usual four. The names of the buttons can change, so read the labels in the dashboard.

Supabase

The key can be a service_role key, an sb_secret_ key, or a database password. The publishable key (sb_publishable_) and the legacy anon key are designed for the browser. They are not secret. RLS protects your data from them.

  1. Open the Supabase dashboard. Select Settings, then API Keys.
  2. Create a new secret key.
  3. Move your app to the new key.
  4. Delete the leaked secret key. For a legacy key, deactivate the legacy keys.
  5. For a legacy service_role key, revoke the legacy JWT secret too.

The full steps are in the service role key leak guide. Supabase also has an official page on how to rotate a leaked API key. If the leaked item is the database password, reset it in the database settings and update every connection string.

OpenAI

  1. Open the OpenAI platform. Go to the API keys page.
  2. Create a new key. Give it a name that shows its use.
  3. Put the new key in your server environment.
  4. Delete the leaked key on the same page.
  5. Open the usage page. Check for spend that you did not make.

Set a monthly spend limit for the project.

Stripe

  1. Open the Stripe dashboard. Go to Developers, then API keys.
  2. For a secret key (sk_live_...) or a restricted key (rk_live_...), use the roll action.
  3. Put the new key in your server environment.
  4. Make sure the old key no longer works.
  5. Check the payments, refunds, and customers for actions that you did not make.

A publishable key (pk_live_...) is not secret. It is made for the browser. A webhook signing secret (whsec_...) is secret. If it leaked, roll it in the webhook settings. A person with this value can send fake payment events. The Stripe webhook guide explains the risk.

Resend

  1. Open the Resend dashboard. Go to API Keys.
  2. Create a new key with the least rights that your app needs.
  3. Put the new key in your server environment.
  4. Delete the leaked key.
  5. Check the logs for emails that you did not send.

Another provider

Use the same pattern. Find the page for API keys. Create a new key. Update the app. Delete the old key. Check the usage log. If you do not know where the key comes from, the token leak checker can help you to identify the type of a token.

How do I put the new key in my app?

Never commit the new key. Use the secret store of your host. Do not use a file in the repository.

  1. Vercel, Netlify, Railway, Render. Add the key in the environment variable settings of the project. Redeploy. The Vercel guide shows how to rotate variables and how to check the preview environments.
  2. Lovable and Bolt. Use the secret store of the tool or of the backend. Do not paste the key in the chat. A key in a chat can end up in a file again.
  3. Local development. Put the key in a .env file. Add the file to .gitignore before you create it.
.env
.env.*
!.env.example

If a file is already tracked, the .gitignore rule does not apply. Remove the file from tracking and keep it on your disk:

git rm --cached .env
git commit -m "Stop tracking .env"

This does not remove the file from the old commits. That is why the rotation comes first.

AI coding tools can also read .env files. The Claude Code .env guide shows how to stop this.

How do I check if someone used the key?

Do this step after the rotation. Look at the provider logs for the time since the commit.

  1. Open the usage log or the audit log of the provider.
  2. Find the time of the commit that contained the key. Start the search at that time.
  3. Look for requests from IP addresses that are not yours.
  4. Look for spend that you did not expect. For a cloud or an AI key, check the bill.
  5. Look for new data, deleted data, and new users.
  6. Check other keys in the same file. A .env file often holds more than one key.

If you see use that is not yours, treat the case as a breach. Rotate every other key that the attacker could reach. If the key opened a database with personal data, ask a lawyer about your duty to tell the users.

Do I need to clean the Git history?

Usually not. After you revoke the key, the old text in the history is only a dead string. GitHub says that cleaning history is possible but often not necessary if you already revoked the credential. It also says that the process “can be a destructive and disruptive process,” because it can need a force push.

Clean the history in these cases only:

  • The repository is public, and you do not want a dead key to stay in view.
  • The secret is not a key. It is a personal item, such as a customer record, that you must remove.
  • A company rule or a law requires it.

If you decide to clean it, remember these facts:

  • Every collaborator must clone the repository again, or reset it.
  • Open pull requests can break.
  • Forks and caches keep the old data.
  • A tool such as git filter-repo rewrites the history. Make a backup first.
git clone --mirror https://github.com/OWNER/REPO.git
cd REPO.git
git filter-repo --path .env --invert-paths
git push --force --mirror

Warning: Do not run this command on your only copy. A mistake can destroy your history. Ask a developer for help if you are not sure.

What if push protection blocked my push?

The block is a good sign. The key did not reach GitHub. Remove the key from the code and push again. GitHub gives these steps for the latest commit:

  1. Remove the secret from the file.
  2. Run git commit --amend --all.
  3. Run git push.

If the secret is in an earlier commit, find the earliest commit that has it. Run git log and note the hashes from the error message. Then start an interactive rebase from just before that commit:

git rebase -i <COMMIT-ID>~1

Change pick to edit for that commit. Remove the secret. Run git add ., then git commit --amend, then git rebase --continue. Push again.

Check the GitHub documentation on push protection for more detail.

Caution: The block has a bypass option. You can allow the push with a reason, such as “it is used in tests.” Do not use it for a real key. A reason that is not true leaves the key in the history.

How do I close the alert?

Close the alert after the key is revoked. GitHub does not close it for you when the text leaves the repository.

  1. Open the repository on GitHub.
  2. Select the Security and quality tab. If you do not see it, open the … menu.
  3. Under “Vulnerability alerts,” select Secret scanning.
  4. Open the alert.
  5. Open the Close as menu. Select Revoked.
  6. Add a comment. Write the date of the rotation and the name of the new key. Do not write the key itself.
  7. Select Close alert.

The menu has other reasons too. Use them only when they are true. For example, use a false-positive reason when the text is not a real key. Do not use them to hide an active key.

How do I stop this problem in the future?

  1. Turn on push protection. GitHub says to enable it for the repository and for your personal account. A real key then never enters the history.
  2. Use environment variables. Keep keys out of the code. Read them from the environment on the server.
  3. Keep server keys on the server. A variable with a NEXT_PUBLIC_ or VITE_ prefix goes into the browser code. Never use these prefixes for a secret.
  4. Use keys with the fewest rights. A restricted key limits the damage.
  5. Do not paste keys in chats. This is the common path from a non-developer to a leaked key.
  6. Check your public repositories. Open each repository that your tools created. The Lovable GitHub repository guide shows how to make one private.
  7. Scan the live app. The key can leak from the running app, not only from the repository.

When should I get help?

Get help in these cases:

  • The provider log shows use of the key from an unknown address.
  • The key opened a database with personal data or payment data.
  • You find many keys in the history, and you do not know which ones are active.
  • The repository is public, the leak is old, and the key had wide rights.
  • You need to clean the history in a repository with many contributors.

After you finish, open the alert page again. It must be closed. Test the old key against the provider API. The provider must reject it.

Common questions

Is the GitHub alert email real?
Open GitHub in your browser, not the email link. Go to the Security tab of the repository. If the alert is there, it is real. Never enter a password on a page that the email opened.
Is my repository safe if it is private?
Safer, but not safe. People with access can read the key. A private repository can become public later. Rotate the key in both cases.
Must I delete the secret from the Git history?
Not first. Rotate the key first. A revoked key is no longer a secret. GitHub says that cleaning history is destructive and often not necessary after a revoke.
What does push protection do?
It rejects a push that contains a secret that GitHub knows. The message names the secret type, the commit, the file, and the line. Remove the secret and push again.
Which reason must I choose to close the alert?
Choose Revoked after you revoke the key at the provider. Use the other reasons only when they are true, for example for a false positive.

Check what the key opens

A VibeEval scan tests the live app and API whose keys may have leaked, and reports open data, exposed keys in the bundle, and missing access rules.

14-day free trial · Cancel anytime

SCAN YOUR APP →