devtools.codes

How to check for API keys before you commit

Your tool input is processed locally in your browser and is not intentionally uploaded to our servers. Advertising and analytics providers may still process normal page, device, cookie and network information.

Catching a credential before it reaches a commit is dramatically cheaper than dealing with one afterwards. Once a secret has been pushed it must be rotated, and rewriting history does not change that.

The values worth looking for fall into a few families. Provider API keys usually have recognisable prefixes — a short identifier followed by a long random string — which makes them the easiest category to catch reliably. Private key blocks announce themselves with a BEGIN header. Connection strings embed a password between the username and the host, and are easy to miss because they look like configuration rather than a credential. And then there are unstructured values: something assigned to a variable called token or secret that matches no known format.

The last category is where detection gets uncertain. A high-entropy string assigned to a secret-sounding name is often a credential and often a hash, an identifier or a test fixture. Any tool that flags these will produce false positives, and any tool that does not will miss real secrets. Seeing them separately from confident matches is more useful than having the tool guess.

Placeholders should not be flagged. A value written as ${API_KEY} is a reference, not a secret, and a scanner that reports it teaches you to ignore its output — which is the real failure mode, because a noisy tool gets switched off.

Run the check at the point where it is cheap: before staging, or in a pre-commit hook, or before pasting a configuration file into a chat window. The last of those is worth calling out, since pasting a config into an assistant to ask what is wrong with it is a routine way for credentials to escape.

Treat a clean result as one check rather than a clearance. Pattern matching finds what it recognises. A credential in an unusual format, encoded, or split across lines can pass unnoticed, and no scanner can promise otherwise.

More on how to check for API keys before you commit

Does .gitignore protect me?

Only for files that were never tracked. Adding a path to .gitignore does nothing for a file already in the index, and nothing at all for the history of one committed previously. It is a good preventative measure and no help whatsoever after the fact, which is a distinction worth being clear about before relying on it.

Should I scan before staging or before pushing?

Before staging, because that is where the fix is a single edit. A pre-commit hook is the natural place for an automated check, and a manual scan is worth doing before pasting any configuration file or log excerpt into a chat window — which is a routine and easily forgotten way for credentials to leave a machine.

Why are placeholders not flagged?

Because a value written as ${API_KEY} is a reference rather than a secret, and reporting it trains you to skim past the output. A scanner that cries wolf gets switched off, and a tool that is switched off catches nothing. Suppressing obvious placeholders is what keeps the remaining findings worth reading.

Does a clean scan mean the file is safe?

No. Pattern matching finds what it recognises. A credential in an unusual format, one that is base64 encoded, or one split across lines can pass unnoticed, and no scanner can promise otherwise. Treat a clean result as one useful check among several rather than as a clearance to publish.

The tool behind this, and related guides