Skip to content

security: redact sensitive data in logger decorators + httpclient logging#121

Merged
intel352 merged 2 commits into
mainfrom
sec/clear-text-logging-20260529
May 29, 2026
Merged

security: redact sensitive data in logger decorators + httpclient logging#121
intel352 merged 2 commits into
mainfrom
sec/clear-text-logging-20260529

Conversation

@intel352
Copy link
Copy Markdown
Contributor

Summary

Fixes GitHub CodeQL go/clear-text-logging HIGH-severity alerts in the root modular module.

  • logger_decorator.go: Strengthened sanitizeLogArgs with a broad case-insensitive sensitive-key list (password, passwd, secret, token, authorization, auth, apikey, api_key, accesskey, access_key, credential, cookie, set-cookie, private_key, privatekey, session, bearer). Added isSensitiveKey helper for the matching logic. Applied sanitizeLogArgs in every decorator that forwards raw caller args to a logging sink: DualWriterLoggerDecorator (both inner + secondary), ValueInjectionLoggerDecorator (on combined args, after injection), FilterLoggerDecorator, LevelModifierLoggerDecorator.logWithLevel, and PrefixLoggerDecorator (already had it). BaseLoggerDecorator remains a pure passthrough to preserve the MaskingLogger (logmasker subpackage) contract and avoid double-masking.
  • httpclient/module.go: Added isSensitiveHeader and redactHeaders helpers. Sensitive headers (Authorization, Proxy-Authorization, Cookie, Set-Cookie, X-Api-Key, X-Auth-Token, and any header whose name contains token/secret/password/apikey) have their values replaced with *** before being logged as important_headers. Applied at both the logRequest and logResponse sites.

What changed

File Change
logger_decorator.go Broad sensitiveKeyPatterns list + isSensitiveKey helper; sanitizeLogArgs uses contains-match (case-insensitive); sanitization applied in DualWriter, ValueInjection, Filter, LevelModifier decorators
logger_decorator_test.go TestSanitizeLogArgs_BroadSensitiveKeys (per-key subtests), TestSanitizeLogArgs_NonSensitivePassThrough, TestDecorators_SensitiveArgsAreMasked (per-decorator subtests)
httpclient/module.go sensitiveHeaderPatterns, isSensitiveHeader, redactHeaders helpers; applied at both request and response logging sites
httpclient/logging_improvements_test.go TestSensitiveHeadersRedacted: asserts Authorization/Cookie/Set-Cookie values are masked in logged important_headers

Test plan

  • New security tests written first (TDD); confirmed they fail on unfixed code
  • Implemented fixes; all new tests pass
  • GOWORK=off go test -race ./... (root) — ok
  • cd httpclient && GOWORK=off go test -race ./...ok
  • GOWORK=off go vet ./...clean
  • GOWORK=off golangci-lint run ./... (root + httpclient) — 0 issues
  • gofmt -l on changed files — clean

Notes

  • Residual CodeQL alerts flagging the detailed-logging path (LogHeaders=true/LogBody=true, which dumps raw HTTP via httputil.DumpRequestOut) are out of scope for this PR — those paths intentionally expose full wire content when explicitly enabled by the operator. Those will be triaged separately by the lead.
  • The logmasker subpackage (MaskingLogger) applies its own [REDACTED] strategy before reaching BaseLoggerDecorator, which is why BaseLoggerDecorator remains a pure passthrough — adding sanitization there would cause double-masking and break existing logmasker tests/behavior.

🤖 Generated with Claude Code

…ging

Fixes GitHub CodeQL go/clear-text-logging HIGH alerts:

1. logger_decorator.go — strengthen sanitizeLogArgs with a broad
   case-insensitive sensitive-key list (password, passwd, secret, token,
   authorization, auth, apikey, api_key, accesskey, access_key, credential,
   cookie, set-cookie, private_key, privatekey, session, bearer) via
   isSensitiveKey helper. Apply sanitizeLogArgs in DualWriterLoggerDecorator
   (both inner + secondary), ValueInjectionLoggerDecorator (on combined args),
   FilterLoggerDecorator, LevelModifierLoggerDecorator.logWithLevel, and
   PrefixLoggerDecorator (already had it). BaseLoggerDecorator remains a pure
   passthrough to preserve the MaskingLogger (logmasker) contract.

2. httpclient/module.go — add isSensitiveHeader + redactHeaders helpers that
   replace values of Authorization, Proxy-Authorization, Cookie, Set-Cookie,
   X-Api-Key, X-Auth-Token, and any header containing token/secret/password/
   apikey with "***". Apply redactHeaders at both logRequest (~line 695) and
   logResponse (~line 826) important_headers logging sites.

Tests added in logger_decorator_test.go (TestSanitizeLogArgs_BroadSensitiveKeys,
TestSanitizeLogArgs_NonSensitivePassThrough, TestDecorators_SensitiveArgsAreMasked)
and httpclient/logging_improvements_test.go (TestSensitiveHeadersRedacted).
All existing tests continue to pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 29, 2026

📋 API Contract Changes Summary

No breaking changes detected - only additions and non-breaking modifications

Changed Components:

Core Framework

Contract diff saved to artifacts/diffs/core.json

Module: auth

Contract diff saved to artifacts/diffs/auth.json

Module: cache

Contract diff saved to artifacts/diffs/cache.json

Module: database

Contract diff saved to artifacts/diffs/database.json

Module: eventbus

Contract diff saved to artifacts/diffs/eventbus.json

Module: jsonschema

Contract diff saved to artifacts/diffs/jsonschema.json

Module: letsencrypt

Contract diff saved to artifacts/diffs/letsencrypt.json

Module: reverseproxy

Contract diff saved to artifacts/diffs/reverseproxy.json

Artifacts

📁 Full contract diffs and JSON artifacts are available in the workflow artifacts.

Copy link
Copy Markdown
Contributor

@github-advanced-security github-advanced-security AI left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 92.20779% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
logger_decorator.go 89.47% 4 Missing ⚠️
httpclient/module.go 94.87% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…king

Address adversarial-review findings on the go/clear-text-logging fix:

CRITICAL 1 — httpclient detailed-logging path leaked secrets. When
LogHeaders/LogBody is enabled, logRequest/logResponse logged the raw
httputil dump (Authorization/Cookie/Set-Cookie in clear text) as
"details". Added redactDump(string) which scrubs sensitive header values
in the dump's header section (up to the first blank line) to "***" while
preserving header names, the request/status line, and the body. Applied
to both detailed logRequest and logResponse before logging; truncation
now operates on the already-redacted string.

CRITICAL 2 — over-masking tenantID. "tenant"/"requestid" moved to an
exact-match set (sensitiveKeyExact) so tenantID/tenantName/tenantCount
(primary observability keys) are no longer masked.

IMPORTANT 3+4 — bare auth/token/key substrings over-masked
author/authority/authenticated/token_count/primary_key. Replaced the
broad Contains list with a precise sensitiveKeySubstrings set (password,
passwd, secret, credential, apikey/api_key/api-key, accesskey/access_key,
privatekey/private_key, authorization, cookie, bearer, and explicit
*_token compound forms). Bare auth/token/key removed.

Tests: TestSanitizeLogArgs_SensitiveKeys (precise masks),
TestSanitizeLogArgs_NotMasked (over-masking regression guard:
tenantID/token_count/author/authority/etc.),
TestSensitiveHeadersRedactedInDetailedDump (LogHeaders=true dump
redaction), and updated existing detailed-logging assertion to require
the Authorization secret VALUE be absent while the header NAME remains.

IMPORTANT 5 — residual CodeQL taint through the dump string is expected
post-rescan and will be dismissed by the lead; the runtime leak is now
structurally redacted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@intel352 intel352 merged commit d53e255 into main May 29, 2026
19 of 20 checks passed
@intel352 intel352 deleted the sec/clear-text-logging-20260529 branch May 29, 2026 11:07
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.

2 participants