digest: flush state on origin or credential change

Verified by test 1686

Closes #21944
This commit is contained in:
Daniel Stenberg 2026-06-10 10:27:50 +02:00
parent 3f1055303e
commit 5c6b488035
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 203 additions and 4 deletions

View file

@ -94,6 +94,22 @@ CURLcode Curl_output_digest(struct Curl_easy *data,
#endif
}
else {
bool flush = FALSE;
DEBUGASSERT(data->conn->origin);
if(data->state.digest.origin &&
!Curl_peer_same_destination(data->conn->origin,
data->state.digest.origin))
flush = TRUE;
else if(data->state.digest.creds &&
!Curl_creds_same(data->state.creds, data->state.digest.creds))
flush = TRUE;
if(flush)
/* flush host Digest state */
Curl_auth_digest_cleanup(&data->state.digest);
Curl_peer_link(&data->state.digest.origin, data->conn->origin);
Curl_creds_link(&data->state.digest.creds, data->state.creds);
digest = &data->state.digest;
allocuserpwd = &data->req.hd_auth;
creds = data->state.creds;

View file

@ -148,13 +148,12 @@ typedef CURLcode (Curl_recv)(struct Curl_easy *data, /* transfer */
#ifndef CURL_DISABLE_DIGEST_AUTH
/* Struct used for Digest challenge-response authentication */
struct digestdata {
struct Curl_creds *creds;
struct Curl_peer *origin;
#ifdef USE_WINDOWS_SSPI
BYTE *input_token;
size_t input_token_len;
CtxtHandle *http_context;
/* linked credentials used to make the identity for http_context.
may be NULL. */
struct Curl_creds *creds;
#else
char *nonce;
char *cnonce;

View file

@ -1039,6 +1039,8 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
*/
void Curl_auth_digest_cleanup(struct digestdata *digest)
{
Curl_peer_unlink(&digest->origin);
Curl_creds_unlink(&digest->creds);
curlx_safefree(digest->nonce);
curlx_safefree(digest->cnonce);
curlx_safefree(digest->realm);

View file

@ -630,6 +630,7 @@ void Curl_auth_digest_cleanup(struct digestdata *digest)
/* Free the copy of user/passwd used to make the identity for http_context */
Curl_creds_unlink(&digest->creds);
Curl_peer_unlink(&digest->origin);
}
#endif /* USE_WINDOWS_SSPI && !CURL_DISABLE_DIGEST_AUTH */