Skip to content

Enforce HTTPS for WS-Trust endpoints - #6165

Merged
Logan Dorsey (logdog16) merged 17 commits into
mainfrom
lodorsey/wstrust-https-enforcement
Sep 17, 2026
Merged

Logan Dorsey (logdog16) merged 17 commits into
mainfrom
lodorsey/wstrust-https-enforcement

Conversation

@logdog16

Copy link
Copy Markdown
Member

Changes proposed in this request

  • Harden WS-Trust endpoint validation and redirect handling.
  • Require HTTPS for remotely supplied federation metadata and selected WS-Trust endpoints.
  • Add regression coverage for endpoint selection and rejected insecure requests.

Testing

  • Added unit tests covering federation metadata validation, WS-Trust endpoint selection, redirect handling, and request suppression.
  • Product and unit-test projects build successfully across the affected target frameworks.
  • Focused test execution is blocked locally by an MSTest 4.0.2 adapter/runtime mismatch; CI validation is required.

Performance impact
No expected measurable impact. The additional HTTP client configuration is created only when needed and is pooled for reuse.

Documentation

  • No documentation changes are required.

Reject insecure MEX and WS-Trust endpoints, prevent automatic redirects for credential-bearing WS-Trust requests, and add regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 21, 2026 03:48
@logdog16
Logan Dorsey (logdog16) requested a review from a team as a code owner August 21, 2026 03:48

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

This PR hardens WS-Trust and federation metadata handling by enforcing HTTPS-only endpoints and adding redirect-related protections, along with unit test coverage to prevent regressions in endpoint selection and request behavior.

Changes:

  • Enforces HTTPS for federation metadata URLs and for WS-Trust endpoints selected/used by WS-Trust flows, with explicit non-HTTPS redirect rejection.
  • Introduces redirect-control plumbing (new allowAutoRedirect parameter on IHttpManager.SendRequestAsync, HttpResponse.RequestUri, and an internal IHttpClientFactoryWithRedirectControl) to support disabling auto-redirect for sensitive requests.
  • Adds/extends unit tests for MEX parsing, endpoint selection, and redirect/insecure-endpoint rejection scenarios.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Microsoft.Identity.Test.Unit/RequestsTests/IntegratedWindowsAuthUsernamePasswordTests.cs Adds regression test ensuring injected HTTP WS-Trust endpoints from metadata are rejected before any WS-Trust request is sent.
tests/Microsoft.Identity.Test.Unit/Helpers/ParallelRequestMockHandler.cs Updates test IHttpManager implementation signature to include redirect control.
tests/Microsoft.Identity.Test.Unit/CoreTests/WsTrustTests/WsTrustTests.cs Adds tests for disallowing auto-redirect and rejecting non-HTTPS redirects / HTTP WS-Trust endpoints.
tests/Microsoft.Identity.Test.Unit/CoreTests/WsTrustTests/MexParserTests.cs Adds tests for HTTPS-only endpoint selection and rejecting HTTP MEX endpoints / non-HTTPS redirects; expands input validation coverage.
tests/Microsoft.Identity.Test.Unit/CoreTests/HttpTests/HttpClientFactoryTests.cs Verifies redirect-disabled clients use a separate cached instance from the default pool.
src/client/Microsoft.Identity.Lab.Api/Http/MockHttpManager.cs Propagates allowAutoRedirect through mocks and applies it to the handler used by test HttpClient instances.
src/client/Microsoft.Identity.Client/WsTrust/WsTrustWebRequestManager.cs Adds federation metadata URL validation, HTTPS enforcement, redirect checks, disables auto-redirect for WS-Trust calls, and introduces helpers for HTTPS/redirect detection.
src/client/Microsoft.Identity.Client/WsTrust/MexDocument.cs Filters out non-HTTPS WS-Trust endpoint addresses during MEX parsing.
src/client/Microsoft.Identity.Client/PlatformsCommon/Shared/SimpleHttpClientFactory.cs Adds redirect-controlled pooling for non-mTLS clients and supports redirect control via internal interface.
src/client/Microsoft.Identity.Client/MsalErrorMessage.cs Updates/introduces WS-Trust-specific error messages for HTTPS requirements and redirect rejection.
src/client/Microsoft.Identity.Client/Http/IHttpManager.cs Extends SendRequestAsync contract to include allowAutoRedirect.
src/client/Microsoft.Identity.Client/Http/IHttpClientFactoryWithRedirectControl.cs Adds internal interface for factories that can supply redirect-enabled/disabled clients.
src/client/Microsoft.Identity.Client/Http/HttpResponse.cs Adds RequestUri to help detect final request URI after redirects.
src/client/Microsoft.Identity.Client/Http/HttpManager.cs Threads redirect control through request execution and records RequestUri in HttpResponse.

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

Comment thread src/client/Microsoft.Identity.Client/WsTrust/WsTrustWebRequestManager.cs Outdated
Prevent federation metadata fetches from following redirects before HTTPS validation and assert redirect suppression in regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 21, 2026 04:14

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Comment thread src/client/Microsoft.Identity.Client/Http/HttpManager.cs
Copilot AI review requested due to automatic review settings August 21, 2026 18:05

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 26, 2026 19:33
@logdog16

Copy link
Copy Markdown
Member Author

Bogdan Gavril (@bgavrilMS) / Travis Walker (@trwalke) / Neha Bhargava (@neha-bhargava) can I get a review on this? I've got an active ICM for this bug and need it merged.

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Comment thread src/client/Microsoft.Identity.Client/WsTrust/WsTrustWebRequestManager.cs Outdated
Comment thread src/client/Microsoft.Identity.Client/WsTrust/WsTrustWebRequestManager.cs Outdated
Follow bounded HTTPS redirect chains for federation metadata and WS-Trust requests while rejecting insecure redirect targets before transmission.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 26, 2026 21:10

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

@logdog16
Logan Dorsey (logdog16) enabled auto-merge (squash) August 27, 2026 18:42
Copilot AI review requested due to automatic review settings August 31, 2026 20:14

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

src/client/Microsoft.Identity.Client/WsTrust/WsTrustWebRequestManager.cs:186

  • When MaxRedirects is reached for a WS-Trust request, the loop breaks and the method throws a FederatedServiceReturnedError based on the last 3xx response, which can be misleading. Throwing a dedicated exception when the redirect limit is exceeded would make failures easier to understand.
                if (!TryGetSecureRedirectUri(resp, requestUri, out Uri redirectUri) ||
                    redirectCount >= MaxRedirects)
                {
                    break;
                }

Comment thread src/client/Microsoft.Identity.Client/WsTrust/WsTrustWebRequestManager.cs Outdated
This was referenced Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants