Skip to content

fix: redact sensitive headers in tonic debug logs#3465

Open
rornic wants to merge 2 commits intoopen-telemetry:mainfrom
rornic:redact-sensitive-headers-in-debug-logs
Open

fix: redact sensitive headers in tonic debug logs#3465
rornic wants to merge 2 commits intoopen-telemetry:mainfrom
rornic:redact-sensitive-headers-in-debug-logs

Conversation

@rornic
Copy link
Copy Markdown
Contributor

@rornic rornic commented Apr 19, 2026

Fixes #3367

Changes

Prevents logging of sensitive header values in OTLP tonic exporter by only logging header keys.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.7%. Comparing base (cef3317) to head (b66b3bc).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3465   +/-   ##
=====================================
  Coverage   83.7%   83.7%           
=====================================
  Files        126     126           
  Lines      25386   25386           
=====================================
  Hits       21255   21255           
  Misses      4131    4131           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rornic rornic marked this pull request as ready for review April 19, 2026 10:03
@rornic rornic requested a review from a team as a code owner April 19, 2026 10:03
(k.clone(), v.clone())
}
})
.collect()
Copy link
Copy Markdown
Member

@lalitb lalitb Apr 21, 2026

Choose a reason for hiding this comment

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

Can we also add redact for cookie and set-cookie header, as they do Carry sensitive data. And also make the test coverage better.

@lalitb
Copy link
Copy Markdown
Member

lalitb commented Apr 21, 2026

Add a Changelog entry, as this is user visible fix.


let (headers_from_env, headers_for_logging) = parse_headers_from_env(signal_headers_var);
let (headers_from_env, all_headers) = parse_headers_from_env(signal_headers_var);
let headers_for_logging = redact_sensitive_headers(all_headers);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

stepping back question - do we actually need to include header keys and values in the debug logs at all? If we switch it to just have the header names, won't that be sufficient? (since the value is coming from env variable, operators can query for it anyway, once they know which keys are picked up by the application)..

if we do that, then there is no need of the redaction at all, and it is never possible catch all sensitive headers anyway. (what is sensitive to a user might be required for another user etc.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes this seems reasonable since headers_for_logging is not modified at all before it's logged - so the values must be coming straight from environment.

It was mentioned as an alternative fix in the original issue.

I'll update the PR soon when I get a chance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks!

Copy link
Copy Markdown
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

#3465 (comment) - better to skip logging values, as discussed here.

Adds function that ensures headers that look sensitive are redacted, to be used inside debug logs.

Attempted a parameterised test but `run_env_test` only accepts static strings for env vars.
@rornic rornic force-pushed the redact-sensitive-headers-in-debug-logs branch from b3e755b to eae289f Compare May 3, 2026 13:37
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.

Auth tokens leaked via otel_debug! header logging in OTLP tonic exporter

3 participants