{"record":{"id":"e80e940ab44f3d7e","repo":"gofr-dev/gofr","slug":"endpoint-d-w-s-example-api-users-id-0-9","errorCode":null,"errorMessage":"endpoint[%d]: %w: %s. Example: /api/users/{id:[0-9]+} instead of ^/api/users/\\d+$","messagePattern":"endpoint\\[(.+?)\\]: %w: (.+?)\\. Example: /api/users/(.+?) instead of \\^/api/users/\\\\d\\+\\$","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/rbac/config.go","lineNumber":242,"sourceCode":"\t}\n\n\treturn nil\n}\n\n// checkWildcardPattern checks if path contains wildcard pattern.\nfunc (*Config) checkWildcardPattern(path string, index int) error {\n\tif strings.Contains(path, \"/*\") {\n\t\treturn fmt.Errorf(\"endpoint[%d]: %w: %s. Examples: /api/{resource} for single-level or /api/{path:.*} for multi-level\",\n\t\t\tindex, errWildcardPatternNotSupported, path)\n\t}\n\n\treturn nil\n}\n\n// checkRegexPattern checks if path contains old regex pattern.\nfunc (*Config) checkRegexPattern(path string, index int) error {\n\tif strings.HasPrefix(path, \"^\") || strings.HasSuffix(path, \"$\") {\n\t\treturn fmt.Errorf(\"endpoint[%d]: %w: %s. Example: /api/users/{id:[0-9]+} instead of ^/api/users/\\\\d+$\",\n\t\t\tindex, errRegexPatternNotSupported, path)\n\t}\n\n\treturn nil\n}\n\n// checkRegexIndicators checks if path contains regex indicators outside variable constraints.\nfunc (*Config) checkRegexIndicators(path string, index int) error {\n\tif strings.Contains(path, \"\\\\d\") || strings.Contains(path, \"\\\\w\") || strings.Contains(path, \"\\\\s\") {\n\t\t// Only allow if it's inside a variable constraint like {id:[0-9]+}\n\t\tif !strings.Contains(path, \"{\") || !strings.Contains(path, \":\") {\n\t\t\treturn fmt.Errorf(\"endpoint[%d]: %w: %s. Example: /api/users/{id:[0-9]+}\",\n\t\t\t\tindex, errRegexIndicatorNotSupported, path)\n\t\t}\n\t}\n\n\treturn nil\n}","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/rbac/config.go#L224-L260","documentation":"checkRegexPattern rejected a path that looks like an anchored regular expression (starts with ^ or ends with $). RBAC paths must use mux variable syntax, not raw regex, so permission matching stays consistent with routing.","triggerScenarios":"An endpoint path such as ^/api/users/\\d+$ passed to EnableRBAC/LoadPermissions and caught by validate -> validateEndpointPath -> checkRegexPattern.","commonSituations":"Carrying over regex routes from an older config format or another router; converting a regexp-based auth table to this RBAC config verbatim.","solutions":["Strip ^ and $ anchors and rewrite the regex as mux variables.","Convert character-class segments: \\\\d+ becomes {id:[0-9]+} inside braces.","Use {path:.*} for catch-all tails.","Confirm each rewritten path matches the same URLs your regex covered."],"exampleFix":"// before\npath: \"^/api/users/\\\\d+$\"\n// after\npath: \"/api/users/{id:[0-9]+}\"","handlingStrategy":"validation","validationCode":"for i, ep := range endpoints {\n    if strings.HasPrefix(ep.Path, \"^\") || strings.HasSuffix(ep.Path, \"$\") {\n        return fmt.Errorf(\"endpoint[%d] %s: anchored regex not supported; use mux variables like {id:[0-9]+}\", i, ep.Path)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := prevalidateRegexPaths(endpoints); err != nil { return err }\nif _, err := rbac.LoadPermissions(path, logger, metrics, tracer); err != nil {\n    if strings.Contains(err.Error(), \"instead of ^/api\") {\n        return fmt.Errorf(\"rewrite regex paths to mux syntax: %w\", err)\n    }\n    return err\n}","preventionTips":["Ban ^ and $ characters in RBAC paths via a lint rule.","Convert legacy regex routes once, centrally, with a mapping table.","Verify rewritten mux patterns match the same URL set as the old regex (unit tests)."],"tags":["go","rbac","routing","regex","validation"],"backgroundTag":"invalid-route-pattern","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}