#8037·caddy

caddyauth: basic_auth accepts duplicate usernames that only collide after {env.*} expansion

Author: SantoshkumarpuppalaCreated Sep 19, 2026Updated Sep 19, 2026
Labelsbug :lady_beetle:help wanted :sos:

Issue Details

Follow-up from #8017, where @hktitof suggested a separate issue because this predates that PR.

Provision checks hba.Accounts[acct.Username] for duplicates at modules/caddyhttp/caddyauth/basicauth.go:105-106, before the username is expanded at :109-110, and :129 stores the expanded name. So two accounts whose usernames only become equal after {env.*} expansion load as one account, and only the second password works.

Run at master df77f8bd with X=Y=carol and Z=dave, using two bcrypt hashes for different passwords:

  • carol + carol: error account 1: username is not unique: carol (control).
  • {env.X} + {env.Y}, carol + {env.Y}, and {env.X} + {env.X}: no error, one account, and only the second password authenticates.
  • {env.X} + {env.Z}: two accounts, and both passwords work (control).

With a binary built from df77f8bd, caddy validate rejects literal duplicates and {$VU1}/{$VU2} duplicates, which are expanded at adapt time, but reports Valid configuration for {env.VU1}/{env.VU2}.

This is not an auth bypass: one configured credential silently stops working. Moving the check below the two replace lines makes all four collision cases error, keeps the control passing, and go test ./modules/caddyhttp/caddyauth/ -count=1 passes (run at 2d38ac51, the #8017 head). The error would then print the expanded username. Happy to send that as a PR with a test for the four cases.

Assistance Disclosure

AI used

If AI was used, describe the extent to which it was used.

An AI assistant traced the code path and wrote and ran the reproduction probe; I reviewed the results and the wording before filing.