Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
599b0a0
* modules/aaa/mod_auth_digest.c: Fix stale and misleading comments.
notroj Sep 1, 2026
18ada30
Merge r1937711 from trunk (test changes already on 2.4.x):
notroj Sep 1, 2026
cc5eb40
Merge r1937712 from trunk (test changes already on 2.4.x):
notroj Sep 1, 2026
caa7f24
Merge r1937713 from trunk (test changes already on 2.4.x):
notroj Sep 1, 2026
560e5ef
* modules/aaa/mod_auth_digest.c (note_digest_auth_failure): Drop the
notroj Sep 1, 2026
2beb466
Merge r1937716 from trunk (test changes already on 2.4.x):
notroj Sep 1, 2026
9a70581
Merge r1937888 from trunk (test changes already on 2.4.x):
notroj Sep 4, 2026
39f447e
Merge r1938032 from trunk (test changes already on 2.4.x):
jfclere Sep 9, 2026
dff9f25
mod_auth_digest: Simplify further, moving the client_id counter into the
notroj Oct 11, 2026
f3ecbb6
Merge r1939031 from trunk (test changes already on 2.4.x):
notroj Oct 11, 2026
3e84e51
Merge r1939032 from trunk (test changes already on 2.4.x):
notroj Oct 11, 2026
d4682f7
Merge r1939033 from trunk (test changes already on 2.4.x):
notroj Oct 11, 2026
102d751
Merge r1939034 from trunk (test changes already on 2.4.x; conflicts r…
notroj Oct 11, 2026
c4fd57d
Merge r1939035 from trunk (test changes already on 2.4.x):
notroj Oct 11, 2026
eed7016
Merge r1939036 from trunk (test changes already on 2.4.x):
notroj Oct 11, 2026
229f51e
* modules/aaa/mod_auth_digest.c: Code style tweaks only, no functional
notroj Oct 11, 2026
4c8e9b0
Merge r1939038 from trunk (test changes already on 2.4.x):
notroj Oct 11, 2026
c14ad0b
mod_auth_digest: Bind the nonce lifetime kind into the nonce hash:
notroj Oct 18, 2026
f6cb2f2
mod_auth_digest: Bind a client entry to the user who first used it:
notroj Oct 18, 2026
ffe4050
mod_auth_digest: Challenge a failed nonce-count check as stale:
notroj Oct 18, 2026
81d4a94
mod_auth_digest: Don't force stale=true for an unknown opaque:
notroj Oct 18, 2026
d252a0c
* modules/aaa/mod_auth_digest.c (gen_nonce_hash, gen_nonce): Drop the
notroj Oct 18, 2026
e572ec0
* modules/aaa/mod_auth_digest.c (authenticate_digest_user): Compare the
notroj Oct 18, 2026
cb667ce
mod_auth_digest: Do less while holding client_lock:
notroj Oct 18, 2026
bff636e
mod_auth_digest: Refuse a nonce whose time field does not fully decode:
notroj Oct 19, 2026
0f31f7f
mod_auth_digest: Fold nonce handling functions together, no functiona…
notroj Oct 20, 2026
b1fa3a9
Merge 6354a2826a from trunk (initialize_child changes omitted, 543897…
notroj Oct 28, 2026
3eb827b
* test/modules/aaa: Mark the tests of r1937711, r1937713, r1937888 and
notroj Nov 22, 2026
01b4cf9
Merge remote-tracking branch 'origin/2.4.x' into 2.4.x-digest-p3
notroj Nov 22, 2026
441c44d
* modules/aaa/mod_auth_digest.c (initialize_child): Renumber the AH10635
notroj Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes-entries/digest-authinfo-errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*) mod_auth_digest: With one-time nonces (AuthDigestNonceLifetime 0),
stop needlessly re-challenging a client after an error response.
[Joe Orton]
3 changes: 3 additions & 0 deletions changes-entries/digest-shmem-size.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*) mod_auth_digest: Increase the default AuthDigestShmemSize to 8192
bytes, tracking around 140 clients rather than around 12.
[Joe Orton]
9 changes: 8 additions & 1 deletion docs/manual/mod/mod_auth_digest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ authentication</description>
<description>The amount of shared memory to allocate for keeping track
of clients</description>
<syntax>AuthDigestShmemSize <var>size</var></syntax>
<default>AuthDigestShmemSize 1000</default>
<default>AuthDigestShmemSize 8192</default>
<contextlist><context>server config</context></contextlist>

<usage>
Expand All @@ -254,6 +254,13 @@ of clients</description>
<code>0</code> and read the error message after trying to start the
server.</p>

<p>The default holds roughly 140 clients. A client which is discarded
to make room for another is not denied access: it is issued a new
nonce with <code>stale=true</code>, which costs it one extra request.
Note that a request which does not authenticate also takes an entry,
since the challenge sent back to it carries the identifier the client
is tracked by.</p>

<p>The <var>size</var> is normally expressed in Bytes, but you
may follow the number with a <code>K</code> or an <code>M</code> to
express your value as KBytes or MBytes. For example, the following
Expand Down
1,012 changes: 551 additions & 461 deletions modules/aaa/mod_auth_digest.c

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions test/modules/aaa/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def env(pytestconfig) -> AAATestEnv:
f'AuthUserFile "{pwfile}"',
'AuthDigestDomain "/digest/domain/" "https://mirror.example.org/other/"',
]))
# Tracks clients like "nccheck", but with a domain; a client crossing
# between the two is still the same user (test_015).
conf.add(_digest_dir(docs, "nccheck-domain", [
'AuthDigestProvider file',
f'AuthUserFile "{pwfile}"',
'AuthDigestNcCheck On',
'AuthDigestDomain "/digest/nccheck-domain/"',
]))
conf.add(_digest_dir(docs, "noprovider", [
# AuthDigestProvider intentionally omitted: falls back to "file".
f'AuthUserFile "{pwfile}"',
Expand Down Expand Up @@ -117,6 +125,19 @@ def env(pytestconfig) -> AAATestEnv:
' Require valid-user',
'</Location>',
])
# A second server with the same realm but its own accounts, on its own
# port so that the main server keeps the rest. The main server's
# <Directory> sections apply here too; this one overrides the password
# file for the nccheck location.
conf.add(f'Listen {env.http_port2}')
conf.start_vhost(domains=[f"aaa2.{env.http_tld}"], port=env.http_port2,
doc_root=docs)
conf.add(_digest_dir(docs, "nccheck", [
'AuthDigestProvider file',
f'AuthUserFile "{env.digest_pwfile2}"',
'AuthDigestNcCheck On',
]))
conf.end_vhost()
conf.install()
assert env.apache_restart() == 0
return env
Expand Down
11 changes: 11 additions & 0 deletions test/modules/aaa/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ class AAATestEnv(HttpdTestEnv):
DIGEST_PASSWORD = "digestpass2617"
DIGEST_USER2 = "otheruser"
DIGEST_PASSWORD2 = "otherpass2617"
# DIGEST_USER's password in the second file, for a vhost with its own
# accounts under the same realm.
DIGEST_PASSWORD_VHOST2 = "vhost2pass2617"

def __init__(self, pytestconfig=None):
super().__init__(pytestconfig=pytestconfig)
self.add_httpd_log_modules(["auth_digest", "authn_file", "authz_core"])
self._digest_pwfile = os.path.join(self.server_dir, "digest.passwd")
self._digest_pwfile2 = os.path.join(self.server_dir, "digest2.passwd")

def setup_httpd(self, setup: HttpdTestSetup = None):
super().setup_httpd(setup=AAATestSetup(env=self))
Expand All @@ -46,11 +50,18 @@ def ha1(user, password):
f"{ha1(self.DIGEST_USER, self.DIGEST_PASSWORD)}\n")
fd.write(f"{self.DIGEST_USER2}:{self.REALM}:"
f"{ha1(self.DIGEST_USER2, self.DIGEST_PASSWORD2)}\n")
with open(self._digest_pwfile2, 'w') as fd:
fd.write(f"{self.DIGEST_USER}:{self.REALM}:"
f"{ha1(self.DIGEST_USER, self.DIGEST_PASSWORD_VHOST2)}\n")

@property
def digest_pwfile(self) -> str:
return self._digest_pwfile

@property
def digest_pwfile2(self) -> str:
return self._digest_pwfile2

def configtest(self, directory_lines: List[str], extra_top_lines: Optional[List[str]] = None
) -> ExecResult:
"""Run `httpd -t` against a minimal, standalone config built from the
Expand Down
1 change: 1 addition & 0 deletions test/modules/aaa/htdocs/digest/nccheck-domain/secret.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
digest-nccheck-domain-secret
22 changes: 21 additions & 1 deletion test/modules/aaa/test_001_challenge_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_digest_014_tampered_response_hash(self, env):
assert r.response["status"] == 401
env.httpd_error_log.ignore_recent(lognos=["AH01794"])

@not_backported("r1939034", "rejecting an Authorization uri which fails to unescape")
@not_backported("r1939034", "rejecting an Authorization uri which fails to unescape", backported_in="2.4.72")
def test_digest_015_uri_bad_escaping_rejected(self, env):
# The Authorization uri= is compared against the request-target after
# %-decoding both. A uri= that fails to decode -- an encoded NUL or
Expand All @@ -197,3 +197,23 @@ def test_digest_015_uri_bad_escaping_rejected(self, env):
assert r.response["status"] == 400, \
f"uri={bad_uri!r} was not rejected"
env.httpd_error_log.ignore_recent(lognos=["AH01783"])

def test_digest_016_wrong_password_unknown_opaque_not_stale(self, env):
# A wrong password is wrong whatever opaque the request quotes. An
# opaque this server has no entry for (never issued, or garbage
# collected) used to force stale=true onto the challenge, so the
# client retried silently with the password it had just been told
# was wrong -- once -- before being re-prompted.
challenge = self.challenge(env, location="nccheck")
auth = dc.build_authorization(
AAATestEnv.DIGEST_USER, challenge, "not-the-password",
method="GET", uri="/digest/nccheck/secret.txt",
opaque="deadbeef")
r = env.curl_get(self.url(env, location="nccheck"),
options=["-H", f"Authorization: {auth}"])
assert r.response["status"] == 401
fresh = dc.DigestChallenge.parse(r.response["header"]["www-authenticate"])
assert fresh.stale is False
# ...though the unknown opaque is still replaced by one of ours.
assert fresh.opaque not in (None, "deadbeef")
env.httpd_error_log.ignore_recent(lognos=["AH01794"])
12 changes: 7 additions & 5 deletions test/modules/aaa/test_003_nccheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ def test_digest_032_nccheck_replay_rejected(self, env):
r2 = self.authenticate(env, "nccheck", challenge, nc="00000002")
assert r2.response["status"] == 200

# replay an already-used nc -> rejected, and NOT reported as stale
# (this is a distinct failure mode from an invalid/expired nonce).
# replay an already-used nc -> rejected, and reported as stale: the
# digest verified, so the credentials are good, and a client which
# sent requests out of nonce-count order retries silently on the
# fresh nonce rather than being told its password was wrong.
r3 = self.authenticate(env, "nccheck", challenge, nc="00000001")
assert r3.response["status"] == 401
new_challenge = dc.DigestChallenge.parse(r3.response["header"]["www-authenticate"])
assert new_challenge.stale is False
assert new_challenge.stale is True
env.httpd_error_log.ignore_recent(lognos=["AH01774"])

# recovery: the rejected attempt handed out a fresh challenge for
Expand Down Expand Up @@ -147,7 +149,7 @@ def test_digest_035_out_of_range_opaque_is_not_truncated(self, env):
assert new_challenge.opaque != crafted, \
f"an opaque 2^{bits} above a live client id was truncated onto it"

@not_backported("r1939033", "nonce-count validation")
@not_backported("r1939033", "nonce-count validation", backported_in="2.4.72")
def test_digest_036_malformed_nc_rejected(self, env):
# The nonce-count is 8 hex digits. A value which is not -- a negative
# number, non-hex, or the wrong length -- must be rejected rather
Expand All @@ -159,7 +161,7 @@ def test_digest_036_malformed_nc_rejected(self, env):
assert r.response["status"] == 401, f"nc={bad!r} was accepted"
env.httpd_error_log.ignore_recent(lognos=["AH01782"])

@not_backported("r1939033", "nonce-count validation")
@not_backported("r1939033", "nonce-count validation", backported_in="2.4.72")
def test_digest_037_malformed_nc_does_not_poison_client(self, env):
# A correctly-signed request carrying nc="-0000001" must not be
# accepted: before the count was validated it was read as a huge
Expand Down
4 changes: 2 additions & 2 deletions test/modules/aaa/test_006_config_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def test_digest_067_shmemsize_units_accepted(self, env):
r = env.configtest([], extra_top_lines=["AuthDigestShmemSize 64K"])
assert r.exit_code == 0

@not_backported("r1939036", "AuthDigestShmemSize validation")
@not_backported("r1939036", "AuthDigestShmemSize validation", backported_in="2.4.72")
def test_digest_068_shmemsize_trailing_junk_rejected(self, env):
# Junk after the unit character must be rejected, not silently
# ignored (which read "64Kfoo" as 64K).
r = env.configtest([], extra_top_lines=["AuthDigestShmemSize 64Kfoo"])
assert r.exit_code != 0
assert "AuthDigestShmemSize" in r.stderr

@not_backported("r1939036", "AuthDigestShmemSize validation")
@not_backported("r1939036", "AuthDigestShmemSize validation", backported_in="2.4.72")
def test_digest_069_shmemsize_no_room_for_entry_rejected(self, env):
# A size which would hold the table and an entry by their bare
# struct sizes, but not once the per-allocation rmm overhead is
Expand Down
6 changes: 3 additions & 3 deletions test/modules/aaa/test_007_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
from . import digest_client as dc
from .env import AAATestEnv

# See the note in test_003_nccheck.py: a failed nc check is not reported as
# stale, since it is a distinct failure mode from an invalid/expired nonce.
# A failed nc check is reported as stale (the digest verified, so the
# credentials are good): the client retries silently on the fresh nonce.
NC_FAILED = "AH01774"
NONCE_HASH_INVALID = "AH01776"
PASSWORD_MISMATCH = "AH01794"
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_digest_074_legit_client_recovers_via_fresh_challenge(self, env):
assert r.response["status"] == 401
env.httpd_error_log.ignore_recent(lognos=[NC_FAILED])
fresh = dc.DigestChallenge.parse(r.response["header"]["www-authenticate"])
assert fresh.stale is False
assert fresh.stale is True
assert fresh.opaque == challenge.opaque, \
"the client keeps its identity across a re-challenge"
assert fresh.nonce != challenge.nonce
Expand Down
2 changes: 1 addition & 1 deletion test/modules/aaa/test_009_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
_WIN32 = sys.platform == "win32"

# on the tests that fail without it (the others pass there as well)
NOT_BACKPORTED = not_backported("r1937711", "random client ids after a restart")
NOT_BACKPORTED = not_backported("r1937711", "random client ids after a restart", backported_in="2.4.72")


class TestDigestRestart:
Expand Down
2 changes: 1 addition & 1 deletion test/modules/aaa/test_010_eviction.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
BOTH = ["nccheck", "onetime"]

# on the tests that fail without it (the others pass there as well)
NOT_BACKPORTED = not_backported("r1937713", "evicting never-authenticated clients first")
NOT_BACKPORTED = not_backported("r1937713", "evicting never-authenticated clients first", backported_in="2.4.72")


class TestDigestEviction:
Expand Down
2 changes: 1 addition & 1 deletion test/modules/aaa/test_011_authinfo_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .env import AAATestEnv

# on the tests that fail without it (the others pass there as well)
NOT_BACKPORTED = not_backported("r1937888", "Authentication-Info on error responses")
NOT_BACKPORTED = not_backported("r1937888", "Authentication-Info on error responses", backported_in="2.4.72")


class TestAuthInfoOnError:
Expand Down
2 changes: 1 addition & 1 deletion test/modules/aaa/test_012_errordoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyhttpd.backport import skip_not_backported
from .env import AAATestEnv

pytestmark = skip_not_backported("r1939032", "no Digest record for a request failing header validation")
pytestmark = skip_not_backported("r1939032", "no Digest record for a request failing header validation", backported_in="2.4.72")


class TestDigestErrorDocument:
Expand Down
29 changes: 29 additions & 0 deletions test/modules/aaa/test_012_truncated_nonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,32 @@ def test_digest_012_01(self, env):
assert r2.response["status"] == 401

env.httpd_error_log.ignore_recent(lognos=["AH01782"])

def test_digest_012_02_time_not_base64(self, env):
# A nonce of the right length, ending in the '=' the time field
# must end in, whose time field is not base64 beyond its first
# four characters. The decoder stops there, so the time is only
# partly decoded; the nonce must be refused for that, before the
# partial time is used for anything.
url = env.mkurl("http", "aaa", "/digest/default/secret.txt")
r1 = env.curl_get(url)
assert r1.response["status"] == 401
challenge = dc.DigestChallenge.parse(
r1.response["header"]["www-authenticate"])
eq_pos = challenge.nonce.index("=")
bad_nonce = "AAAA" + "!" * (eq_pos - 4) + challenge.nonce[eq_pos:]
assert len(bad_nonce) == len(challenge.nonce)

auth_header = dc.build_authorization(
AAATestEnv.DIGEST_USER, challenge, AAATestEnv.DIGEST_PASSWORD,
method="GET", uri="/digest/default/secret.txt",
nonce_val=bad_nonce)

r2 = env.curl_get(url, options=['-H', f'Authorization: {auth_header}'])
assert r2.response["status"] == 401
stale = dc.DigestChallenge.parse(r2.response["header"]["www-authenticate"])
assert stale.stale is True

not_base64 = re.compile(r".*AH10678: invalid nonce .* - time is not base64")
assert env.httpd_error_log.scan_recent(not_base64)
env.httpd_error_log.ignore_recent(lognos=["AH10678"])
2 changes: 1 addition & 1 deletion test/modules/aaa/test_013_proxy_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pyhttpd.backport import not_backported
from . import digest_client as dc

pytestmark = not_backported("r1939035", "domain= for reverse-proxied requests")
pytestmark = not_backported("r1939035", "domain= for reverse-proxied requests", backported_in="2.4.72")


class TestDigestProxyDomain:
Expand Down
83 changes: 83 additions & 0 deletions test/modules/aaa/test_014_mixed_lifetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""A realm with both a one-time-nonce location (AuthDigestNonceLifetime 0)
and a timed one, which nothing stops a configuration from having: there is
no directory merge for the directive, so every <Directory> starts from the
defaults.

The time field of a nonce is a timestamp at the timed location and a small
ordinal at the one-time one, and a one-time client records the last nonce
it used by that field. So a *timed* nonce, verified at the one-time
location, used to be recorded as the client's last ordinal -- some 1.7e15,
which the counter will never reach -- after which every genuine one-time
nonce that client was handed was "already used", and the client locked out
until its entry was garbage collected.

The nonce is bound to the opaque, so the timed nonce has to have been
minted for the one-time client's opaque; that just takes quoting the opaque
at the timed location, which issues one when it tracks clients
(AuthDigestNcCheck here). A browser does exactly this by itself: both
locations are one protection space, so it carries its current nonce and
opaque from one to the other. No attacker is needed to hit this, though
anybody with an account on the realm could do it to another client's
opaque.

A nonce now verifies only for the kind of lifetime it was minted under.
"""

from . import digest_client as dc
from .env import AAATestEnv

NONCE_HASH_INVALID = "AH01776"

ONETIME = "onetime"
TIMED = "nccheck"


class TestMixedLifetime:

def url(self, env, location):
return env.mkurl("http", "aaa", f"/digest/{location}/secret.txt")

def challenge(self, env, location):
r = env.curl_get(self.url(env, location))
assert r.response["status"] == 401
return dc.DigestChallenge.parse(r.response["header"]["www-authenticate"])

def header(self, location, challenge):
return dc.build_authorization(
AAATestEnv.DIGEST_USER, challenge, AAATestEnv.DIGEST_PASSWORD,
method="GET", uri=f"/digest/{location}/secret.txt")

def send(self, env, location, auth):
r = env.curl_get(self.url(env, location),
options=["-H", f"Authorization: {auth}"])
return r

def test_digest_140_timed_nonce_does_not_poison_onetime_client(self, env):
# The client is established at the one-time location...
onetime = self.challenge(env, ONETIME)
assert onetime.opaque is not None

# ...and roams to the timed one with that nonce and opaque. The
# nonce is refused (it is not a timed nonce) and the challenge
# carries a timed nonce minted for the same opaque.
r = self.send(env, TIMED, self.header(TIMED, onetime))
assert r.response["status"] == 401
timed = dc.DigestChallenge.parse(r.response["header"]["www-authenticate"])
assert timed.stale is True
assert timed.opaque == onetime.opaque

# Back at the one-time location with the timed nonce: this must
# not verify, since that would record its timestamp as the
# client's last one-time ordinal.
r = self.send(env, ONETIME, self.header(ONETIME, timed))
assert r.response["status"] == 401, \
"a timed nonce was accepted at the one-time location"
fresh = dc.DigestChallenge.parse(r.response["header"]["www-authenticate"])
assert fresh.stale is True
assert fresh.opaque == onetime.opaque

# The client follows the challenge and is not locked out.
r = self.send(env, ONETIME, self.header(ONETIME, fresh))
env.httpd_error_log.ignore_recent(lognos=[NONCE_HASH_INVALID])
assert r.response["status"] == 200, \
"the client's one-time nonce state was poisoned"
Loading
Loading