
New releaseAug 25, 2026
Zero-dependency Go library stripping credential-like patterns (API keys, JWTs, Authorization headers, URL userinfo) before they reach logs/telemetry.
gitlab.com/phpboyscout/go/redact redacts credential-like content from free-form
strings at the boundary between trusted and untrusted observability surfaces —
telemetry vendors, log aggregators, metric stores. Error messages, command
arguments, and HTTP header values routinely carry secrets by accident (a URL with
embedded userinfo, an --api-key=sk-… flag in os.Args, an Authorization
header quoted in an export error). Route those through redact.String on the way
out and they never leave the process in the clear.
regexp, strings) — nothing but
the module enters your graph. A depfootprint_test.go guard enforces it.go get gitlab.com/phpboyscout/go/redact
import "gitlab.com/phpboyscout/go/redact"
safe := redact.String("failed calling https://user:[email protected]?api_key=sk-abc123…")
// → credentials in the URL userinfo, the api_key query param, and the sk- token are masked
msg := redact.Error(err) // redact.String applied to err.Error() (nil-safe)
if redact.IsSensitiveHeaderKey("Authorization") { /* … redact this header's value … */ }
redact.String strips URL userinfo for any scheme (https://, postgres://,
redis://, …), credential name=value assignments, JSON credential fields such
as "access_token" and "client_secret", Authorization-header tokens, JWTs,
well-known provider prefixes (sk-, ghp_, glpat-, AIza, AKIA, Slack),
and long opaque tokens. SensitiveHeaderKeys / IsSensitiveHeaderKey identify
headers whose values should be redacted.
Pattern catalogues never reach 100% recall, and this one is deliberately conservative:
String does not mask arbitrary header values. It knows Authorization:
and nothing else; X-API-Key: … passes through. That is what the header
symbols are for.What redact does not do states the full boundary.
Full guides, reference and threat model: redact.go.phpboyscout.uk. Generated API docs and runnable examples: pkg.go.dev.
See LICENSE.