mholt / caddy-l4

Layer 4 (TCP/UDP) app for Caddy
Apache License 2.0
976 stars 75 forks source link

Panic with match tls alpn xmpp-client #259

Open tctlrd opened 1 week ago

tctlrd commented 1 week ago

I have started to get a panic in caddy w/L4 from part of a config for an XMPP server that matches for alpn: xmpp-client. It was working previously, but I updated caddy and now it seems to have broken or changed. I also tried with a json config with no yaml adapter and had the same issue. The panic happens as soon as I visit a page that caddy is serving. Is anyone else experiencing this?

I removed these lines and caddy is fine: https://github.com/snikket-im/snikket-server/blob/f89e01402b9f5d5f63c9c54152531c3755587abd/docs/advanced/reverse_proxy.md?plain=1#L380-L389

routes: 
 - match: 
   - tls:      # match encrypted XMPP traffic 
       alpn: 
       - xmpp-client 
   handle: 
   - handler: proxy 
     upstreams: 
     - dial:   # and send to Snikket's encrypted XMPP port 
       - localhost:5223 

Here is the panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x159e52e]

goroutine 43 [running]:
github.com/mholt/caddy-l4/modules/l4tls.(*MatchALPN).Match(0xc000699d70, 0xc0007a4488)
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/modules/l4tls/alpn_matcher.go:40 +0x2e
github.com/mholt/caddy-l4/modules/l4tls.(*MatchTLS).Match(0xc000745380, 0xc0003387e0)
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/modules/l4tls/matcher.go:115 +0x2ea
github.com/mholt/caddy-l4/layer4.MatcherSet.Match({0xc0007398a0?, 0x596325?, 0xc00069ace8?}, 0xc0003387e0)
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/layer4/matchers.go:53 +0xa3
github.com/mholt/caddy-l4/layer4.(*MatcherSets).AnyMatch(0xc0006336b0, 0xc0003387e0)
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/layer4/matchers.go:88 +0x6f
github.com/mholt/caddy-l4/layer4.(*Server).Provision.RouteList.Compile.func1(0xc0003387e0)
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/layer4/routes.go:156 +0x615
github.com/mholt/caddy-l4/layer4.HandlerFunc.Handle(0x1f83f58?, 0xc00069ace8?)
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/layer4/handlers.go:61 +0x19
github.com/mholt/caddy-l4/layer4.(*Server).handle(0xc000338310, {0x1f83f58, 0xc00069ace8})
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/layer4/server.go:171 +0x191
created by github.com/mholt/caddy-l4/layer4.(*Server).serve in goroutine 35
    github.com/mholt/caddy-l4@v0.0.0-20240912211411-4f012d4517cf/layer4/server.go:89 +0x27c

https://github.com/snikket-im/snikket-server/issues/237#issue-2612766615

vnxme commented 1 week ago

Thanks for reporting. It may be caused by e491c44895fe3f11e24ad4d8c4f6a668144c0ef9, I’ll check.