top of page
Security, Governance & AI Operations

API Keys Exposed on GitHub? Rotate and Secure Them

Got a leaked key alert? We find every exposed secret, rotate it without downtime and stop new leaks.

API keys are exposed on GitHub when credentials such as cloud keys, payment keys or database passwords are committed to a repository, where bots can find them within minutes and use them before anyone notices.

Reviewed by: Codersarts Security Engineering Team · Last updated: November 2026



What it means when API keys are exposed on GitHub


An exposed API key is a credential, such as an AWS access key, Stripe secret key, OpenAI key or database password, that has been committed to a repository. Automated bots scan GitHub constantly, and public leaks are often used within minutes for crypto mining, spam or data theft.


Deleting the file doesn't fix it. The key stays in git history, and it may already have been copied. The only real fix is to rotate the key, then clean up and prevent the next leak.



Symptoms: you're in the right place if


  • GitHub, AWS, Stripe, OpenAI or another provider emailed you about an exposed key

  • A .env or config file with passwords was committed at some point

  • Secret keys are bundled in frontend or mobile app code

  • Cloud, AI or SMS charges jumped unexpectedly

  • Former developers or agencies still know production credentials


Treat any key that was ever committed as compromised, even if the repository is private. Private repositories get cloned, forked and shared.


Business function


Business functions affected: Engineering and Finance.


Typical owner: CTO or lead engineer.


Common stage: Any stage, especially fast-moving teams, apps built by freelancers or AI tools, and teams that recently made a repository public.



Is this the right help for you?


A good fit if:


  • A provider warned you about a leaked key

  • You suspect secrets are in your git history

  • You want secrets stored properly across environments

  • A developer or agency has left


Not the right fit if:


  • Attackers already used the key to break in further: see app got hacked

  • You only need to change one password you control: rotate it now yourself



First steps if a key leaked


  1. Rotate or revoke the exposed key immediately, before cleaning anything

  2. Check the provider's logs and billing for activity you don't recognize

  3. Search the repository and its history for other secrets

  4. Add the file to .gitignore and turn on push protection



Business impact: what it costs to leave it unfixed


  • Surprise bills: leaked cloud keys are used to run expensive resources.

  • Data access: database and storage keys give attackers your data.

  • Account abuse: payment, email or SMS keys get used for fraud or spam.

  • Outages: rushed rotations break production when nobody knows where keys are used.



Root causes: how keys end up on GitHub


Committed .env files

Environment files added before .gitignore was set up.


Keys in frontend code

Secret keys bundled into JavaScript or mobile apps.


Copied examples

Real keys pasted into sample code, tests or docs.


No prevention

No pre-commit hooks or push protection to block secrets.



Common leaked key scenarios


Scenario

Usual cause

First fix

AWS key leaked, bill spikes

Key in a public repository

Revoke the key, delete rogue resources, contact AWS

Stripe secret key in frontend

Wrong key type used in client code

Rotate and move to the server

OpenAI key abused

Key committed or exposed in a browser app

Rotate, set usage limits, proxy through your server

Supabase service-role key exposed

Used in client code

Rotate and keep server-side only



Secrets readiness checklist


Every “no” is a likely gap.


Storage


  • Are production secrets stored in a secrets manager or protected environment settings?

  • Are secrets different for development and production?


Prevention


  • Is push protection or a pre-commit secret scanner turned on?

  • Is .env in .gitignore in every repository?


Rotation


  • Do you know where every key is used?

  • Do you rotate keys when someone leaves?



Potential solution family


Solution type: Fix. We find, rotate and secure every exposed secret.


Solution family: Secrets management: leak scanning, safe rotation, secure storage and prevention.



How we fix it: cleaning up leaked secrets


1. Scan

Search code, full git history, CI logs, images and builds for secrets.


2. Triage

Confirm which secrets are live and what each one unlocks.


3. Rotate

Replace and revoke keys in a safe order so production keeps working.


4. Secure

Move secrets into protected settings or a secrets manager.


5. Clean history

Remove secrets from git history where it's still needed.


6. Prevent

Turn on push protection and pre-commit scanning.



Typical timeline


Phase

Typical duration

Leak scan of one repository

24 hours

Rotation and history cleanup

1 day

Secrets manager across environments

3 days to 2 weeks


Rotation comes first and usually takes hours. Prevention and proper storage follow.



Mistakes to avoid


  • Deleting the key from the latest commit without rotating it

  • Making the repository private and assuming the leak is over

  • Rotating keys without knowing where they're used, causing outages

  • Keeping secret keys in frontend code



Required skills




Relevant technologies


  • Code hosting: GitHub, GitLab and Bitbucket

  • Cloud: AWS, Azure and Google Cloud

  • Secret stores: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault and Google Secret Manager

  • Scanners: Gitleaks, TruffleHog and GitHub secret scanning



Diagnosis offer: start with a fixed-price secrets cleanup


Find out every secret that's exposed, and rotate them safely.


What you get:


  • A list of every exposed secret and where it was found

  • Safe rotation of live secrets

  • Git history cleanup where needed

  • Push protection and pre-commit scanning




Proof


Example engagement: AWS key alert turns up 12 secrets

An illustrative example based on the pattern we see most often. Client details are kept confidential.


The situation: A startup received a GitHub alert about an AWS key in an old commit.


What we found:


  • The AWS key had been used to start servers in another region

  • 11 more secrets were in git history, including a live Stripe key

  • A database password was shared by all environments


What we changed:


  • Rotated all 12 secrets with no downtime

  • Removed rogue AWS resources

  • Moved secrets into AWS Secrets Manager

  • Turned on push protection


The result: No live secrets remained in the code, and new leaks are now blocked before they're pushed.


Why buyers trust Codersarts

  • Delivering software, cloud and security engineering for clients worldwide since 2018

  • A managed in-house engineering team, not a freelancer marketplace

  • Security engineers who are also developers, so we fix what we find

  • Testing only with written authorization and agreed scope

  • Confidential by default: we sign NDAs before accessing your code or accounts



Frequently asked questions


What should I do if my API key is exposed on GitHub?

Rotate or revoke it immediately, check the provider's logs for misuse, then clean up git history and turn on push protection.

No. The key stays in git history and may already be copied. It must be rotated.

Safer, but not safe. Private repositories are cloned, shared with contractors and sometimes made public later.

Often within minutes on public repositories, because bots scan GitHub continuously.

Yes. We add the new key, switch the app over, confirm it works, then revoke the old one.



Related problems


bottom of page