Repository navigation
[azure-core] Withhold key/SAS credentials on cross-domain redirect - #49787
Draft
venkatchalla06 wants to merge 1 commit into
Draft
venkatchalla06 wants to merge 1 commit into
venkatchalla06 wants to merge 1 commit into
Conversation
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>
Contributor
|
Thank you for your contribution venkatchalla06! We will review the pull request and get back to you soon. |
Contributor
|
venkatchalla06 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
|
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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #49786.
Problem
On a cross-domain HTTP redirect,
azure-corestrips only theAuthorizationheader 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 byAzureKeyCredentialPolicy(a custom-named header such asapi-key/Ocp-Apim-Subscription-Key) and the signature appended byAzureSasCredentialPolicyare transmitted to the redirect-target host. Bearer tokens are already protected (their header isAuthorization, 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_changesignalRedirectPolicyalready sets andSensitiveHeaderCleanupPolicyalready 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;SensitiveHeaderCleanupPolicydoes 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_redirectandtest_sas_credential_withheld_after_cross_domain_redirectintests/test_authentication.py, mirroring the existingtest_auth_header_stripped_after_cross_domain_redirect*pattern (sameMockTransport+ 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 120clean.🤖 Generated with Claude Code