Skip to main content
ContentCritical PriorityPro

Exposed API Keys & Secrets

Updated November 2026·SecScanner Team

Credentials such as AWS access keys, Stripe live keys, GitHub tokens and private keys sometimes ship to the browser inside HTML or bundled JavaScript, where anyone can read them.

Results in 1–3 minutes · Free · No signup required

Why It Matters

A leaked key is an immediate compromise, not a theoretical one: automated scanners harvest public pages for key patterns within minutes of publication. Depending on the key, an attacker gets your cloud account, your payment data, or your source repositories — no exploit required.

How We Check

We match your served HTML and inline scripts against signatures for well-known credential formats — AWS `AKIA…` access key IDs, `sk_live_`/`pk_live_` Stripe keys, GitHub `ghp_`/`github_pat_` tokens, Google `AIza…` API keys, Slack `xox…` tokens, SendGrid keys and PEM private-key blocks.

Good vs Bad Values

Good and bad values for Exposed API Keys & Secrets
ValueVerdictWhy
NEXT_PUBLIC_MAPS_KEY referrer-restricted in the cloud consoleGoodA key designed for the browser, limited to your site and one API. If it leaks, the damage is bounded.
No secret-shaped strings in the first 500 KB of HTMLGoodThe check passes. It reads the page and its inline scripts, not external bundles.
AKIAIOSFODNN7EXAMPLE style AWS access key ID in a scriptBadAn AWS key ID begins with AKIA followed by 16 characters. Treat the paired secret as exposed too and rotate both.
sk_live_… (Stripe secret key)BadLets the holder create charges and refunds against your account. Roll it in the dashboard immediately.
ghp_…, github_pat_… or other GitHub tokenBadGrants whatever repository access the token has. Revoke it in the GitHub settings page for the account that issued it.
-----BEGIN PRIVATE KEY-----BadA private key in public HTML means whatever it signs or decrypts is compromised. Replace the key pair.
AIza… Google API keyWeakBrowser keys are meant to be visible, so this is reported as high rather than critical. It is only safe if it has HTTP-referrer and API restrictions.
pk_live_… Stripe publishable keyWeakPublishable keys are designed for the client and cannot move money alone. The check still lists it so you can confirm it is not a secret key with a similar name.
xoxb-…, SG.…, Authorization: Bearer <30+ chars> in inline codeBadSlack, SendGrid and hard-coded bearer tokens are credentials for server-side use. They must not reach the browser.

How to Fix

Revoke and rotate every exposed credential first — removing it from the page does not un-leak it. Move secrets to server-side environment variables and expose only public, origin-restricted keys to the browser. Add a secret scanner (gitleaks, GitHub secret scanning) to CI so the next one never reaches production.

Order of work: revoke, rotate, then fix, then look at logs. For AWS:

aws iam update-access-key --access-key-id AKIA... --status Inactive --user-name app-user
aws iam create-access-key --user-name app-user
# deploy the new key, then:
aws iam delete-access-key --access-key-id AKIA... --user-name app-user

Check CloudTrail (or the equivalent audit log of the provider) for use of the old key since it was first deployed.

Keep secrets on the server. In Next.js only variables prefixed NEXT_PUBLIC_ are placed in the client bundle; everything else stays in the server runtime. Call the third-party service from a route handler and return only the result:

// app/api/send/route.ts
export async function POST(req: Request) {
  const body = await req.json();
  const res = await fetch('https://api.example.com/v1/send', {
    method: 'POST',
    headers: { Authorization: 'Bearer ' + process.env.EMAIL_API_KEY },
    body: JSON.stringify(body),
  });
  return Response.json({ ok: res.ok });
}

In Vite only VITE_ variables are exposed, and in Create React App only REACT_APP_. Restrict keys that must be public — set an HTTP-referrer allowlist and an API allowlist in the provider console.

Catch the next one before release:

# CI step or pre-commit hook
gitleaks detect --source . --redact

Turn on GitHub secret scanning and push protection for the repository. Verify by viewing the page source, searching for the prefixes in this table, and by scanning the built JavaScript too, since this check reads only the HTML response.

Common Mistakes

  • Removing the key from the page and stopping there. The key was public from the first deploy and may already be in a bot's list; revoke and rotate it.
  • Naming a secret variable with the framework's public prefix (NEXT_PUBLIC_, VITE_, REACT_APP_). Those prefixes mean copy this into the browser bundle.
  • Putting a server key in a client component because it was easier than writing an API route.
  • Restricting a Google key by API but not by referrer, or the other way around. Use both.
  • Committing a .env file once, deleting it, and assuming git forgot it. History keeps it; rotate the credentials as well.
  • Leaving a secret in a build-time environment variable that the bundler inlines, such as a value read at import time in shared code.

Frequently Asked Questions

What is Exposed API Keys & Secrets?

Credentials such as AWS access keys, Stripe live keys, GitHub tokens and private keys sometimes ship to the browser inside HTML or bundled JavaScript, where anyone can read them.

Why does Exposed API Keys & Secrets matter for website security?

A leaked key is an immediate compromise, not a theoretical one: automated scanners harvest public pages for key patterns within minutes of publication. Depending on the key, an attacker gets your cloud account, your payment data, or your source repositories — no exploit required.

How do I fix Exposed API Keys & Secrets issues?

Revoke and rotate every exposed credential first — removing it from the page does not un-leak it. Move secrets to server-side environment variables and expose only public, origin-restricted keys to the browser. Add a secret scanner (gitleaks, GitHub secret scanning) to CI so the next one never reaches production.

Related Security Checks

Check Your Website Now

Run a free security scan to check for Exposed API Keys & Secrets issues and 61 other security checks.

Scan Your Website Free