PLATFORM SECURITY

    Exposed API Keys In AI-Built Apps: How To Check And What To Do If One Leaks

    Found an exposed API key in your AI-built app? Learn how to check for leaks, replace the key in the right order and keep API keys secure.

    LetMeCheck team · 4 min read
    Exposed API Key? How To Check And What To Do If One Leaks
    IN THIS POST

    An API key is a password your app uses to talk to other services. Here is how they leak, how to spot one and what to do, in the right order, if yours does.

    An API key is a password your app uses to talk to another service: your database, your email provider, your AI model, your payment processor. Whoever holds the key can act as your app. If it leaks, they can read your data, send mail in your name or run up your bill, often without you noticing until the invoice arrives.

    AI coding tools make this mistake easy. To get a feature working quickly, they will happily paste a key straight into front-end code that every visitor can read. Here is how to check for an exposed API key, what to do in the first hour if you find one and how to keep your keys safe from here on.

    How API Keys End Up Exposed

    Most leaks come from a few repeat patterns.

    • Keys written into front-end code. Anything the browser downloads can be read. If a secret key is in that code, it is public. Replit's security guide says API credentials should always stay server-side.
    • Keys committed to a repository. A key in a file pushed to GitHub is exposed, even if the repository is private today and public tomorrow.
    • A reachable .env file. The file meant to hold secrets sits at a web address, and anyone can download it.
    • Keys in screenshots, chat logs and prompts. A key pasted into a public forum post or shared project is as exposed as one in code.
    • The wrong key in the right place. Some keys are meant to be public, such as a Supabase public key, but the service role key is not. Mixing them up is a frequent and serious mistake.

    The pattern differs by tool. We see API keys in front-end code most often on Bolt projects, secrets added to code instead of Replit Secrets on Replit, and open database tables on Lovable. Our glossary entry on API key exposure has the short definition.

    Check Your App For Exposed Keys

    1. Scan your live site from the outside. A quick check looks at what a stranger can see, such as keys in browser files, without a sign-up or any changes. The guide to running your first scan walks through it.
    2. Search your own code. Search the project for "key", "secret", "token", "password" and the names of services you use. Look at where each match sits. A match in a server file is normal. A match in a file the browser loads is not.
    3. Open the browser's developer tools. On your live site, look at the Sources and Network tabs and search for the same words. This shows what visitors actually receive.
    4. Visit /.env on your site. If anything other than a not-found page appears, treat every value inside as compromised.
    5. Check your repository, including history. Deleted keys can still be found in old commits. GitHub's secret scanning, or a full check that reads your repository with read-only GitHub access, will flag them.
    6. Look at each provider's usage page. Odd traffic, unfamiliar locations or a sudden jump in usage are signs someone else is using your key.

    Respond Fast: What To Do If A Key Leaks

    The order matters. People often start by cleaning up the code, but a key that has been seen is already out. GitHub's guidance puts it plainly: revoke or rotate the secret first. Once it can no longer be used, the leak may not be a problem at all, and rewriting history may not be necessary.

    1. Replace the key at the provider. Create a new one and delete the old one. Do not wait for a quiet moment. Resend's documentation advises deleting a leaked key straight away rather than waiting for a scheduled rotation. Here is more on key rotation.
    2. Put the new key where it belongs. Store it as a server-side environment variable or in a secrets manager, never in front-end code.
    3. Check for misuse. Review the provider's logs and billing from the time the key was exposed. If you see activity you do not recognise, tell the provider and, if user data was reachable, think about whether users need to be told.
    4. Clean the code and history if needed. Remove the key from the files. GitHub notes that rewriting history has trade-offs: old clones and forks may still hold the secret, commit hashes change and collaborators have to re-clone. That is why replacing the key comes first.
    5. Cap the damage next time. Set spending limits and restrict what each key can do.

    Deleting a post, a commit or a file does not make an exposed key safe. Treat any key that has been public, even for a few minutes, as compromised. Secrets were also the target of the worm behind our write-up of the September 2025 npm attacks, which is a reminder that stolen keys get used quickly.

    Keep Your API Keys Safe Going Forward

    Habit
    Why It Helps
    Keep secrets server-side only
    Browser code is readable by everyone
    Add .env to .gitignore before the first commit
    Stops keys reaching the repository
    Use a separate key per project and environment
    Limits what one leak can reach
    Restrict each key's permissions and domains
    A stolen key does less damage
    Turn on push protection or secret scanning
    Catches mistakes before they go public
    Rotate keys on a schedule and after any scare
    Shrinks the window of exposure
    Re-scan after big AI-assisted changes
    New prompts can reintroduce old problems

    A leaked key is stressful, but it is one of the most fixable problems in an AI-built app. Replace it, move it, watch the logs and carry on. If you are not sure you have cleaned up properly, ask a developer to look. It is a short job for someone who has done it before.

    References

    Does your app have any of these problems?

    Paste your website for a free quick check. About a minute, and nothing on your site is changed.