@marcel91200 / caddy Mirror · read-only / commits / 3b7bde8f
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, 09:45 UTC

httpcaddyfile: error on duplicate named_routes (#7800)

* fix: error on duplicate named_routes Fixes issue #7798 Validate named route names before inserting them into the named route map. This prevents later definitions from overwriting existing named routes and returns an error when a route name is defined more than once. * test: add test for duplicate named_routes

Rhul committed Jun 5, 2026 at 00:25 UTC 3b7bde8f25122a3a83ae0777e5bdce47f449e47d
2 files changed +21 -1
caddyconfig/httpcaddyfile/httptype.go
+5 -1
@@ -523,7 +523,11 @@ func (ServerType) extractNamedRoutes(
523 route.HandlersRaw = []json.RawMessage{caddyconfig.JSONModuleObject(handler, "handler", subroute.CaddyModule().ID.Name(), h.warnings)}
524 }
525
526 - namedRoutes[sb.block.GetKeysText()[0]] = &route
526 + key := sb.block.GetKeysText()[0]
527 + if _, exists := namedRoutes[key]; exists {
528 + return nil, fmt.Errorf("cannot have duplicate named_routes: %s", key)
529 + }
530 + namedRoutes[key] = &route
531 }
532 options["named_routes"] = namedRoutes
533
caddytest/integration/caddyfile_adapt/duplicate_named_route_challenge.caddyfiletest new
+16
@@ -0,0 +1,16 @@
1 +&(api) {
2 + header X-Version v1
3 + respond "API v1"
4 +}
5 +
6 +&(api) {
7 + header X-Version v2
8 + respond "API v2"
9 +}
10 +
11 +localhost {
12 + invoke api
13 +}
14 +
15 +----------
16 +cannot have duplicate named_routes: api