Skip to content

Restart HttpListener authentication when protection policy changes - #136072

Merged
rzikm merged 2 commits into
dotnet:mainfrom
rzikm:rzikm/ntlm-rejection-status-mapping
Oct 20, 2026
Merged

rzikm merged 2 commits into
dotnet:mainfrom
rzikm:rzikm/ntlm-rejection-status-mapping

Conversation

@rzikm

@rzikm rzikm commented Oct 19, 2026

Copy link
Copy Markdown
Member

HttpListener currently returns 400 when its extended-protection selector changes policy between NTLM handshake legs. On Windows Server 2019 (RS5), the old context is discarded and its continuation token is passed to a fresh context, which returns InvalidToken; the managed client-fault mapping then selects 400.

Restart authentication with 401 and a fresh challenge when an in-progress, same-package context becomes policy-incompatible. Detach and dispose the old context rather than reusing its weaker policy. Fresh malformed-token mappings remain unchanged. The existing regression still requires successful Never/Never authentication and unauthenticated strict rejection, and now also requires a bare WWW-Authenticate: NTLM restart challenge.

Validation

  • Baseline: build.cmd clr+libs -rc release passed.
  • dotnet build /t:test src\libraries\System.Net.HttpListener\tests\System.Net.HttpListener.Tests.csproj /p:RuntimeConfiguration=Release passed locally: 688 passed, 0 failed, 8 skipped. The credential-gated regression was skipped locally; malformed NTLM/Negotiate token cases retained their expected 400 responses.
  • NativeAOT build: dotnet build src\libraries\System.Net.HttpListener\tests\System.Net.HttpListener.Tests.csproj /p:TestNativeAot=true /p:RuntimeConfiguration=Release /p:Optimize=true /p:OptimizationPreference=Size passed.
  • On RS5 under SYSTEM, System.Net.HttpListener.Tests.exe -method System.Net.Tests.HttpListenerAuthenticationTests.ExtendedProtectionSelectorDelegate_IncreasesPolicyBetweenNtlmLegs_AuthenticationFails failed before the fix with 400, then passed all 10 post-fix runs with no skips and a successful unchanged-policy control.
  • On RS5, System.Net.HttpListener.Tests.exe -notrait category=OuterLoop -notrait category=failing -xml C:\ntlm\native-after-suite.xml passed: 696 passed, 0 failed, 12 skipped.
  • An additional RS5 CoreCLR control using repository-built networking assemblies on the CI SDK runtime passed 10 relaxed/strict pairs: authenticated 204 / unauthenticated 401 with a fresh NTLM challenge. The detailed context/SSPI trace came from this control, not from instrumented NativeAOT execution.

Resolves #135190

Note

This pull request description and code changes were generated with GitHub Copilot.

Reject continuations from an incompatible in-progress authentication context with a fresh 401 challenge instead of passing them to a new context and returning 400. Preserve malformed-token mappings and require an NTLM restart challenge in the regression test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 783cf1e9-32b8-4d90-83d3-ab0f0644bf74
@azure-pipelines

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

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 783cf1e9-32b8-4d90-83d3-ab0f0644bf74
@rzikm

rzikm commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

/ba-g test failures are unrelated

@rzikm
rzikm merged commit d2f66cb into dotnet:main Oct 20, 2026
86 of 88 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Net.Tests.HttpListenerAuthenticationTests fail with UnexpectedFailure

2 participants