digest: pass in the user name quoted (as well)

For cases where the user puts a double quote or backspace in the user
name.

Adjusted test 907 to verify

Reported-by: am-perip on hackerone

Closes #20940
This commit is contained in:
Daniel Stenberg 2026-03-16 16:23:49 +01:00
parent 8423cc8e3b
commit 3e8df37885
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 9 additions and 6 deletions

View file

@ -356,6 +356,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
char *spn = NULL;
char *qrealm;
char *qnonce;
char *quserp;
/* Decode the challenge message */
CURLcode result = auth_decode_digest_md5_message(chlg,
@ -469,20 +470,22 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
for(i = 0; i < MD5_DIGEST_LEN; i++)
curl_msnprintf(&resp_hash_hex[2 * i], 3, "%02x", digest[i]);
/* escape double quotes and backslashes in the realm and nonce as
/* escape double quotes and backslashes in the username, realm and nonce as
necessary */
qrealm = auth_digest_string_quoted(realm);
qnonce = auth_digest_string_quoted(nonce);
if(qrealm && qnonce)
quserp = auth_digest_string_quoted(userp);
if(qrealm && qnonce && quserp)
/* Generate the response */
response = curl_maprintf("username=\"%s\",realm=\"%s\",nonce=\"%s\","
"cnonce=\"%s\",nc=\"%s\",digest-uri=\"%s\","
"response=%s,qop=%s",
userp, qrealm, qnonce,
quserp, qrealm, qnonce,
cnonce, nonceCount, spn, resp_hash_hex, qop);
curlx_free(qrealm);
curlx_free(qnonce);
curlx_free(quserp);
curlx_free(spn);
if(!response)
return CURLE_OUT_OF_MEMORY;