Skip to content

[azure-core] Withhold key/SAS credentials on cross-domain redirect - #49787

Closed
venkatchalla06 wants to merge 1 commit into
Azure:mainfrom
venkatchalla06:azure-core-redirect-credential-cleanup
Closed

venkatchalla06 wants to merge 1 commit into
Azure:mainfrom
venkatchalla06:azure-core-redirect-credential-cleanup

Conversation

@venkatchalla06

Copy link
Copy Markdown

Fixes #49786.

Problem

On a cross-domain HTTP redirect, azure-core strips only the Authorization header family (RedirectPolicy.REDIRECT_HEADERS_BLACKLIST, SensitiveHeaderCleanupPolicy.DEFAULT_SENSITIVE_HEADERS). Because the credential policies re-apply their credential on every send and run downstream of the redirect policy, the credential set by AzureKeyCredentialPolicy (a custom-named header such as api-key / Ocp-Apim-Subscription-Key) and the signature appended by AzureSasCredentialPolicy are transmitted to the redirect-target host. Bearer tokens are already protected (their header is Authorization, which is stripped); this restores the same protection for the other two first-party credential policies.

Fix

Both policies now honor the same insecure_domain_change signal RedirectPolicy already sets and SensitiveHeaderCleanupPolicy already consumes:

  • AzureKeyCredentialPolicy.on_request — on a cross-domain redirect, removes its custom header (the header was set on the pre-redirect request and is not re-added on the redirected send). A simple skip is insufficient because the header set before the redirect persists on the reused request object; SensitiveHeaderCleanupPolicy does not know the custom header name to strip it.
  • AzureSasCredentialPolicy.on_request — on a cross-domain redirect, does not re-append the SAS (the redirected URL has already replaced the pre-redirect query).

Same-domain redirects and normal requests are unaffected.

Tests

Adds test_key_credential_withheld_after_cross_domain_redirect and test_sas_credential_withheld_after_cross_domain_redirect in tests/test_authentication.py, mirroring the existing test_auth_header_stripped_after_cross_domain_redirect* pattern (same MockTransport + pipeline order). Verified locally that the credential is withheld after a cross-domain redirect and still applied on normal requests and same-domain redirects (no over-stripping). black --line-length 120 clean.

Note: this changes authentication-logic in shared azure-core, so it likely warrants the security review called out in AGENTS.md. Opened as a draft per contributor guidance. Happy to adjust the approach — e.g. registering the credential's header name with SensitiveHeaderCleanupPolicy instead of handling it in each credential policy — if maintainers prefer the cleanup to stay centralized.

🤖 Generated with Claude Code

azure-core's redirect credential cleanup only removes the `Authorization`
header family (RedirectPolicy.REDIRECT_HEADERS_BLACKLIST and
SensitiveHeaderCleanupPolicy.DEFAULT_SENSITIVE_HEADERS). Bearer tokens are
therefore protected across a cross-domain redirect, but the credential set by
`AzureKeyCredentialPolicy` (a custom-named header such as `api-key` /
`Ocp-Apim-Subscription-Key`) and the signature appended by
`AzureSasCredentialPolicy` are not, so they are transmitted to the redirect
target host.

Fix: both policies now honor the same `insecure_domain_change` signal
RedirectPolicy sets. On a cross-domain redirect AzureKeyCredentialPolicy removes
its header (and does not re-add it) and AzureSasCredentialPolicy does not
re-append the SAS. Same-domain redirects and normal requests are unaffected.

Adds tests mirroring the existing cross-domain Authorization-stripping test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution venkatchalla06! We will review the pull request and get back to you soon.

@azure-pipelines

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

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 customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azure-core: redirect credential cleanup strips only Authorization; custom-header key credentials and SAS are sent to the redirect target

1 participant