Skip to content

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

Open
arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/httpd-70332-authn-socache-key
Open

arturobernalg wants to merge 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.

…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_017_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.
  test/modules/aaa/env.py (AAATestSetup): Load mod_authn_dbd and mod_dbd.

PR: 70332
Reported by: saku0512sec@gmail.com
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.

1 participant