opyeb logscrub

Secrets that leak into logs, and what to do

2026-11-29 · 2 min read

One-line answer: the moment a token appears in a log, treat it as leaked — revoke and reissue first, then clean the logs.

How secrets get there

The most common path is middleware that logs whole request and response headers. Authorization: Bearer … lands in the file, and at debug level the body follows. The second is the query string: putting a token in a URL writes it to access logs, proxy logs and browser history at the same time.

Cookies and session ids, the password inside a database URL, the secret path of a webhook and a signed download URL cause the same problem. Error messages that echo configuration are another frequent source.

Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.EXAMPLE.PAYLOAD
GET /api/v1/checkout?token=EXAMPLEONLYTOKEN123456
Cookie: session=EXAMPLEONLYSESSION
postgres://app:EXAMPLE_ONLY_password@db.example.internal:5432/app

Patterns to search for

JWTs start with eyJ and have three dot-separated parts; GitHub tokens start with ghp_ or github_pat_; AWS keys with AKIA or ASIA followed by 16 characters; Slack with xoxb- or xoxp-; Stripe with sk_live_ or sk_test_; OpenAI with sk-; Google with AIza. These can be found by shape regardless of the field name.

When the shape is unclear, look at the field name. Values after password, secret, token, api_key, authorization, cookie or dsn are candidates. Names alone miss too much, so combine them with patterns.

Common patterns
KindPrefix or shape
JWTeyJ plus three dot-separated parts
GitHubghp_, github_pat_
AWSAKIA or ASIA plus 16 characters
Slackxoxb-, xoxp-, xoxa-
Stripesk_live_, sk_test_, rk_live_
OpenAI, Anthropicsk-, sk-ant-
GoogleAIza
Database URLpostgres://user:password@host

The order to respond in

First establish whether the token is still valid. If it is, revoke it and issue a new one immediately. Revocation comes before cleaning the log, because copies may already exist elsewhere.

Then search other logs, tickets, chats and backups for the same value. For a broadly scoped key, check its usage history for unexpected calls. Finally fix the cause: exclude headers in the logger, move query tokens into headers, remove configuration values from error messages.

  1. Check validity, revoke, reissue
  2. Find the exposure: logs, tickets, chat, backups, CI output
  3. Review usage for abnormal calls or permission changes
  4. Fix the cause: headers, query, error messages, debug level
  5. Add a regression test and a detection rule
grep -RInE 'eyJ[A-Za-z0-9_-]{10,}\.|ghp_[A-Za-z0-9]{20,}|AKIA[A-Z0-9]{16}' /var/log/app

Do not log it in the first place

The best response is prevention. Exclude Authorization, Cookie, Set-Cookie and X-Api-Key from the request logger by default, and log request bodies with an allowlist of fields rather than a denylist.

A structured logger can apply per-field redaction. Add a test that logs a dummy token and scans the output before deployment, so a new field that leaks is caught early.

Questions

Is deleting the token from the log enough?

No. It may already have been copied or shipped elsewhere, so revocation and reissue come first. Cleaning the log only reduces the exposure window.

If the access log has no token, am I safe?

No. Application logs, proxy logs, error trackers and CI output can contain the same value. Check every output path.

Sources

Every example here can be pasted into the workbench as it is.

Open the workbench