Skip to content

mod_authn_socache: Make the cache key injective to keep protection spaces apart - #1064

Merged
arturobernalg merged 1 commit into
apache:trunkfrom
arturobernalg:fix/httpd-70332-authn-socache-key
Dec 1, 2026
Merged

arturobernalg merged 1 commit into
apache:trunkfrom
arturobernalg:fix/httpd-70332-authn-socache-key

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

Bug: https://bz.apache.org/bugzilla/show_bug.cgi?id=70332

construct_key() in mod_authn_socache built the socache key by joining the context, provider, auth type, user and realm with a : delimiter. A field that itself contains a : (a client-supplied Digest or form username, or a realm) can shift a field boundary, so two distinct (user, realm) tuples map to the same key. A credential cached for one protection space is then returned for a request in another, so a request can authenticate as a different user. RFC 9110 section 11.5 scopes credentials to their protection space, so the key must be injective.

Fix: join each field with its byte length prefixed.

This is a trunk-only regression: the AuthName/realm was added to the key by #930 and the auth type by #1049. 2.4.x does not put them in the basic/form key and is not affected. #930 was committed by jorton, so a review from the socache maintainers would be welcome.

Test: test/modules/aaa/test_017_authn_socache_dbd_key.py reproduces the cross-realm collision over Digest + mod_authn_dbd (the database keeps user and realm in separate columns, so only the cache key is under test). It fails on trunk (the attack returns 200) and passes with the fix (401); the existing test_016_authn_socache suite still passes.

No CHANGES entry: the regression has not shipped in a release; happy to add one if preferred.

@arturobernalg
arturobernalg force-pushed the fix/httpd-70332-authn-socache-key branch from e0d3ccf to 7d04188 Compare November 24, 2026 08:14

@notroj notroj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a bit cleaner with apr_pstrcatv but that's nitpicking ;) Thanks for doing this.

…aces apart.

construct_key() joined the context, provider, auth type, user and realm
with a ':' delimiter.  A field that itself contains a ':' -- a client
supplied Digest or form username, or a realm -- could shift a field
boundary, so two distinct (user, realm) tuples produced the same cache
key.  A credential cached for one protection space could then be returned
for a request in another, letting a request authenticate as a different
user.  RFC 9110 section 11.5 scopes credentials to their protection space,
so the key must be injective: join each field with its byte length
prefixed.

* modules/aaa/mod_authn_socache.c (construct_key): Length-prefix each
  field when building the key.

* test/modules/aaa/test_019_authn_socache_dbd_key.py: New test for the
  cross-realm collision, using mod_authn_dbd so the backing store keeps
  user and realm apart and only the cache key is under test.

PR: 70332
Reported by: saku0512sec@gmail.com
@arturobernalg
arturobernalg force-pushed the fix/httpd-70332-authn-socache-key branch from 7d04188 to 689f6cf Compare December 1, 2026 08:14
@arturobernalg

Copy link
Copy Markdown
Member Author

Done, switched to apr_pstrcatv() and rebased on trunk (test renamed to test_019, env.py change dropped since trunk already loads dbd/authn_dbd as optional modules; the test now requires them). Thanks!

@notroj notroj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@arturobernalg
arturobernalg merged commit 753762d into apache:trunk Dec 1, 2026
45 of 46 checks passed
arturobernalg added a commit that referenced this pull request Dec 1, 2026
…ction spaces apart (#1142)

mod_authn_socache: Make the cache key injective to keep protection spaces apart.

construct_key() joined the context, user and realm with a ':' delimiter.
A field that itself contains a ':' -- a client supplied Digest or form
username, or a realm -- could shift a field boundary, so two distinct
(user, realm) tuples produced the same cache key.  A credential cached
for one protection space could then be returned for a request in
another, letting a request authenticate as a different user.  RFC 9110
section 11.5 scopes credentials to their protection space, so the key
must be injective: join each field with its byte length prefixed.

* modules/aaa/mod_authn_socache.c (construct_key): Length-prefix each
  field when building the key.

* test/modules/aaa/test_019_authn_socache_dbd_key.py: New test for the
  cross-realm collision, using mod_authn_dbd so the backing store keeps
  user and realm apart and only the cache key is under test.

Backport of trunk 753762d (#1064).  2.4.x does not have the provider
and auth type fields of the trunk key (b3e1ac2, 9c70606), so only
the context, user and realm are length-prefixed.

PR: 70332
Reported by: saku0512sec@gmail.com

(cherry picked from commit 753762d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants