@@ -64,6 +64,16 @@ func (am *ACMEIssuer) HandleHTTPChallenge(w http.ResponseWriter, r *http.Request
6464 return am .distributedHTTPChallengeSolver (w , r )
6565}
6666
67+ func challengeIdentifierHost (hostport string ) string {
68+ host := hostOnly (hostport )
69+ if inner , ok := strings .CutPrefix (host , "[" ); ok {
70+ if inner , ok := strings .CutSuffix (inner , "]" ); ok {
71+ return inner
72+ }
73+ }
74+ return host
75+ }
76+
6777// distributedHTTPChallengeSolver checks to see if this challenge
6878// request was initiated by this or another instance which uses the
6979// same storage as am does, and attempts to complete the challenge for
@@ -72,7 +82,7 @@ func (am *ACMEIssuer) distributedHTTPChallengeSolver(w http.ResponseWriter, r *h
7282 if am == nil {
7383 return false
7484 }
75- host := hostOnly (r .Host )
85+ host := challengeIdentifierHost (r .Host )
7686 chalInfo , distributed , err := am .config .getACMEChallengeInfo (r .Context (), host , ! am .DisableDistributedSolvers )
7787 if err != nil {
7888 if am .DisableDistributedSolvers {
@@ -178,7 +188,7 @@ func allBase64URL(s string) bool {
178188func solveHTTPChallenge (logger * zap.Logger , w http.ResponseWriter , r * http.Request , challenge acme.Challenge , distributed bool ) bool {
179189 challengeReqPath := challenge .HTTP01ResourcePath ()
180190 if r .URL .Path == challengeReqPath &&
181- strings .EqualFold (hostOnly (r .Host ), challenge .Identifier .Value ) && // mitigate DNS rebinding attacks
191+ strings .EqualFold (challengeIdentifierHost (r .Host ), challenge .Identifier .Value ) && // mitigate DNS rebinding attacks
182192 r .Method == http .MethodGet {
183193 w .Header ().Add ("Content-Type" , "text/plain" )
184194 w .Write ([]byte (challenge .KeyAuthorization ))
@@ -249,7 +259,7 @@ func (iss *ZeroSSLIssuer) distributedHTTPValidationAnswer(w http.ResponseWriter,
249259 if logger == nil {
250260 logger = zap .NewNop ()
251261 }
252- host := hostOnly (r .Host )
262+ host := challengeIdentifierHost (r .Host )
253263 valInfo , distributed , err := iss .getDistributedValidationInfo (r .Context (), host )
254264 if err != nil {
255265 logger .Warn ("looking up info for HTTP validation" ,
0 commit comments