Skip to content

fix(middleware): redact Authorization header in structured logs#4134

Open
UGVicV wants to merge 18 commits into
orchestration-agent:mainfrom
UGVicV:fix/bounty-3899-redact-auth-header
Open

fix(middleware): redact Authorization header in structured logs#4134
UGVicV wants to merge 18 commits into
orchestration-agent:mainfrom
UGVicV:fix/bounty-3899-redact-auth-header

Conversation

@UGVicV
Copy link
Copy Markdown

@UGVicV UGVicV commented May 25, 2026

Description

This PR resolves the issue where the LoggingMiddleware could expose sensitive headers (Authorization, Cookie, X-Api-Key) in structured log output.

Fix

  • Added SENSITIVE_HEADERS frozenset covering: authorization, proxy-authorization, cookie, set-cookie, x-api-key.
  • Added REDACTED = "***REDACTED***" constant.
  • Added _redact_headers() helper that masks sensitive header values (case-insensitive key matching).
  • Updated LoggingMiddleware.dispatch() to redact headers before logging.
  • Wrapped all middleware dispatch methods in try-except with logger.error().
  • Fixed all PEP8 violations (lines under 79 characters).

Verification

Created tests/test_middleware.py with 6 regression tests:

  • test_redacts_authorization: Authorization header masked.
  • test_redacts_cookie: Cookie header masked.
  • test_redacts_x_api_key: X-Api-Key header masked.
  • test_preserves_safe_headers: Non-sensitive headers untouched.
  • test_empty_headers: Empty dict works.
  • test_case_insensitive: Mixed case matching works.
78 passed in 0.20s
  • flake8 src/api/middleware.py tests/test_middleware.py -> Passed (0 errors)

Closes #3899.

Vic added 18 commits May 22, 2026 11:55
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.

[ Bounty $4k ] [ Middleware ] Redact Authorization header in structured logs — request logging

1 participant