@marcel91200 / caddy Mirror · read-only / commits / 7ffb640a
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 14:45 UTC

httpcaddyfile: Fix missing TLS connection policies when auto_https is default (#7325) (#7507)

Paulo Henrique committed Feb 21, 2026 at 23:42 UTC 7ffb640a4da666203ab43396eaeb2b6b84bb983f
2 files changed +53 -1
caddyconfig/httpcaddyfile/httptype.go
+1 -1
@@ -822,7 +822,7 @@ func (st *ServerType) serversFromPairings(
822 // https://caddy.community/t/making-sense-of-auto-https-and-why-disabling-it-still-serves-https-instead-of-http/9761
823 createdTLSConnPolicies, ok := sblock.pile["tls.connection_policy"]
824 hasTLSEnabled := (ok && len(createdTLSConnPolicies) > 0) ||
825 - (addr.Host != "" && srv.AutoHTTPS != nil && !slices.Contains(srv.AutoHTTPS.Skip, addr.Host))
825 + (addr.Host != "" && (srv.AutoHTTPS == nil || !slices.Contains(srv.AutoHTTPS.Skip, addr.Host)))
826
827 // we'll need to remember if the address qualifies for auto-HTTPS, so we
828 // can add a TLS conn policy if necessary
caddyconfig/httpcaddyfile/httptype_test.go
+52
@@ -1,9 +1,11 @@
1 package httpcaddyfile
2
3 import (
4 + "encoding/json"
5 "testing"
6
7 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
8 + "github.com/caddyserver/caddy/v2/modules/caddyhttp"
9 )
10
11 func TestMatcherSyntax(t *testing.T) {
@@ -209,3 +211,53 @@ func TestGlobalOptions(t *testing.T) {
211 }
212 }
213 }
214 +
215 +func TestDefaultSNIWithoutHTTPS(t *testing.T) {
216 + caddyfileStr := `{
217 + default_sni my-sni.com
218 + }
219 + example.com {
220 + }`
221 +
222 + adapter := caddyfile.Adapter{
223 + ServerType: ServerType{},
224 + }
225 +
226 + result, _, err := adapter.Adapt([]byte(caddyfileStr), nil)
227 + if err != nil {
228 + t.Fatalf("Failed to adapt Caddyfile: %v", err)
229 + }
230 +
231 + var config struct {
232 + Apps struct {
233 + HTTP struct {
234 + Servers map[string]*caddyhttp.Server `json:"servers"`
235 + } `json:"http"`
236 + } `json:"apps"`
237 + }
238 +
239 + if err := json.Unmarshal(result, &config); err != nil {
240 + t.Fatalf("Failed to unmarshal JSON config: %v", err)
241 + }
242 +
243 + server, ok := config.Apps.HTTP.Servers["srv0"]
244 + if !ok {
245 + t.Fatalf("Expected server 'srv0' to be created")
246 + }
247 +
248 + if len(server.TLSConnPolicies) == 0 {
249 + t.Fatalf("Expected TLS connection policies to be generated, got none")
250 + }
251 +
252 + found := false
253 + for _, policy := range server.TLSConnPolicies {
254 + if policy.DefaultSNI == "my-sni.com" {
255 + found = true
256 + break
257 + }
258 + }
259 +
260 + if !found {
261 + t.Errorf("Expected default_sni 'my-sni.com' in TLS connection policies, but it was missing. Generated JSON: %s", string(result))
262 + }
263 +}