Fix NTLM ProcessTargetInfo returning wrong buffer slice when skipping entries#125201
Fix NTLM ProcessTargetInfo returning wrong buffer slice when skipping entries#125201
Conversation
…erage Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
There was a problem hiding this comment.
Pull request overview
Fixes a managed NTLM bug where ProcessTargetInfo could return the unused tail of a preallocated target-info buffer (all zeros) after skipping certain AV pairs, breaking NTLMv2 verification when servers include TargetName or ChannelBindings entries.
Changes:
- Fix
ProcessTargetInfoto return the written portion of the target-info buffer (AsSpan(0, targetInfoOffset)). - Extend
FakeNtlmServerto optionally emit pre-existingTargetName/ChannelBindingsAV pairs in the challenge TargetInfo. - Add a regression test that exercises combinations of those pre-existing AV pairs and validates successful authentication.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Net.Security/src/System/Net/NegotiateAuthenticationPal.ManagedNtlm.cs | Corrects the returned slice so the produced target-info contains the data actually written. |
| src/libraries/Common/tests/System/Net/Security/FakeNtlmServer.cs | Adds knobs to include dummy pre-existing TargetInfo entries, enabling coverage of the skip/replace path. |
| src/libraries/System.Net.Security/tests/UnitTests/NegotiateAuthenticationTests.cs | Adds regression test to cover the previously-unreachable code path and ensure end-to-end NTLM succeeds. |
|
@Dotnet-s390x build |
|
Build Queued.. To cancel the current build, please comment: |
|
Build Failed Build Error Summary |
|
@copilot There are test failures, can you take a look? |
…UseManagedNtlm Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
Head branch was pushed to by a user without write access
The s390x build failed because Changed the gate to Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
ProcessTargetInfoin managed NTLM returns trailing zeros instead of actual target info data when the server challenge includesTargetNameorChannelBindingsAV pairs (which are skipped and replaced). The early-exit path was correct; the fallback return was off-by-one in the wrong direction.Changes
Bug fix (
NegotiateAuthenticationPal.ManagedNtlm.cs): One-character fix —AsSpan(targetInfoOffset)→AsSpan(0, targetInfoOffset). The old code returned the unused trailing portion of the pre-allocated buffer; the fix returns the written portion.Test infrastructure (
FakeNtlmServer.cs): AddedSendPreExistingTargetNameandSendPreExistingChannelBindingsproperties (defaultfalse). When set, the server challenge includes dummyTargetName/ChannelBindingsAV pairs that the client must skip and replace, forcingtargetInfoOffset < targetInfoBuffer.Lengthand hitting the previously dead code path.Regression test (
NegotiateAuthenticationTests.cs):NtlmWithPreExistingTargetInfoEntriesTest—[ConditionalTheory]gated onUseManagedNtlm, exercises all non-trivial flag combinations(true,false),(false,true),(true,true)and verifies full authentication succeeds. The test is scoped to managed NTLM platforms (Ubuntu 24/26, OpenSUSE 16) because the bug lives in the managed implementation; platforms using the system gss-ntlmssp library may not handle pre-existing AV pairs in the server challenge consistently across versions.Customer Impact
NTLM authentication fails when the server includes
TargetNameorChannelBindingsentries in the challenge's target info. The corrupted target info causes HMAC verification to fail on the server side, breaking authentication entirely for those server configurations.Regression
Not a regression introduced in the most recent release — this is a pre-existing latent bug in the managed NTLM implementation. It was masked because
FakeNtlmServernever emitted those AV pair types in tests.Testing
Full NTLM exchange tested with each combination of pre-existing
TargetName/ChannelBindingsentries in the challenge. All 122 existing unit tests continue to pass.Risk
Low. The fix is a single character change to a slice argument. The affected code path was previously unreachable in tests; the new tests confirm correctness. No protocol logic changed.
Package authoring no longer needed in .NET 9
IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.
Original prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.