An API key that looks like any other random string cannot be reliably found when it leaks, cannot be told apart from a hash or an ID, and cannot be routed to the team that can revoke it. Over the last few years many providers have redesigned their tokens with identifiable prefixes, checksums and fixed encodings so that scanners can find them with almost no false positives and report them to the issuer automatically. This guide explains each design element, what it buys and what it does not, using formats that providers publish in their own documentation, and gives a practical recipe for designing your own token format. It is for platform engineers who issue API keys or tokens and for secrets programme owners who run scanning and revocation.
Key takeaways
- Format is a security control. A distinctive prefix plus a checksum turns leak detection from guesswork on entropy into a near-exact match, which makes automated revocation practical.
- Prefixes identify issuer, type and environment. Published examples include
ghp_,glpat-,pypi-,xoxb-andsk_live_; none of them carry secret material. - Checksums let anyone discard fakes offline. GitHub stores a 32-bit CRC32 checksum in the last six characters so candidates can be validated without a database call; a checksum is not a signature and adds no secrecy.
- Entropy still does the security work. The random part must come from a CSPRNG with at least 128 bits of entropy, as OWASP ASVS 5.0 requires for non-guessable strings.
- Design for the whole leak lifecycle. A good format is matched by a published pattern, a scanning partner integration, a revocation endpoint and server-side storage of only a hash.
Why secret format matters
Secret scanners face two problems with unstructured keys. Generic high-entropy detection produces large numbers of false positives (hashes, UUIDs, random IDs), and even a true match does not say which service issued the credential, so triage is slow. GitHub describes its old tokens as 40-character hexadecimal strings that looked like SHA hashes, which made detection "inefficient and sometimes inaccurate". When the format is distinctive, three things improve at once:
- Precision: a regular expression anchored on a unique prefix matches almost only real tokens. GitHub expected the prefix alone to bring its secret scanning false positive rate down to 0.5%.
- Routing: the prefix names the issuer and token type, so a finding goes straight to the right revocation process. See the Developer Secret Scanning Triage.
- Automation: issuers can join scanning partner programmes and receive reports for leaked tokens within their own systems, without the leaking customer doing anything.
Leaked credentials found in files are mapped by MITRE ATT&CK as T1552.001 Credentials In Files under T1552 Unsecured Credentials. Format design does not stop the leak; it shortens the time from exposure to revocation.
Identifiable prefixes
The table lists prefixes exactly as each provider documents them, as of November 2026. Providers are listed alphabetically; the order is not a ranking, and each provider's own guide on this site covers its tokens in depth.
| Provider | Documented prefixes (examples) | What the prefix encodes | Source |
|---|---|---|---|
| GitHub | ghp_ personal access token, gho_ OAuth access, ghu_ user-to-server, ghs_ server-to-server, ghr_ refresh | Issuer ("gh") plus the first letter of the token type, joined by an underscore | GitHub engineering blog |
| GitLab | glpat- personal, project, group and impersonation tokens; gldt- deploy; glrt- runner; glcbt- CI/CD job; glptt- trigger; gloas- OAuth application secret | Issuer ("gl") plus token type; GitLab describes them as "standard identifications" | GitLab token overview |
| PyPI | pypi- followed by a base64-serialised macaroon | Issuer; documented match pattern pypi-[A-Za-z0-9-_]{85,} | PyPI secret reporting API docs |
| Slack | xoxb- bot, xoxp- user, xapp- app-level, xoxe.xapp- rotating app-level | Token family and type | Slack token types docs |
| Stripe | pk_ publishable, rk_ restricted, sk_ secret, each with _test_ or _live_; sk_org_ organisation | Key type and mode (sandbox or live), which also signals whether the key is safe to expose | Stripe API keys docs |
Provider details: the GitHub Token Types and Prefixes Reference, GitLab Tokens Security Guide, PyPI API Tokens and Trusted Publishing Security Guide, Slack Tokens Security Guide and Stripe API Keys Security Guide.
Prefix design choices
- Separator outside the body alphabet: GitHub chose an underscore because it is not a Base64 character, so a random string is unlikely to reproduce the prefix by accident, and because double-clicking selects the whole token. Hyphens and dots also appear in published formats; whichever you choose, keep it out of the random body's alphabet if possible.
- Type and environment, never secrets: encode issuer, token type and environment (Stripe's
_test_and_live_are a clear example). Never put customer IDs, email addresses, tenant names, scopes or anything confidential in the prefix: it is printed in logs, scanners and alerts by design. - Stable and fixed: GitLab notes its prefixes cannot be configured (except personal access tokens), because stability is what lets scanners rely on them.
- Distinct per type: separate prefixes for long-lived keys, short-lived access tokens and refresh tokens let responders prioritise.
The IETF published a vendor-neutral alternative, RFC 8959 "The 'secret-token' URI Scheme" (Informational, January 2021), which wraps any token as secret-token:<token> so repositories and CI systems can refuse commits containing it. The RFC notes the scheme cannot prevent intentional disclosure and that users may strip the scheme to evade detection.
Checksums and offline validation
A prefix tells a scanner what a string claims to be; a checksum lets it check that claim cheaply. GitHub's design computes a 32-bit CRC32 over the token, encodes it in Base62 with leading zero padding, and places it in the last six characters. In GitHub's words, this lets it "eliminate fake tokens without having to hit our database". GitHub's secret scanning partner programme documentation recommends the same three traits for any issuer: a uniquely defined prefix, high-entropy random strings and a 32-bit checksum.
| Design element | Benefit | What it does not do |
|---|---|---|
| Unique prefix | Near-exact scanner matching; routes findings to issuer and type | Does not prove the string is a real token |
| Non-alphabet separator | Random strings cannot mimic the prefix; whole token selectable | No security value on its own |
| Checksum (e.g. CRC32, 32 bits) | Offline rejection of typos, examples and fakes; fewer false positives and API calls | Not a MAC or signature: anyone can compute a valid checksum, so it never authenticates |
| Fixed length and alphabet | Tight regex with low false positives; predictable storage | Does not add entropy |
| CSPRNG random body (128 bits or more) | Unguessability, the actual security property | Does not help detection |
| Environment marker (test or live) | Severity triage; safe-to-expose keys distinguishable | Must not replace server-side checks on mode |
| Published pattern and partner integration | Third-party scanners report leaks to the issuer automatically | Needs a working, monitored revocation path |
Because the checksum is public knowledge, an attacker can generate strings with valid checksums. That is harmless: a valid checksum only means "worth checking", and the issuer still validates the token against its store. Do not use a keyed MAC in the token as a substitute for a server-side lookup unless you have designed the key management for it.
Entropy, length and encoding
- Entropy target: OWASP ASVS 5.0 requirement V11.5.1 asks that non-guessable strings come from a CSPRNG with at least 128 bits of entropy, and notes that UUIDs do not meet this. Many issuers go higher; GitHub raised OAuth token entropy from 160 to 178 bits while keeping the length unchanged.
- Encoding: Base62 (letters and digits) avoids characters that break in URLs, shells and config files, and keeps tokens selectable. Base32 is case-insensitive and easier to read aloud; Base64url is denser. Pick one alphabet and fix the length.
- Length budget: total length = prefix + separator + random body + checksum. With Base62, each character carries about 5.95 bits, so 128 bits needs at least 22 characters of body and GitHub's six-character checksum holds 32 bits.
- Structured tokens: some formats serialise a structured credential after the prefix. PyPI's tokens are
pypi-followed by a base64 macaroon of variable length (85 characters or more), so scanners match a minimum length rather than an exact one.
Designing your own token format
- Inventory what you issue: list every credential type (API keys, personal tokens, service tokens, refresh tokens, webhook secrets) with lifetime and blast radius.
- Choose a prefix scheme: a short, registered-looking issuer code plus a type code (and environment where relevant), and a separator outside your body alphabet. Check public scanner rule sets for collisions with existing prefixes.
- Generate the body: at least 128 bits from a CSPRNG, encoded in a fixed alphabet and length.
- Append a checksum: a 32-bit CRC over prefix and body, encoded in the same alphabet with fixed padding. Document the algorithm so scanners can validate offline.
- Store only a hash: keep a hash of the full token server side (with the prefix and perhaps the last few characters shown in your console for identification). This supports lookup without retaining the secret, in line with NIST SP 800-53 IA-5 authenticator management and SC-28 protection at rest.
- Publish the pattern: document the regex, join scanning partner programmes and provide a signed-report endpoint. GitHub's programme sends a JSON list with
token,type,urlandsource, signed with ECDSA (NIST P-256, SHA-256), and asks partners to treat every reported secret as public and compromised. PyPI adopted the same reporting pattern for its own API. - Roll out alongside old formats: issue new-format tokens to new requests first, accept both formats during a migration window, prompt users to rotate old tokens, then retire the old format with a dated notice.
- Test: unit-test generation, checksum validation and rejection of altered tokens; run your published regex against real repositories and logs to measure false positives before announcing it.
Rollback is simple if the server accepts both formats during migration: if a client library mishandles the new separator or length, keep issuing the old format to that client while it is fixed. For broader key handling, see the API Key Management Guide.
Impact on secret scanning and revocation
| Stage | Without a designed format | With prefix, checksum and partner integration |
|---|---|---|
| Detection | Entropy heuristics, many false positives | Anchored regex plus checksum check, few false positives |
| Attribution | Manual guess at issuer | Prefix names issuer and type |
| Validation | Live API call for every candidate | Offline checksum first, live check only for survivors |
| Notification | Depends on the person who leaked it | Scanner reports to issuer endpoint automatically |
| Revocation | Manual, often delayed | Issuer can revoke or alert the owner on receipt |
Internal scanners benefit the same way: precise rules for your own formats can run in pre-commit hooks, CI and push protection without alert fatigue. See the Git Secret Scanning Guide and the Secret Scanner Rule Coverage Comparison Guide.
Measuring the programme
- Share of issued credentials in a prefixed, checksummed format.
- Scanner precision for your own token rules (true findings divided by all findings).
- Median time from leak report to revocation or owner notification.
- Number of legacy-format tokens still active, trending to zero.
- Partner report volume and the share processed automatically.
Common failure patterns
- Encoding tenant names, user IDs or scopes in the prefix, leaking information through every log line and alert.
- Treating the checksum as proof of authenticity and skipping the server-side lookup.
- Using UUIDs or timestamps as the random body, which falls short of 128 bits of entropy.
- Publishing a prefix but no revocation endpoint, so reports arrive with nowhere to go.
- Allowing legacy unprefixed tokens to live on indefinitely after the new format ships.
- Storing tokens in plaintext so the issuer can "show" them later, which turns a database read into a credential leak.
Framework mapping
| Framework | Reference | How format design supports it |
|---|---|---|
| NIST SP 800-53 Rev 5 | IA-5 Authenticator Management; IA-5(7) No Embedded Unencrypted Static Authenticators | Detectable formats make embedded secrets findable and revocable |
| NIST SP 800-53 Rev 5 | SC-28 Protection of Information at Rest; SI-4 System Monitoring | Hash-only storage; scanning for exposed tokens |
| NIST CSF 2.0 | PR.AA-01 | Credentials for services managed by the organisation |
| OWASP ASVS 5.0 | V11.5.1 | CSPRNG with at least 128 bits of entropy |
| MITRE ATT&CK v20 | T1552.001 Credentials In Files | Shortens exposure window for leaked keys |
Practitioner checklist
- List every credential type you issue and decide its prefix, type code and environment marker.
- Keep prefixes free of any confidential or customer data.
- Generate at least 128 bits of CSPRNG entropy in a fixed alphabet and length.
- Append and document a 32-bit checksum for offline validation, and never treat it as authentication.
- Store only hashes of issued tokens.
- Publish the regex, join scanning partner programmes and run a signed-report revocation endpoint.
- Migrate legacy formats with a dated retirement plan and measure remaining legacy tokens.
- Add rules for your own formats to internal pre-commit, CI and push protection scanning.
Standards and references
- IETF: RFC 8959 The "secret-token" URI Scheme
- OWASP: Application Security Verification Standard 5.0
- GitHub Docs: Secret scanning partner program
- GitHub: Behind GitHub's new authentication token formats
- GitLab Docs: GitLab token overview
- PyPI Docs: Secret Reporting API
- Slack Developer Docs: Token types
- Stripe Docs: API keys
Related NHI Mgmt Group resources: Secrets Management Guide · API Key Management Guide · Git Secret Scanning Guide · API Key Leak Response Playbook