Skip to content

Commit 174fa2d

Browse files
authored
caddyhttp: Evaluate tls.client placeholders more accurately (fix #7530) (#7534)
1 parent cd9e166 commit 174fa2d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

modules/caddyhttp/replacer.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,16 @@ func getReqTLSReplacement(req *http.Request, key string) (any, bool) {
420420
if strings.HasPrefix(field, "client.") {
421421
cert := getTLSPeerCert(req.TLS)
422422
if cert == nil {
423-
return nil, false
423+
// Instead of returning (nil, false) here, we set it to a dummy
424+
// value to fix #7530. This way, even if there is no client cert,
425+
// evaluating placeholders with ReplaceKnown() will still remove
426+
// the placeholder, which would be expected. It is not expected
427+
// for the placeholder to sometimes get removed based on whether
428+
// the client presented a cert. We also do not return true here
429+
// because we probably should remain accurate about whether a
430+
// placeholder is, in fact, known or not.
431+
// (This allocation may be slightly inefficient.)
432+
cert = new(x509.Certificate)
424433
}
425434

426435
// subject alternate names (SANs)

0 commit comments

Comments
 (0)