Skip to content

fix(client): redact credentials from TF_LOG=DEBUG dumps - #751

Merged
tembleking merged 2 commits into
masterfrom
fix/redact-authorization-header-debug-log
Sep 3, 2026
Merged

fix(client): redact credentials from TF_LOG=DEBUG dumps#751
tembleking merged 2 commits into
masterfrom
fix/redact-authorization-header-debug-log

Conversation

@tembleking

Copy link
Copy Markdown
Member

DumpRequestOut/DumpResponse with body=true logged raw HTTP request/response bytes at DEBUG level, including the Authorization bearer token and any secret-bearing JSON/form field (IBM's access_token, apikey, accessKey, apiKey, clientSecret, routingKey, serviceKey, publicToken...). Anyone running with TF_LOG=DEBUG leaked live credentials into their logs.

Redact by pattern instead of hardcoding field names: any header, JSON field, or form value whose name looks like a credential (auth/key/token/secret/password/credential) gets scrubbed, escape-aware so an escaped quote inside a secret can't leak the rest of the string. Also strip the provider's own configured secrets (token, IBM apikey, extra_headers values) as a literal-value fallback for anything the name-based patterns miss.

DumpRequestOut/DumpResponse with body=true dumped the raw Authorization
header and response bodies verbatim into TF_LOG=DEBUG output, leaking
bearer tokens and the customer accessKey returned by GET /api/users/me.
CI jobs running with debug logging (e.g. testacc) surfaced these in
build logs.
…llowlist

The initial fix only matched a fixed allowlist of JSON field names
(accessKey, password, secret, token) and the literal Authorization
header, missing real cases already returned by the API: IBM IAM's
access_token, IBM's apikey sent as x-www-form-urlencoded, and
camelCase/compound secret fields (apiKey, clientSecret, routingKey,
serviceKey, publicToken). It also broke on escaped quotes inside a
secret value, leaking the tail of the string.

Redact by pattern instead:
- any header whose name looks like a credential (auth/key/token/
  secret/password/credential), covering Proxy-Authorization and
  future custom headers from extra_headers
- any JSON field or form-urlencoded value whose name matches the
  same pattern, escape-aware so escaped quotes don't leak
- known configured secrets (token, IBM apikey, extraHeaders values)
  as a literal-value fallback for anything the patterns miss

Adds TestRedactDump covering all of the above.
Copilot AI lite review requested due to automatic review settings September 3, 2026 07:50
@tembleking
tembleking enabled auto-merge (squash) September 3, 2026 07:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The JSON and form-field redaction patterns currently omit the “auth” keyword described in the PR, which can still allow certain credential fields (e.g., auth/authorization) to leak in debug dumps.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens the Sysdig provider’s internal HTTP client debug logging by redacting credentials from httputil.DumpRequestOut / httputil.DumpResponse output, reducing the risk of leaking live secrets when users run with TF_LOG=DEBUG.

Changes:

  • Added regex-based redaction for credential-like headers, JSON fields, and form/query parameters in request/response dumps.
  • Added a “known secrets” literal-value fallback (provider-configured token, IBM API key, and extra_headers values) to scrub secrets even when key names are unexpected.
  • Added unit tests covering several credential formats and escaping behavior.
File summaries
File Description
sysdig/internal/client/v2/client.go Introduces dump redaction helpers and applies them to DEBUG request/response logging.
sysdig/internal/client/v2/client_test.go Adds unit tests validating redaction behavior across headers/JSON/form payloads.
Review details

Suppressed comments (1)

sysdig/internal/client/v2/client.go:55

  • The form/query-string redaction regex also omits the "auth" keyword mentioned in the PR description. This can miss fields like "auth" or "authorization" in x-www-form-urlencoded bodies or URLs and leak credentials in debug dumps.
// sensitiveFormFieldRe redacts the value of any x-www-form-urlencoded (or
// URL query string) field whose name looks like it carries a credential,
// e.g. IBM IAM's "apikey=..." token-exchange request body.
var sensitiveFormFieldRe = regexp.MustCompile(`(?i)(\w*(?:key|token|secret|password|credential)\w*=)[^&\s"]*`)

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sysdig/internal/client/v2/client.go
@tembleking
tembleking merged commit 496ccc0 into master Sep 3, 2026
182 checks passed
@tembleking
tembleking deleted the fix/redact-authorization-header-debug-log branch September 3, 2026 12:16
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.

3 participants