Skip to content

Commit 7f273cc

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 7f273cc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.aspell.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mode: commit
22
min_length: 3
33
allowed:
4+
- acl
45
- aspell
56
- repo
67
- yaml

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)