Skip to content

fix: redact credential headers from log dumps [COMP-2963] - #1292

Merged
munishchouhan merged 3 commits into
masterfrom
fix/COMP-2963-redact-credentials-in-logs
Nov 19, 2026
Merged

munishchouhan merged 3 commits into
masterfrom
fix/COMP-2963-redact-credentials-in-logs

Conversation

@munishchouhan

@munishchouhan munishchouhan commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Closes part of COMP-2963. The storage half of that story — encrypting Platform credentials at rest in Redis — is split out to COMP-3140 and is not in this PR.

Problem

RegHelper.dumpHeaders wrote every header value verbatim, so any credential in a header reached the logs through each of its callers.

Two paths matter:

  • TowerConnector, at TRACE. The Platform token-refresh response carries the newly minted JWT and JWT_REFRESH_TOKEN in Set-Cookie — parseTokens() reads them from exactly there — and that dump printed them in full.
  • ErrorHandler and the two deny-filters, at WARN/ERROR. Both levels are on at the io.seqera: DEBUG default, so any inbound Authorization header was logged verbatim. On master that is a registry-proxy credential; once the read API lands, ReadApiController accepts a Platform bearer in that header, so this closes the exposure ahead of it.

The same refresh response also has an AccessRefreshToken body holding both tokens again — verified against Platform's own OauthControllerTest, which deserializes /oauth/access_token into that type. It was logged in full at TRACE and truncated to 500 chars at DEBUG, the default level. Redacting only the header would have left the identical token pair one field over.

Separately, JwtAuth.toString() returned the full bearer and refresh token whenever TRACE was enabled, via a trunc0 helper that consulted the log level.

Change

  • RegHelper.dumpHeaders redacts authorization, proxy-authorization, cookie and set-cookie. Matching is case-insensitive via equalsIgnoreCase — HTTP header names are case-insensitive, and toLowerCase() would misbehave under a Turkish default locale, where AUTHORIZATION lowercases to a dotless ı and the match silently fails open.
  • TowerConnector no longer logs the refresh response body at any level.
  • JwtAuth.toString() truncates unconditionally, matching PlatformId.toString(). trunc0 and the now-unused @Slf4j are gone. This covers all thirteen sites that render a JwtAuth.

www-authenticate is deliberately not redacted: registry challenges carry realm, service and scope, which are needed on the proxy path and were not shown to carry a secret.

Tests

RegHelperTest gains two cases — one pinning the exact dump output including an uppercase PROXY-AUTHORIZATION, one through the io.micronaut.http.HttpRequest overload, which is the path the default-level callers use.

Green: RegHelperTest 27, TowerClientTest 59, TowerClientHttpTest 21, JwtAuthTest 3, JwtAuthStoreTest 2, JwtRefreshParamsTest 1, DenyCrawlerFilterTest 2, DenyPathsFilterTest 5 — 0 failures.

Known follow-up, not in this PR

dumpHeaders is not yet the only door. Four sites render headers into logs without it, two carrying the inbound bearer:

  • RateLimiterFilter.groovy:136 — raw ${request.getHeaders().asMap()} at TRACE
  • ProxyClient.groovy:355-370 — traceResponse is dumpHeaders hand-rewritten
  • TraceSlowEndpointPublisher.java:118-127 — a third copy at DEBUG, opt-in via a property set in no yml
  • TowerConnector.groovy:231 — ${resp} renders ProxyHttpResponse's @ToString over the whole header map and body

RegHelper.isSensitiveHeader(name) is public so routing them through it is a small change. Raising separately to keep this PR to one concern.

Also pre-existing and untouched: RegistryAuthServiceImpl:217 logs full base64 registry credentials at TRACE, and :189 uses the single-arg trunc, which returns an entire first line.

🤖 Generated with Claude Code

RegHelper.dumpHeaders wrote every header value verbatim, so credentials
reached the logs through each of its callers. Redact Authorization,
Proxy-Authorization, Cookie and Set-Cookie at that one point, matching
header names case-insensitively since HTTP header names are.

The Set-Cookie case is the serious one: the Platform token-refresh
response carries the newly minted JWT and refresh token there, and
TowerConnector dumped those headers at TRACE. That same response has an
AccessRefreshToken body holding both tokens again, logged in full at
TRACE and truncated to 500 chars at DEBUG, which is the default level --
so stop logging the refresh body at any level.

JwtAuth.toString rendered the full bearer and refresh token whenever
TRACE was enabled; truncate unconditionally, as PlatformId.toString
already does. That covers all thirteen sites that render a JwtAuth.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@munishchouhan
munishchouhan requested review from a team and pditommaso as code owners November 19, 2026 15:57
@munishchouhan munishchouhan self-assigned this Nov 19, 2026

@pditommaso pditommaso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good: each change cuts down what gets logged, and every dumpHeaders caller is covered by the one function. A few proposed changes:

  1. Use the existing StringUtils.redact for secrets. Wave already has a helper for masking secrets in logs (io.seqera.wave.util.StringUtils.redact, used in Bootstrap, RegistryAuthServiceImpl, RegistryCredentialsFactoryImpl, ContainerRegistryKeys, and others). trunc(value,25) only shortens a string, it doesn't hide it: that's harmless for a JWT, whose first ~20 chars are the standard header, but it would expose most of a short opaque refresh token. See the inline suggestion on JwtAuth.
  2. Optional: dumpHeaders could print StringUtils.redact(val) rather than the [redacted] literal, so header masking matches the rest of the logs, e.g. Authorization=Bea****, which also keeps the scheme visible. [redacted] is fine too, so take or leave it (the test expectations would change accordingly).
  3. Follow-up: PlatformId.toString() has the same trunc(accessToken,25) that JwtAuth now copies. It should use redact too: either a one-line addition here or the follow-up ticket.

Review feedback. trunc shortens a value, it does not hide it: at 25
characters a JWT still shows its header and the start of its payload.
Use StringUtils.redact in JwtAuth.toString, which keeps 3 characters,
and in PlatformId.toString, which had the same 25-character truncation
of the Platform access token.

Also give dumpHeaders' early exit its missing return. That branch was
not merely dead: TowerConnector passes resp.headers, which can be null,
so the fall-through reached a for loop over null and threw inside the
token refresh path.

The new test used /v1alpha3/builds, a route that does not exist on
master; the path is irrelevant to the assertion, so use /v1alpha1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…963]

Review feedback. Print StringUtils.redact(val) rather than a literal, so
header masking matches the rest of the logs and the scheme stays visible
(Authorization=Bea****). Add x-registry-auth to the redacted set: it
carries base64 registry credentials and arrives inbound, as its presence
in RegistryProxyService's cacheable headers shows.

Pin the guarantee in tests: nothing asserted that JwtAuth.toString and
PlatformId.toString hide their tokens, which is how the level-dependent
trunc0 survived unnoticed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@munishchouhan
munishchouhan merged commit 1e69354 into master Nov 19, 2026
9 checks passed
@munishchouhan
munishchouhan deleted the fix/COMP-2963-redact-credentials-in-logs branch November 19, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants