Skip to content

Commit e1655ab

Browse files
[release/5.0] ignore empty domain for digest auth (#50598)
* ignore empty domain for digets auth * style cleanup Co-authored-by: wfurt <[email protected]>
1 parent da22c3d commit e1655ab

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.Authentication.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public abstract class HttpClientHandler_Authentication_Test : HttpClientHandlerT
3333
private async Task CreateAndValidateRequest(HttpClientHandler handler, Uri url, HttpStatusCode expectedStatusCode, ICredentials credentials)
3434
{
3535
handler.Credentials = credentials;
36-
3736
using (HttpClient client = CreateHttpClient(handler))
3837
using (HttpResponseMessage response = await client.GetAsync(url))
3938
{
@@ -94,6 +93,13 @@ public static IEnumerable<object[]> Authentication_SocketsHttpHandler_TestData()
9493
yield return new object[] { $"Digest realm=\"testrealm\", algorithm=sha-256, nonce=\"testnonce\"", true };
9594
yield return new object[] { $"Digest realm=\"testrealm\", algorithm=sha-256-SESS, nonce=\"testnonce\", qop=\"auth\"", true };
9695
}
96+
97+
// Add tests cases for empty values that are not mandatory
98+
if (!IsWinHttpHandler)
99+
{
100+
yield return new object[] { "Digest realm=\"testrealm\",nonce=\"6afd170437eb5144258b308f7c491d96\",opaque=\"\",stale=FALSE,algorithm=MD5,qop=\"auth\"", true };
101+
yield return new object[] { "Digest realm=\"testrealm\", domain=\"\", nonce=\"NA42+vpOFQd1GwCyVRZuhhy+jDn4BMRl\", algorithm=MD5, qop=\"auth\", stale=false", true };
102+
}
97103
}
98104

99105
[Theory]

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.Digest.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal partial class AuthenticationHelper
1818
private const string Qop = "qop";
1919
private const string Auth = "auth";
2020
private const string AuthInt = "auth-int";
21+
private const string Domain = "domain";
2122
private const string Nonce = "nonce";
2223
private const string NC = "nc";
2324
private const string Realm = "realm";
@@ -402,9 +403,13 @@ private unsafe void Parse(string challenge)
402403

403404
// Get the value.
404405
string? value = GetNextValue(challenge, parsedIndex, MustValueBeQuoted(key), out parsedIndex);
406+
if (value == null)
407+
break;
408+
405409
// Ensure value is valid.
406-
if (string.IsNullOrEmpty(value)
407-
&& (value == null || !key.Equals(Opaque, StringComparison.OrdinalIgnoreCase)))
410+
// Opaque and Domain can have empty string
411+
if (value == string.Empty &&
412+
(!key.Equals(Opaque, StringComparison.OrdinalIgnoreCase) && !key.Equals(Domain, StringComparison.OrdinalIgnoreCase)))
408413
break;
409414

410415
// Add the key-value pair to Parameters.

0 commit comments

Comments
 (0)