digest: escape control codes too

Since the username is decoded when used and control codes are accepted
in HTTP usernames in general, the username encoding for the Digest auth
needs to percent encode such bytes.

Verified by test 3221

Reported-by: Trail of Bits
Closes #21915
This commit is contained in:
Daniel Stenberg 2026-06-08 23:21:55 +02:00
parent 04afd16076
commit a2b943b115
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 81 additions and 1 deletions

View file

@ -36,6 +36,7 @@
#include "curl_sha512_256.h"
#include "curlx/strparse.h"
#include "rand.h"
#include "escape.h"
#ifndef USE_WINDOWS_SSPI
#define SESSION_ALGO 1 /* for algos with this bit set */
@ -163,6 +164,11 @@ static char *auth_digest_string_quoted(const char *s)
if(!result)
result = curlx_dyn_addn(&out, s, 1);
}
else if((*s < ' ') || (*s > 0x7e)) {
unsigned char buf[3] = { '%' };
Curl_hexbyte(&buf[1], (unsigned char)*s);
result = curlx_dyn_addn(&out, buf, 3);
}
else
result = curlx_dyn_addn(&out, s, 1);
if(result)