API Keys in Documents: The Leak Nobody Screens For

← PII Shield · All guides

Secrets rarely leak from repositories. They leak into documents: screenshots with a bearer token in a header, meeting notes with a test credential, a Support ticket quoting an Authorization header, a paste of environment variables "quickly" sent to a colleague.

Why keyword matching fails

Searching for "key", "token" and "password" finds the field names, not the values, and misses the value in X-Api-Key: sk_live_4eC39HqL… when the label is truncated off the screenshot.

What actually identifies a secret

Prefixes the provider publishes. OpenAI keys start sk- (project keys carry a suffix), Google API keys start AIza, AWS access keys are AKIA + 16 uppercase, Stripe keys carry sk_live/sk_test, pk_live/pk_test, GitHub tokens are ghp_/gho_/ghs_/… and Slack tokens xox[baprs]-. These are stable, public conventions — a detector can anchor on them exactly.

Structure, when there is no prefix. A JWT has three base64url segments split by two dots, and the first decodes to JSON with a header. A PEM private key begins with a literal -----BEGIN line. These are formats, not guesses.

Entropy as a filter, not a trigger. Randomness alone will flag every base64 blob, and a short secret like a 12-char key can be below a flat threshold. PII Shield length-normalises (H ≤ log₂(len) is the ceiling — a fixed threshold is a length test in disguise) and uses entropy only to discard high-structure-confidence candidates that are too regular to be secret, like aaaaaaaaaaaaaaaa.

Banlists are as important as detectors

sk-example, YOUR_API_KEY, CHANGEME, xxxxxxxxxxxxxxxx — documentation placeholders. A detector that screams at these trains the user to ignore every later warning. Half of PII Shield's credential unit suite asserts that placeholders produce no finding.

Prefix families the detector covers

OpenAI (sk-, project keys), Anthropic (sk-ant-), Google (AIza), AWS (AKIA, ASIA for temporary credentials), Stripe (sk_live_, pk_live_, rk_live_), GitHub (ghp_, gho_, ghu_, ghs_, ghr_), Slack (xox[bpars]-), Telegram bot tokens (d+:AA…), Bearer/JWT forms, and -----BEGIN ... PRIVATE KEY----- blocks. Where a provider does not publish a prefix, the detector falls back to structure (JWT segments, base64 entropy) plus the keyword context — with lower confidence shown in the finding list.

Rotation, not just masking

A masked document stops the next reader; it does nothing about readers who already saw the key. The moment a credential lands anywhere you did not intend — a chat, a ticket, a public repo — treat it as burned and rotate: revoke the old key, issue a new one, and only then re-share the masked document. Masking before sending and rotating after a leak are different actions for different failures, and you usually need both.

When you find one

Rotate it. A masked document does not un-leak a key that was already read. Masking stops the next copy; rotation invalidates this one.

Everything on this page runs in your browser — open PII Shield and paste the document you are about to send.