libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 07c051dd7e9e61af612e6f960c071d27edebc4ed
parent acef58a0773e894a655599eec44bf320eae1cc53
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 28 Jul 2026 16:58:41 +0200

fail MHD_digest_auth_check_digest2 on MHD_DIGEST_ALG_AUTO

Diffstat:
Msrc/include/microhttpd.h | 5++++-
Msrc/microhttpd/digestauth.c | 23+++++++++++++++++++++--
2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -5922,7 +5922,10 @@ MHD_digest_auth_check (struct MHD_Connection *connection, * @param digest_size number of bytes in @a digest (size must match @a algo!) * @param nonce_timeout The amount of time for a nonce to be * invalid in seconds - * @param algo digest algorithms allowed for verification + * @param algo digest algorithm allowed for verification; exactly one + * algorithm must be named, as @a digest is a hash produced by one + * specific algorithm. #MHD_DIGEST_ALG_AUTO cannot be used here + * and makes this function return #MHD_NO * @return #MHD_YES if authenticated, #MHD_NO if not, * #MHD_INVALID_NONCE if nonce is invalid or stale * @note Available since #MHD_VERSION 0x00096200 diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c @@ -3425,7 +3425,10 @@ MHD_digest_auth_check2 (struct MHD_Connection *connection, * @param digest_size number of bytes in @a digest (size must match @a algo!) * @param nonce_timeout The amount of time for a nonce to be * invalid in seconds - * @param algo digest algorithms allowed for verification + * @param algo digest algorithm allowed for verification; exactly one + * algorithm must be named, as @a digest is a hash produced by one + * specific algorithm. #MHD_DIGEST_ALG_AUTO cannot be used here + * and makes this function return #MHD_NO * @return #MHD_YES if authenticated, #MHD_NO if not, * #MHD_INVALID_NONCE if nonce is invalid or stale * @note Available since #MHD_VERSION 0x00096200 @@ -3445,7 +3448,23 @@ MHD_digest_auth_check_digest2 (struct MHD_Connection *connection, enum MHD_DigestAuthMultiAlgo3 malgo3; if (MHD_DIGEST_ALG_AUTO == algo) - malgo3 = MHD_DIGEST_AUTH_MULT_ALGO3_ANY_NON_SESSION; + { + /* MHD_DIGEST_ALG_AUTO maps to more than one base hashing algorithm, + * but @a digest is a hash of one specific algorithm and its length + * does not identify which one (SHA-256 and SHA-512/256 hashes are + * both 32 bytes). Forwarding AUTO to + * MHD_digest_auth_check_digest3() would therefore reach the + * MHD_PANIC() in that function and kill the process. Report it as + * a failed authentication instead; the caller cannot recover from + * an abort, but it can handle MHD_NO. */ +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + _ ("MHD_DIGEST_ALG_AUTO cannot be used with a " \ + "pre-calculated digest: exactly one algorithm must be " \ + "named, as the digest was produced by one.\n")); +#endif /* HAVE_MESSAGES */ + return MHD_NO; + } else if (MHD_DIGEST_ALG_MD5 == algo) malgo3 = MHD_DIGEST_AUTH_MULT_ALGO3_MD5; else if (MHD_DIGEST_ALG_SHA256 == algo)