From dbf094afd84c8f3800f309de201f55a39ea340af Mon Sep 17 00:00:00 2001 From: Kirill Ryabov Date: Mon, 26 May 2025 18:32:46 +0300 Subject: [PATCH] MSP-5358 add checking path with inverted slash in routes methods --- routes/routes.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/routes/routes.go b/routes/routes.go index 0a7907a..bb60c1f 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -2,6 +2,7 @@ package routes import ( "context" + "strings" "github.com/txix-open/isp-kit/cluster" ) @@ -40,10 +41,21 @@ func (s *Routes) ReceiveRoutes(ctx context.Context, routes cluster.RoutingConfig } func (s *Routes) IsInnerEndpoint(path string) bool { - return s.innerEndpoints[path] + return s.innerEndpoints[path] || s.innerEndpoints[invertLeadingSlash(path)] } func (s *Routes) RequiredAdminPermission(path string) (string, bool) { perm, ok := s.requiredPermissions[path] + if !ok { + perm, ok = s.requiredPermissions[invertLeadingSlash(path)] + } return perm, ok } + +func invertLeadingSlash(path string) string { + path, withoutSlash := strings.CutPrefix(path, "/") + if withoutSlash { + return path + } + return "/" + path +}