Skip to content

Commit 51c67af

Browse files
committed
MINOR: Refine route-acl rules to prevent unintended prefix matches
Since `route-acl` annotated rules take precedence over others, this commit updates its behavior to ensure they do not unintentionally overwrite other rules that share the same prefix. For example, a rule matching the path /api should not inadvertently handle requests to /apiary.
1 parent 1fba224 commit 51c67af

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/route/route.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ func AddCustomRoute(route Route, routeACLAnn string, api api.HAProxyClient) (err
110110
if route.Path.PathTypeMatch == store.PATH_TYPE_EXACT {
111111
routeCond = fmt.Sprintf("%s{ path %s }", routeCond, route.Path.Path)
112112
} else {
113-
routeCond = fmt.Sprintf("%s{ path -m beg %s }", routeCond, route.Path.Path)
113+
if route.Path.Path == "/" {
114+
routeCond = fmt.Sprintf("%s{ path -m beg / }", routeCond)
115+
} else {
116+
path := strings.TrimSuffix(route.Path.Path, "/")
117+
routeCond = fmt.Sprintf("%s{ path -m reg ^%s($|/) }", routeCond, path)
118+
}
114119
}
115120
}
116121
routeCond = fmt.Sprintf("%s { %s } ", routeCond, routeACLAnn)

0 commit comments

Comments
 (0)