Skip to content

fix(proxy): redact sensitive headers in request logs - #2161

Merged
gaius-qi merged 2 commits into
mainfrom
fix-redact-sensitive-request-headers
Nov 18, 2026
Merged

gaius-qi merged 2 commits into
mainfrom
fix-redact-sensitive-request-headers

Conversation

@yxxhero

@yxxhero yxxhero commented Nov 11, 2026

Copy link
Copy Markdown
Member

Description

The dfdaemon proxy Debug-printed the full http::Request at its routing log sites (rule config match, X-Dragonfly-Use-P2P header, direct HTTP/HTTPS proxy, and non-GET bypasses), which leaked the complete authorization, cookie, proxy-authorization, and www-authenticate header values, e.g. authorization: Bearer eyJ..., into the logs.

This PR adds a RedactedRequest Debug wrapper to the existing redaction helpers in dragonfly-client-util:

  • prints method, uri, and version as-is
  • keeps non-sensitive headers intact for request correlation
  • replaces the values of authorization, cookie, proxy-authorization, and www-authenticate with [REDACTED] (case-insensitive match; repeated headers are redacted per value)
  • never prints the body

All request-dumping log sites in dragonfly-client/src/proxy/mod.rs are switched to the wrapper, and the wrapper is covered by unit tests.

Related Issue

N/A (reported directly; main is affected the same way)

Motivation and Context

Bearer tokens (JWTs), session cookies, and proxy credentials were written verbatim to dfdaemon logs at info! level on every proxied request, exposing credentials to anyone with log access.

Screenshots (if appropriate)

N/A

Test plan:

  • cargo fmt --check
  • cargo test -p dragonfly-client-util (102 passed, including 3 new redaction tests)
  • cargo build (full workspace)
  • cargo clippy -p dragonfly-client-util -p dragonfly-client (clean)

The dfdaemon proxy Debug-printed the full http::Request at its routing
log sites (rule config match, X-Dragonfly-Use-P2P header, direct HTTP/HTTPS
proxy, and non-GET bypasses), which leaked the complete authorization,
cookie, proxy-authorization, and www-authenticate header values, e.g.
'authorization: Bearer eyJ...', into the logs.

Add a RedactedRequest Debug wrapper to the existing redaction helpers in
dragonfly-client-util. It prints the method, uri, and version, keeps the
non-sensitive headers for request correlation, and replaces the sensitive
header values with [REDACTED]; the body is never printed. Switch all
Request-dumping log sites in proxy/mod.rs to the wrapper and cover it
with unit tests.

Signed-off-by: yxxhero <aiopsclub@163.com>
@yxxhero
yxxhero requested review from a team as code owners November 11, 2026 00:23
@yxxhero yxxhero added the enhancement New feature or request label Nov 11, 2026
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.01%. Comparing base (0dd88ba) to head (3d65d65).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2161      +/-   ##
==========================================
+ Coverage   65.85%   67.01%   +1.15%     
==========================================
  Files         102      102              
  Lines       31479    32843    +1364     
==========================================
+ Hits        20731    22010    +1279     
- Misses      10748    10833      +85     
Files with missing lines Coverage Δ
dragonfly-client-util/src/types/redacted.rs 100.00% <100.00%> (ø)
dragonfly-client/src/proxy/mod.rs 37.95% <ø> (-0.05%) ⬇️

... and 19 files with indirect coverage changes

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

BraveY
BraveY previously approved these changes Nov 11, 2026

@BraveY BraveY 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.

LGTM

Rename `RedactedRequest` to `RedactedHTTPProxyRequest` and switch its
header output from a deny-list (redacting authorization, cookie, etc.)
to an allow-list that prints only `range`, `user-agent`, `host` and
`x-request-id`. This keeps the per-request log line small and ensures
any unexpected sensitive header never reaches the logs.

Generalize `KeyRequestHeader` over any `(K, V)` iterable so the same
filter serves both `HeaderMap` and `HashMap` headers, drop the now
unused sensitive-header helpers, and update tests and proxy call sites
accordingly.

Signed-off-by: Gaius <gaius.qi@gmail.com>

@gaius-qi gaius-qi left a comment

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.

LGTM

@chlins chlins left a comment

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.

lgtm

@gaius-qi
gaius-qi merged commit 348b4cf into main Nov 18, 2026
7 checks passed
@gaius-qi
gaius-qi deleted the fix-redact-sensitive-request-headers branch November 18, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants