Repository navigation
DigestAuth does not escape backslash or double quote in the Authorization header #3858
Unanswered
goranai
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
DigestAuthwrites the username and the echoed challenge values (realm, nonce, opaque) into theAuthorizationheader as quoted strings. It does not escape\or"in them.RFC 7616 section 3.4 makes these values quoted-strings. In a quoted-string a backslash starts a quoted-pair (RFC 9110 section 5.6.4). So a Windows domain login like
CORP\aliceis read by an RFC parser asCORPalice. Apachemod_auth_digestreads it that way, and the login fails. A double quote in the username or the realm ends the string early and breaks the header.The realm has the same problem the other way round. The challenge parser removes the escape from
realm="my \"realm\"", and httpx then sends backrealm="my "realm"".Repro
No network needed:
Output on master (7cff5f7):
Expected:
The response hash is already computed from the unescaped values. So once the header is escaped, a strict server reads the same values back and the hash matches.
Other clients
curl, Firefox, Chrome and Internet Explorer 7+ escape these characters. curl has a test for it (test1229). Windows servers first try the escaped form and then retry with a raw backslash ([MS-DPSP] appendix A, note 4). That is why
DOMAIN\useragainst IIS works today. A strict server like Apache fails.Fix
Escaping
\and"inDigestAuth._get_header_valuefor every quoted field fixes both cases. Values without those characters stay byte-for-byte the same. I have a small PR with a test ready and will open it if this is welcome.Environment
Clientshown.AsyncClientuses the same_build_auth_header, and the problem does not depend on the HTTP version.Validated with Claude Opus 5.5.
All reactions