Fix credential headers on cross-authority redirects - #50224
Open
Arnab Nandy (arnabnandy7) wants to merge 2 commits into
Open
Fix credential headers on cross-authority redirects#50224Arnab Nandy (arnabnandy7) wants to merge 2 commits into
Arnab Nandy (arnabnandy7) wants to merge 2 commits into
Conversation
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
Arnab Nandy (arnabnandy7)
requested review from
a team,
Jonathan Giles (JonathanGiles),
Alan Zimmer (alzimmermsft),
Sameeksha Vaity (samvaity) and
vcolin7
as code owners
August 22, 2026 03:35
Contributor
|
Thank you for your contribution Arnab Nandy (@arnabnandy7)! We will review the pull request and get back to you soon. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 34 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens azure-core redirect handling to prevent key-based credential headers (for KeyCredentialPolicy / AzureKeyCredentialPolicy) from being forwarded or re-applied when an HTTP redirect changes request authority (scheme/host/effective port), while preserving the existing behavior of clearing Authorization on redirects.
Changes:
- Track “sensitive” key-credential header names in the request context along with their originating authority, and strip them when redirect authority changes.
- Update
KeyCredentialPolicyto avoid re-injecting (and actively remove) the key header on cross-authority redirected requests. - Add sync+async tests for cross-authority vs same-authority redirects and for both policy orderings; document the behavior and update the
azure-corechangelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sdk/core/azure-core/src/main/java/com/azure/core/http/policy/RedirectPolicy.java | Track and remove key credential headers on cross-authority redirects; keep removing Authorization. |
| sdk/core/azure-core/src/main/java/com/azure/core/http/policy/KeyCredentialPolicy.java | Gate key header injection on whether the current request authority matches the original authority. |
| sdk/core/azure-core/src/test/java/com/azure/core/http/policy/RedirectPolicyTest.java | Add sync/async coverage for cross-authority clearing and same-authority preservation across policy orderings. |
| sdk/core/azure-core/CHANGELOG.md | Document the redirect hardening behavior as a bug fix. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Description
Fixes credential leakage across cross-authority HTTP redirects in
azure-core.RedirectPolicypreviously removed only theAuthorizationheader. Custom credential headers added byKeyCredentialPolicyorAzureKeyCredentialPolicy, such asapi-key, could be forwarded or reapplied when a redirect changed the request authority.This pull request:
Authorizationon redirects.azure-coreCHANGELOG.Fixes #50215
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines