-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NTLM authentication sometimes broken by multiple WWW-Authenticate headers #25291
Comments
I am developing on Win7 using Visual Studio. My ultimate target is a ASP.NET Core application running in Docker hosted on CentOS. I am using .NET Core 2.0. I am reproducing the issue with a unit test running as .NET Core 2.0 application. Here is my csproj
I'm running with Resharper in Visual Studio and can consistently get the issue when using NTLM as the type. On the same machine, I have a CentOS VM running Docker and I'm using the following dockerfile and just issuing a docker image build. I've mapped the directory directly to the VM so I'm sure it is the same code.
The from the teamcity output, I'm seeing a success using the same code that fails in Windows. If I switch the type to Negotiate, I get the opposite results. Linux fails and Windows succeeds. These calls are to the exact same IIS server and service. |
I am working on getting cleared to send the network trace, but I do notice a difference in the failures. After the test receives the Unauthorized HTTP packet: These results are consistently reproduceable. |
Is it ok to send trace traces directly to you? |
I'll have to check if that's okay and get back to you. In the mean time though, I have some questions you might be able to answer without having to worry about disclosure issues. The key question for me is about the client response to the 401.
Unfortunately we're probably seeing two separate issues here, since authentication handling is completely different between Windows and Linux |
|
@dbrownxc is it possible to create a smaller repro on your side from which you can publish the traces (and source)? |
Yes. I'll get one out later today. |
@dbrownxc any update on the repro? Our chances to fix it in 2.1 are slowly going down. Thanks! |
Sorry! It got busy around here.
I make it always fail (hack) so I see the returned output even if the call succeeds. |
@rmkerr can you please take a look? |
Yep! Thanks for getting around to sending out the repro @dbrownxc -- it makes things way more manageable on our end. |
Something definitely looks wrong here. With NTLM credentials set on the client side, and both NTLM and Negotiate enabled on the server side, we don't even attempt to authenticate. GET / HTTP/1.1
Connection: Keep-Alive
Host: localhost HTTP/1.1 401 Unauthorized
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/10.0
WWW-Authenticate: Basic realm="localhost"
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM After the exchange above, the client closes the connection to the server without even attempting to authenticate. If I leave I don't have time to investigate more today, but this looks pretty serious so I'll be back on it tomorrow. |
I was concerned that this issue might lie lower down the stack, or that it was an issue of machine policy blocking NTLM. I've gone ahead and tested it directly with the WinHttp authentication API and I don't see the same result, so that isn't the case. Since the issue does not occur on Linux I expect that the problem is somewhere in our Besides that I haven't made a lot of progress here -- I'm still mostly collecting information to help me track down the issue. |
@rmkerr Do i understand you correctly: There is no issue with dotnet core (wether on linux nor on windows). The problem lies within iis based services like OWA which use WinHttpHandler? |
@rmkerr I'm seeing the mirror error on Linux where NTLM correctly works but Negotiate and Negotiate\NTLM combo never attempts to authenticate. It is completely possible that it is further down the stack, too, but just some extra information. |
@seriouz -- I should have been more clear there. WinHttpHandler is part of .NET. It's the underlying implementation of HttpClientHandler on Windows. I think it is very likely that this is a .NET problem. @dbrownxc Thanks for the info -- I'm not as familiar with our authentication setup on Linux, but I'll take a look. |
I think I've tracked this issue down. Here are the conditions under which it will repro:
In the conditions we see here, the user provides NTLM credentials, but the server supports both NTLM and Negotiate (which is considered more secure). This happens because the code we use to choose the authentication scheme only considers the schemes supported by the server, and not those supported by the client. If the we don't have credentials for the most secure protocol supported by the server, we will fail the authentication attempt. You can see the code that chooses the authentication scheme below. The parameter (1) Our implementation ranks schemes in the following order: Negotiate, NTLM, Digest, Basic |
Great news! |
When choosing what authentication scheme to use, WinHttpHandler picks the most secure scheme supported by the server. When the client does not support this scheme it closes the connection. This fix updates the authentication logic to instead pick the most secure scheme offered by the server that is also supported by the client. This change also adds a test of the relevant behavior. Fixes: #27672
…et#28105) When choosing what authentication scheme to use, WinHttpHandler picks the most secure scheme supported by the server. When the client does not support this scheme it closes the connection. This fix updates the authentication logic to instead pick the most secure scheme offered by the server that is also supported by the client. This change also adds a test of the relevant behavior. Fixes: #27672
@rmkerr Do you have a recommended work around? |
@rmadisonhaynie For now, what we are doing is setting this in configuration. Using the new configuration classes, we just set up a development configuration (appSettings) that works for Windows and a release configuration that works for Linux (environment variable override works here). |
Or you can use 2.1 (currently Preview2) where it is fixed. |
…he PlatformNotSupported file (#27672) Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
…he PlatformNotSupported file (#27672) Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
This issue has been split off from #17545, which turned out to be a problem in the tool being used to observe network traffic. Other users saw similar results, but under different conditions and not caused by the testing tool. That issue will be tracked here to clearly separate the two issues.
The issue tracked here occurs with the following code, targeting .NET Core 2.0:
In Windows, the server receives the following headers, but does not initiate the NTLM handshake:
@dbrownxc, can you provide more information on the situation in which you were able to reproduce this issue? It would be good to have full logs for the unsuccessful authentication attempt.
cc: @seriouz @karelz @davidsh
The text was updated successfully, but these errors were encountered: