Hardcoded secret
A hardcoded secret is a password, API key or access token written directly into a site's code or files. If that code reaches a browser or a public repository, anyone can copy the secret and use your account.
Why it matters
Leaked secrets are growing fast. GitGuardian found 28.65 million new hardcoded secrets in public GitHub commits in 2025, a 34% rise on 2024.1 Secrets for AI services alone rose 81%, to 1,275,105, in its data.1
A key in front-end code is a published key. Someone who finds it can run up your bill, send email in your name or read your data.
In practice
- Keep secret keys on the server or in the platform's secrets vault.
- Search the code for
secret,api_key,tokenandsk_before launch. - Revoke any key that was ever in public code, even briefly.
- Give each tool its own key, so you can revoke one.
- Turn on secret scanning in your code repository.
What the sources say
AI service secrets reached 1,275,105, up 81% year over year.
GitGuardian, March 2026, The State of Secrets Sprawl 2026
What to do about hardcoded secret, depending on who you are
If you built the site with an AI tool
AI tools often paste keys into front-end code to make a feature work. GitGuardian counted 1,275,105 leaked AI service secrets in 2025, up 81% in a year.
- Search the project for key-like strings before launch.
- Move any secret to the server or the platform vault.
- Revoke and replace every key that was exposed.
If you manage a team's code
Most leaks happen in ordinary commits. Catching them before they're pushed costs far less than rotating keys afterwards.
- Turn on secret scanning and push protection in the repository.
- Keep keys in environment variables, never in config files.
- Rotate keys on a schedule.
Go deeper
My guide to vibe-coded website security shows where AI tools tend to leave keys and how to check.