Skip to content

basic auth blanks literal braces in usernames and passwords (unknown placeholders) #8016

Closed

Description

@hktitof

Which area

caddyauth (basic auth)

What happened

the basic auth provider expands account usernames and passwords with repl.ReplaceAll, which blanks any {...} the replacer does not recognize

a config like

basic_auth {
	alice-{bogus} <bcrypt hash>
}

provisions the account as alice- (unknown braces swallowed), and a password value with braces like ab{cd}ef is quietly rewritten to abef, which still parses as valid base64 but is not a usable bcrypt hash, so the config mistake passes provisioning silently and logins just fail instead of the config erroring

respond headers were switched to repl.ReplaceKnown in #8014 and the header handler in #4880 (same class as #4418), so basic auth credentials look like the remaining config-data site still on ReplaceAll

Repro (1 command, go test on master 56e3a88)

go test ./modules/caddyhttp/caddyauth/ -run TestBasicAuth -count=1

raw output on untouched master:

--- FAIL: TestBasicAuthProvisionKeepsUnknownPlaceholdersInUsername (0.00s)
    basicauth_test.go:43: expected an account for the username as configured, got accounts ["alice-"]
--- FAIL: TestBasicAuthProvisionRejectsBracedPasswordInsteadOfRewritingIt (0.00s)
    basicauth_test.go:98: expected provisioning to fail for a password with literal braces, instead it accepted the rewritten password "i\xb7\x9f"
FAIL

expected: unknown {...} in credentials survive as literal config data, real placeholders like {env.*} still expand

Version

master 56e3a88 (post v2.10.2)

Assistance disclosure

AI used: yes, for drafting the test and formatting this report

Activity

  1. thejdubb02 commented on Sep 25, 2026

    @thejdubb02

    Confirmed on current master. HTTPBasicAuth.Provision in modules/caddyhttp/caddyauth/basicauth.go runs repl.ReplaceAll on both acct.Username and acct.Password before anything else happens to them, so any literal { or } the replacer does not recognize gets expanded to empty rather than left alone.

    This is the same bug class already fixed in the header handler (#4880) and in the response headers path (#8014), both of which moved to repl.ReplaceKnown so unrecognized placeholders survive as literal text. Basic auth looks like the one remaining call site still on ReplaceAll.

    Since the account list is parsed once at provision time and stored in a plain map, switching those two lines to repl.ReplaceKnown should carry the same fix here with no behavior change for real placeholders like {env.*}, only for the unrecognized-brace case this issue describes.

    Disclosure: I used AI assistance to trace this call site and draft this comment; the code read and conclusion are my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions