Apply reserved-header handling on the request-clone path and cover all X-MS-TOKEN- headers#3915
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes reserved-header handling consistent across DownstreamApi request construction and the MicrosoftIdentityMessageHandler request-clone path (used for challenge retries and mTLS PoP). It also broadens the reserved X-MS-TOKEN- prefix so that all X-MS-TOKEN-* headers are treated as reserved (not only X-MS-TOKEN-AAD-*), and adds test coverage for the new behavior.
Changes:
- Broaden reserved-header prefix matching from
X-MS-TOKEN-AAD-toX-MS-TOKEN-inReservedHeaderNames. - Apply reserved-header filtering when cloning outgoing requests in
MicrosoftIdentityMessageHandler.CloneHttpRequestMessageAsync. - Add/extend unit tests to validate reserved-header classification and clone behavior; document the change in the changelog.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Identity.Web.Test/ReservedHeaderCloneTests.cs | Adds unit tests for reserved-header classification and verifies reserved headers are dropped during request cloning. |
| tests/Microsoft.Identity.Web.Test/DownstreamWebApiSupport/DownstreamApiTests.cs | Extends ExtraHeaderParameters reserved-prefix tests to cover non-AAD X-MS-TOKEN-* headers. |
| src/Microsoft.Identity.Web.TokenAcquisition/ReservedHeaderNames.cs | Broadens reserved prefix matching to cover the full X-MS-TOKEN-* family. |
| src/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityMessageHandler.cs | Ensures cloned requests do not carry over reserved headers (consistent with ExtraHeaderParameters handling). |
| changelog.md | Adds a bug-fix entry describing the reserved-header and clone-path behavior change. |
neha-bhargava
approved these changes
Jul 7, 2026
Filter reserved headers when cloning a request for challenge retries and mTLS PoP, consistently with ExtraHeaderParameters. Broaden the reserved X-MS-TOKEN- prefix to cover the whole X-MS-TOKEN-* family. Move the internal ReservedHeaderNames helper to the TokenAcquisition assembly so both the clone path and DownstreamApi share it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
iNinja
force-pushed
the
iinglese/reserved-header-clone-consistency
branch
from
July 10, 2026 13:50
23b6306 to
4756813
Compare
iarekk
approved these changes
Jul 10, 2026
This was referenced Jul 17, 2026
Merged
Closed
Open
Open
Merged
This was referenced Jul 17, 2026
Closed
Closed
Open
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.
Makes reserved-header handling consistent across the DownstreamApi code paths.
MicrosoftIdentityMessageHandlerclones the outgoing request for challenge retries and mTLS PoP. The clone now applies the same reserved-header filter already used forExtraHeaderParameters, so reserved headers are handled the same way on every path.X-MS-TOKEN-prefix to cover the wholeX-MS-TOKEN-*family rather than onlyX-MS-TOKEN-AAD-*.ReservedHeaderNamesmoves toMicrosoft.Identity.Web.TokenAcquisitionso both it and the DownstreamApi layer share a single definition. It stays internal; no public API change.Tests: added coverage for
IsReservedclassification, the clone path (reserved and Authorization headers are not copied, ordinary headers are), and the additionalExtraHeaderParametersprefix cases. Affected suites pass on net8.0.