Repository navigation
caddyauth: only replace known placeholders in basic auth credentials - #8017
Conversation
The basic auth provider expanded account usernames and passwords with
repl.ReplaceAll, which blanks any {...} the replacer does not recognize
Credentials are config data, so a username like alice-{bogus} was stored
as alice- and a password like ab{cd}ef was quietly rewritten into
different valid base64, turning a config mistake into a working
password the admin never set
Use ReplaceKnown, matching the respond headers fix in caddyserver#8014 and the
header handler fix in caddyserver#4880, so unknown braces survive and real
placeholders like {env.*} still expand
steadytao
left a comment
There was a problem hiding this comment.
LGTM but please correct the password-impact claim; the example becomes valid base64, not a usable bcrypt hash. It does not demonstrate an unintended working password.
|
good catch, thanks, i corrected the wording in the description, the rewritten value is just base64 that decodes but never works as a hash, so the real problem is silent provisioning and not a working password |
|
Separate from this PR (the order predates it), happy to open an issue for this: I ran this at 2d38ac5 and df77f8b with X=Y=carol. Scope: not an auth bypass. One credential silently stops working. Moving the check below the two Replace lines at 2d38ac5 makes all four collision cases above error, the control still passes, and Disclosure: I used AI assistance to trace and test this. |
|
thanks for testing this so carefully @Santoshkumarpuppala, i checked the order again and you are right, the dup check runs on the raw name before the placeholders expand, so two accounts that only collide after expansion load as one and the second password wins silently, opening an issue for it would be welcome bcs this predates the pr and stays outside its scope |
|
all checks green on the head, ready whenever you have time @steadytao! |
|
thanks for the review and merge @steadytao, happy to contribute to caddy! |
Fixes #8016
Summary
the basic auth provider expanded account usernames and passwords with
repl.ReplaceAll, which blanks any{...}the replacer does not recognize, so a username likealice-{bogus}was provisioned asalice-and a password likeab{cd}efwas quietly rewritten into a different string that still parses as valid base64, so provisioning accepted decoded bytes that are not a usable bcrypt hash and logins simply failedthis switches both to
repl.ReplaceKnown, matching the respond headers fix in #8014 and the header handler fix in #4880 (same class as #4418), so unrecognized braces in credentials are left intact and real placeholders like{env.*}still expandSteps to reproduce
go test ./modules/caddyhttp/caddyauth/ -run TestBasicAuth -count=1{...}in usernames survive as literal data, a braced password is rejected instead of silently rewritten,{env.*}placeholders still expandregression tests in
basicauth_test.gopin all three directions: unknown braces survive, a known placeholder still expands, and a braced password fails provisioning loudly instead of being quietly rewrittenAssistance Disclosure
AI used: yes, for drafting test coverage and description formatting