diff --git a/vault/router.go b/vault/router.go index 931a1b5dceb8..e6c36c4c984f 100644 --- a/vault/router.go +++ b/vault/router.go @@ -288,17 +288,19 @@ func (r *Router) RouteExistenceCheck(req *logical.Request) (bool, bool, error) { func (r *Router) routeCommon(req *logical.Request, existenceCheck bool) (*logical.Response, bool, bool, error) { // Find the mount point r.l.RLock() - mount, raw, ok := r.root.LongestPrefix(req.Path) - if !ok { + adjustedPath := req.Path + mount, raw, ok := r.root.LongestPrefix(adjustedPath) + if !ok && !strings.HasSuffix(adjustedPath, "/") { // Re-check for a backend by appending a slash. This lets "foo" mean // "foo/" at the root level which is almost always what we want. - req.Path += "/" - mount, raw, ok = r.root.LongestPrefix(req.Path) + adjustedPath += "/" + mount, raw, ok = r.root.LongestPrefix(adjustedPath) } r.l.RUnlock() if !ok { return logical.ErrorResponse(fmt.Sprintf("no handler for route '%s'", req.Path)), false, false, logical.ErrUnsupportedPath } + req.Path = adjustedPath defer metrics.MeasureSince([]string{"route", string(req.Operation), strings.Replace(mount, "/", "-", -1)}, time.Now()) re := raw.(*routeEntry)