Skip to content

[Cosmos] Harden diagnostics logging redaction (Set-Cookie/auth-challenge headers + error-path URL) - #48827

Open
Anna Tchijova (annatchijova) wants to merge 2 commits into
Azure:mainfrom
annatchijova:cosmos/harden-diagnostics-log-redaction
Open

Anna Tchijova (annatchijova) wants to merge 2 commits into
Azure:mainfrom
annatchijova:cosmos/harden-diagnostics-log-redaction

Conversation

@annatchijova

Copy link
Copy Markdown

What

CosmosHttpLoggingPolicy redacted only a 3-entry denylist (Authorization, ProxyAuthorization, TransferEncoding), logging every other header in the clear when diagnostics logging (enable_diagnostics_logging=True) is on. That re-exposes headers azure-core's HttpLoggingPolicy redacts by default — notably Set-Cookie, Proxy-Authenticate, and WWW-Authenticate, which can carry session material.

Separately, the success path (on_request) logged a query-redacted URL, but the error/exception paths (_log_diagnostics_error, on_exception, _populate_logger_attributes) logged the raw URL, so query-parameter values could be logged.

Changes

  • Add SetCookie, ProxyAuthenticate, WwwAuthenticate to _cosmos_disallow_list (http_constants.py), and note in the comment that deny-by-list is fail-open, so any new sensitive header must be added there.
  • Add a _redact_url helper (_cosmos_http_logging_policy.py) and apply it on the error/exception logging paths, so the URL is redacted consistently with on_request.
  • CHANGELOG entry under Unreleased > Bugs Fixed.
  • Tests covering the header redaction and the error-path URL redaction.

Scope / severity (stated honestly)

Defense-in-depth for diagnostics logging. Credential headers (Authorization for both the master-key HMAC signature and AAD bearer, ProxyAuthorization) were already redacted and remain so; this closes the leakage of cookies / auth-challenge headers and query-parameter values that azure-core redacts by default. Requires opt-in diagnostics logging plus access to the logs; not remotely exploitable.

The deny-by-list design is fail-open by nature (a newly introduced sensitive header would be logged until added to the list). This PR keeps the existing intent (the SDK deliberately logs x-ms-* diagnostics headers) and makes the minimal, mergeable change; a maintainer wanting a stronger posture could switch to an allowlist, which the added comment flags.

…rs + error-path URL)

CosmosHttpLoggingPolicy redacted only a 3-entry denylist (Authorization,
ProxyAuthorization, TransferEncoding), logging every other header in the clear
when diagnostics logging is enabled. That re-exposes headers azure-core's
HttpLoggingPolicy redacts by default -- notably Set-Cookie, Proxy-Authenticate,
and WWW-Authenticate, which can carry session material. Separately, the success
path (on_request) logged a query-redacted URL, but the error and exception paths
(_log_diagnostics_error, on_exception, _populate_logger_attributes) logged the
raw URL, so query-parameter values could be logged.

- Add SetCookie, ProxyAuthenticate, WwwAuthenticate to _cosmos_disallow_list.
- Add a _redact_url helper and apply it on the error/exception logging paths so
  the URL is redacted consistently with on_request.

Deny-by-list logging remains fail-open by design; the comment now states that
any newly added sensitive header must be added to the denylist.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VWmkpCnuhCPKFPD2fexY1a
Copilot AI balanced review requested due to automatic review settings September 1, 2026 14:47
@github-actions github-actions Bot added Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution Anna Tchijova (@annatchijova)! We will review the pull request and get back to you soon.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
6 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

Pull request overview

Hardens Cosmos diagnostics logging against sensitive header and URL query-value exposure.

Changes:

  • Expands sensitive-header redaction.
  • Adds reusable URL redaction across error paths.
  • Adds regression tests and changelog documentation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
CHANGELOG.md Documents logging hardening.
_cosmos_http_logging_policy.py Redacts URLs in several error paths.
http_constants.py Extends the header denylist.
test_cosmos_log_redaction.py Adds redaction regression tests.

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

logger_attributes["activity_id"] = http_request.headers.get(HttpHeaders.ActivityId, "")
logger_attributes["verb"] = http_request.method
logger_attributes["url"] = http_request.url
logger_attributes["url"] = _redact_url(http_request.url)
Comment on lines +499 to +502
# This includes credential/authorization headers and headers that can carry session material
# (cookies, authentication challenges), matching the headers azure-core's HttpLoggingPolicy
# redacts by default. Redaction here is deny-by-list, so any newly added sensitive header must be
# added below to avoid being logged in the clear.
Comment on lines +17 to +18
# These are redacted by azure-core's HttpLoggingPolicy by default and must
# not be logged by the Cosmos policy either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants