fix(client): redact credentials from TF_LOG=DEBUG dumps - #751
Merged
Conversation
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.
tembleking
requested review from
a team,
draraksysdig and
mbarbieri
as code owners
September 3, 2026 07:50
tembleking
enabled auto-merge (squash)
September 3, 2026 07:50
Contributor
There was a problem hiding this comment.
🟡 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_headersvalues) 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.
mateobur
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DumpRequestOut/DumpResponsewith 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.