Skip to content

Redaction pattern reference

The complete, normative list of what redact.String matches and what it puts in its place. Every pattern below is quoted verbatim from redact.go; if this page and the code ever disagree, the code is right and this page is a bug.

There is no way to add, remove, or reorder these rules; see What redact does not do. For why the catalogue is shaped this way, see Why the rule catalogue looks like this.

The order rules are applied in

String runs eight kinds of rule in a fixed order, each operating on the output of the last:

# Rule Replacement
1 URL userinfo <redacted>
2 Credential assignments (name=value) ***
3 JSON credential fields ***
4 Authorization headers in free text ***
5 AWS secret-key assignments ***
6 JSON Web Tokens <redacted-token>
7 Well-known provider prefixes (13 patterns, in table order) <prefix>***, or <redacted-token> inside a longer run
8 The long-opaque-token fallback <redacted-token>

Order is load-bearing in one direction only: the specific, high-confidence rules run before the broad fallback, so a secret a named rule already masked is never re-examined. That is why token= followed by a 41-character value comes back as token=*** and not token=<redacted-token>: rule 2 got there first.

URL userinfo

regexp.MustCompile(`([A-Za-z][A-Za-z0-9+.\-]*://)[^/\s:@]*:[^/\s@]+@`)
// replacement: "${1}<redacted>@"

Matches the user:password@ component of a URL for any RFC 3986 scheme, not just HTTP. The scheme is captured and written back verbatim, so the shape of the URL survives redaction.

https://admin:hunter2@api.example.com/v1  →  https://<redacted>@api.example.com/v1
postgres://svc:s3cret@db.internal:5432/x  →  postgres://<redacted>@db.internal:5432/x
redis://:hunter2@cache.internal:6379      →  redis://<redacted>@cache.internal:6379
mongodb+srv://u:p@cluster.example/db      →  mongodb+srv://<redacted>@cluster.example/db
ldap://cn=admin:pw@host                   →  ldap://<redacted>@host

Connection strings in dial errors are the single most common shape of leaked credential, which is why the scheme is left open rather than restricted to http/https.

The username half may be empty (redis://:pass@host matches) but the colon and the password may not. These are not matched:

Input Why not
user:pass@host No ://, so bare a:b@c prose stays intact
https://user@host/path No :password, so a token used as the whole userinfo is not caught here
https://:@host/path Password is empty
file:///etc/passwd No userinfo at all

Credential assignments (name=value)

const credentialNames = `apikey|api[_-]?key|key|access_token|refresh_token|id_token|token|private_token|` +
    `secret|client_secret|secret_key|private_key|access_key|password|auth|authorization|signature`

regexp.MustCompile(`(?i)(\b(?:` + credentialNames + `)|[?&](?:code|sig))=([^&\s]+)`)
// replacement: "$1=***"

credentialNames is the single list of credential names, and the JSON rule uses the same one, so every name below is masked in both name=value and "name":"value" form:

apikey, api_key, api-key, key, access_token, refresh_token, id_token, token, private_token, secret, client_secret, secret_key, private_key, access_key, password, auth, authorization, signature

Matching is case-insensitive, the value is masked, and the name is kept.

Despite the variable name queryCredPattern, this rule is not limited to URLs. It fires on any name=value in free text, which is deliberate: the same names turn up in form-encoded request bodies, command lines and environment dumps:

POST /v1?apikey=sk-abc123&user=bob     →  POST /v1?apikey=***&user=bob
--api-key=sk-abc123 --verbose          →  --api-key=*** --verbose
login?user=bob&password=hunter2        →  login?user=bob&password=***
client_secret=cs1 grant_type=x         →  client_secret=*** grant_type=x
GET /api/v4/projects?private_token=x   →  GET /api/v4/projects?private_token=***
SECRET_KEY=abc                         →  SECRET_KEY=***

Two more names, code (the OAuth authorisation code) and sig (the Azure SAS signature), are masked only as a query parameter, directly after ? or &. Both are ordinary words, so matching them anywhere else would mask exit codes and status codes in free text. They are not in the JSON list either, where {"code":"invalid_request"} is an error code, not a credential.

Input Output
/callback?code=abc&state=xyz /callback?code=***&state=xyz
blob?sv=2022&sig=abc blob?sv=2022&sig=***
exit code=1 unchanged
?barcode=123 unchanged

The value runs to the next whitespace or &, and nothing else. Any other delimiter is swallowed with the value, so redaction can mangle surrounding structure:

Input Output
Cookie: token=abc; theme=dark Cookie: token=*** theme=dark, the ; goes too
msg="key=abc" other=1 msg="key=*** other=1, the closing quote goes too
token=abc) token=***, the ) goes too

The name must start on a word boundary, so a credential name glued to a longer word is not matched, and one separated by a hyphen or a space is:

Input Output
sort_key=name unchanged: _ is a word character, so there is no boundary
secret_keyboard=x, private_keys_count=3 unchanged: = must follow the name directly
aws_access_key_id=x unchanged: access_key sits between _s, so neither boundary nor = fits
sort-key=name sort-key=***, a false positive
monkey=banana unchanged
primary key=abc primary key=***

= is required. api_key: abc123, the YAML or ini spelling, is not matched by this rule, and only aws_secret_access_key and secret_access_key have a rule that accepts a colon.

JSON credential fields

regexp.MustCompile(`(?i)("(?:` + credentialNames + `)"\s*:\s*")([^"]+)"`)
// replacement: `${1}***"`

Matches a quoted "key": "value" pair whose key is one of the shared credential names, and replaces the value with ***. The key, colon and opening quote are captured and written back, and the closing quote is restored, so a body whose values contain no escaped quotes stays well-formed JSON. OAuth token-endpoint responses quoted inside HTTP client errors are the shape this exists for.

The key list is exactly the assignment rule's shared list. code and sig, which the assignment rule accepts only as query parameters, are not in it. The key must be the whole quoted name, so "nonsecret" and "keyboard" are not matched.

{"access_token":"ya29.a0abc","token_type":"Bearer"}  →  {"access_token":"***","token_type":"Bearer"}
{"password": "x"}                                    →  {"password": "***"}
{"API_Key":"abc12345"}                               →  {"API_Key":"***"}
{"client_secret":"cs_abc123def"}                     →  {"client_secret":"***"}
{"key":"abc"}                                        →  {"key":"***"}
{"code":"invalid_request"}                           →  unchanged
{"name":"bob","token_type":"bearer"}                 →  unchanged

Whitespace either side of the colon is allowed. Only the value is masked; key names are never touched, which is what keeps a redacted body readable.

This is a text pattern, not a JSON parser. A value containing an escaped quote ("secret":"a\"b") ends the match at that quote and leaves the remainder of the value in the output.

Authorization headers in free text

regexp.MustCompile(`(?i)(authorization:\s*)(bearer|basic|digest|apikey)\s+([A-Za-z0-9._~\-+/=]+)`)
// replacement: "${1}$2 ***"

Matches an authorization: header written into a log line or error message, followed by one of four schemes (Bearer, Basic, Digest, ApiKey) and masks the credential while keeping the header name and the scheme, so you can still see which auth failed.

Authorization: Bearer abc123def456        →  Authorization: Bearer ***
Authorization: Basic dXNlcjpwYXNz         →  Authorization: Basic ***
Proxy-Authorization: Basic dXNlcjpwYXNz   →  Proxy-Authorization: Basic ***
Authorization:Bearer abc123def456         →  Authorization:Bearer ***

Proxy-Authorization matches because the pattern is unanchored and proxy-authorization: ends in authorization:.

These are not matched:

Input Why not
Authorization: token abc123 token is not one of the four schemes
authorization : Bearer abc Whitespace before the colon is not allowed
BEARER abc123def456 The authorization: prefix is required
X-API-Key: abc123def456 This rule only knows authorization:

That last row is the important one. String does not mask arbitrary header values. See Does String mask HTTP header values? and the sensitive header reference.

AWS secret-key assignments

regexp.MustCompile(`(?i)(aws_secret_access_key|secret_access_key)(\s*[=:]\s*)\S+`)
// replacement: "${1}${2}***"

AWS secret access keys carry no distinguishing prefix, so they are matched by the name they are assigned to rather than by their value, because matching a bare 40-character string would also scrub every git SHA-1 in your logs. The name and the separator (which may be = or :, with optional surrounding whitespace) are preserved.

aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/…    →  aws_secret_access_key=***
AWS_SECRET_ACCESS_KEY = wJalrXUtnFEMI/K7MDENG/…  →  AWS_SECRET_ACCESS_KEY = ***
secret_access_key : abc def                      →  secret_access_key : *** def

The value is \S+, everything up to the next whitespace. A secret containing a space is only partly masked; a bare aws_secret_access_key with nothing assigned is left alone.

JSON Web Tokens

regexp.MustCompile(`eyJ[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+`)
// replacement: "<redacted-token>"

Matches the three-segment base64url shape beginning with the distinctive eyJ header prefix (which is {" base64-encoded) and replaces the whole token. Unlike the provider prefixes, there is no fragment worth keeping. It catches bare Bearer eyJ… tokens that the Authorization-header rule misses because they carry no authorization: prefix.

Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.dozjgNryP4J  →  Bearer <redacted-token>

All three segments are required, each at least one character: a two-segment eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0 is not matched.

Only the URL-safe base64 alphabet is recognised. Standard base64's + and /, and = padding, are outside the character class, and a token that uses them fares badly in either of two ways. A + inside a segment stops the token matching at all, and a / in the final segment ends the match early, leaving the tail in the clear:

eyJhbGciOiJIUzI1NiJ9.eyJzdWIi+OiIxIn0.abc   →  unchanged
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.ab/c=  →  <redacted-token>/c=

JWTs are specified to use the URL-safe alphabet, so this bites only on a malformed or re-encoded token.

Well-known provider prefixes

Thirteen patterns whose prefix is unambiguous enough that a match is almost certainly a real credential. Each keeps its literal prefix for debug readability and replaces the rest with ***.

The number of characters kept is anchored to the known prefix. It is a constant per pattern, never measured from the matched text. That is what stops a token whose body happens to contain _ or - from leaking a fragment of itself.

A prefix that sits inside a longer run, after other [A-Za-z0-9_-] characters, takes the whole run with it and becomes <redacted-token>. Keeping the prefix there would leave the head of the run in the clear:

see sk-<16 or more>            →  see sk-***
see token_sk-<16 or more>      →  see <redacted-token>
see the-ask-for-the-review-process  →  see <redacted-token>

That includes a slug in which sk- is only the end of ask- or task-. A run that reads as words is not spared here: random letters read as words often enough that sparing them would leave the head of a real token in the clear.

Provider Pattern Minimum body Redacts to
OpenAI / Anthropic-style sk-[A-Za-z0-9_\-]{16,} 16 sk-***
GitHub PAT (classic) ghp_[A-Za-z0-9]{30,} 30 ghp_***
GitHub OAuth gho_[A-Za-z0-9]{30,} 30 gho_***
GitHub app server ghs_[A-Za-z0-9]{30,} 30 ghs_***
GitHub fine-grained PAT github_pat_[A-Za-z0-9_]{30,} 30 github_pat_***
GitLab personal access token glpat-[A-Za-z0-9_\-]{16,} 16 glpat-***
GitLab runner token glrt-[A-Za-z0-9_\-]{16,} 16 glrt-***
GitLab deploy token gldt-[A-Za-z0-9_\-]{16,} 16 gldt-***
Slack xox[baprs]-[A-Za-z0-9-]{10,} 10 xoxb-*** (etc.)
Google API key AIza[A-Za-z0-9_\-]{30,} 30 AIza***
AWS access key ID AKIA[A-Z0-9]{16} exactly 16 AKIA***
Hugging Face access token hf_[A-Za-z]{34}\b exactly 34 letters hf_***
Hugging Face organisation token api_org_[A-Za-z]{34}\b exactly 34 letters api_org_***

The minimum body length is a hard floor, not a hint. sk- followed by 15 characters is left in the clear; 16 is redacted. AKIA requires exactly 16 uppercase letters or digits, matching the real AWS access-key-ID format, so AKIAIOSFODNN7EXAMPL (15) passes straight through.

The Slack pattern covers xoxb, xoxa, xoxp, xoxr and xoxs only. Other Slack token families, xoxc among them, are not matched.

The long-opaque-token fallback

regexp.MustCompile(`(?:^|[^A-Za-z0-9_\-])[A-Za-z0-9_\-]{41,}`)
// replacement: the leading character, if any, then "<redacted-token>"

Anything still left that is a single run of 41 or more characters from [A-Za-z0-9_-] is replaced whole, including a - or _ at either end. The run must start the string or follow a character outside the class, and that character is kept. This is the catch-all for high-entropy secrets with no recognisable prefix, and it runs last so it only ever sees what the named rules did not claim.

The threshold clears the opaque strings that legitimately appear in error text:

Value Length Redacted?
UUID (no hyphens) 32 No
MD5 hash 32 No
UUID (with hyphens) 36 No
SHA-1 / git commit hash 40 No
SHA-256 hash 64 Yes

Because - is inside the character class, two adjacent 41-character runs joined by a hyphen are treated as one token and replaced with a single <redacted-token>.

Runs made of words are left alone

A run that reads as words is not replaced, however long it is. Split the run at every - and _. Every piece must be either a number of at most 8 digits, or all letters whose CamelCase humps are each a word or an acronym. A word has at most 16 letters and contains a vowel (aeiouy, either case). An acronym is at most 4 uppercase letters with no vowel. An acronym run stays whole, so HTTPServer is HTTP and Server. The run is spared only when its words outnumber its numbers and acronyms together.

Value Redacted? Why
0004-agent-service-accounts-and-session-roster No digits, then words
TestARelayDeliversASpooledHandoverAsItsSessionsRole No every hump is a word
PHPBOYSCOUT_AGENT_TOOLKIT_SESSION_HANDOVER_PATH No every piece is a word
0002-kms-ed25519-minisign-artifact-signing Yes ed25519 mixes letters and digits
Thequickbrownfoxjumpsoverthelazydogagainandagain Yes one hump of 48 letters
QWER-TYUP-ASDF-GHJK-ZXCV-BNMQ-WRTP-SDFG-HJKL Yes six acronyms against three words
123456-654321-112233-445566-778899-990011-223344-556677 Yes numbers only, no words
recovery-123456-654321-112233-445566-778899-990011-223344-556677 Yes one word against eight numbers
the-otp-seed-314159265358979323846264338327950288419716939937 Yes a 48-digit piece is not a number
41 random base62 characters Yes, except about 2 in a million short humps without vowels

A few real credential formats can read as words by chance and are let through at these rates, measured on 2026-11-02 over two million each: Linear lin_api_ and Notion secret_ keys a few in a million, and a token of 41 mixed-case letters with no digits about 1 in 470. Hugging Face tokens are letters only and would often read as words, which is why they have their own rules above.

Replacement tokens

Token Length Used for
<redacted> 10 URL userinfo
*** 3 Assignment values, JSON values, Authorization credentials, AWS secret values, provider-prefix bodies
<redacted-token> 16 JWTs and the long-opaque-token fallback

None of these re-matches any rule, which is what makes String idempotent. They are not configurable, and there is no marker distinguishing "a rule fired here" from a literal *** that was in the input already.