Reject Digest challenges missing realm or nonce (RFC 7616 §3.3)

parse_www_authenticate() accepted any WWW-Authenticate: Digest
challenge that carried at least one auth-param, so a server sending
e.g. Digest qop="auth" with no realm/nonce would make it through.
make_digest_authentication_header() then dereferences auth.at("realm")
and auth.at("nonce") unconditionally, throwing std::out_of_range with
no try/catch on the retry path, which terminates the client process.

Now require both realm and nonce before treating a Digest challenge as
usable, same as if no Digest challenge were present at all.
This commit is contained in:
yhirose committed 2026-08-28 23:36:40 -04:00
1 parent 9185fdb6ae
commit 9ce15a14e5
2 files changed
+44 -3

No files matched your search

+6 -3
View File
@@ -9961,9 +9961,12 @@ inline bool parse_www_authenticate(const Response &res,
auth[std::move(key_part)] = std::move(unquoted);
}
// A challenge with no auth-param can't produce a usable Authorization
// header, so treat it the same as no Digest challenge at all.
return found_digest && !auth.empty();
// RFC 7616 Section 3.3 requires realm and nonce on every Digest challenge;
// make_digest_authentication_header() dereferences both unconditionally, so
// a challenge missing either can't produce a usable Authorization header.
// Treat it the same as no Digest challenge at all.
return found_digest && auth.find("realm") != auth.end() &&
auth.find("nonce") != auth.end();
}
class ContentProviderAdapter {