{"record":{"id":"505cc8185231e727","repo":"gofr-dev/gofr","slug":"regex-pattern-is-not-supported-use-mux-patterns-i","errorCode":null,"errorMessage":"regex pattern is not supported, use mux patterns instead","messagePattern":"regex pattern is not supported, use mux patterns instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/rbac/config.go","lineNumber":34,"sourceCode":"\t\"gofr.dev/pkg/gofr/container\"\n\t\"gofr.dev/pkg/gofr/datasource\"\n)\n\nvar (\n\t// errUnsupportedFormat is returned when the config file format is not supported.\n\terrUnsupportedFormat = errors.New(\"unsupported config file format\")\n\n\t// ErrEndpointMissingPermissions is returned when an endpoint doesn't specify requiredPermissions and is not public.\n\tErrEndpointMissingPermissions = errors.New(\"endpoint must specify requiredPermissions (or be public)\")\n\n\t// errWildcardPatternNotSupported is returned when a wildcard pattern is used.\n\terrWildcardPatternNotSupported = errors.New(\"wildcard pattern '/*' is not supported, use mux patterns instead\")\n\n\t// errRegexPatternNotSupported is returned when an old regex pattern is used.\n\terrRegexPatternNotSupported = errors.New(\"regex pattern '^...$' is not supported, use mux patterns instead\")\n\n\t// errRegexIndicatorNotSupported is returned when regex indicators are used outside variable constraints.\n\terrRegexIndicatorNotSupported = errors.New(\"regex pattern is not supported, use mux patterns instead\")\n)\n\n// RoleDefinition defines a role with its permissions and inheritance.\n// Pure config-based: only role->permission mapping is supported.\ntype RoleDefinition struct {\n\t// Name is the role name (required)\n\tName string `json:\"name\" yaml:\"name\"`\n\n\t// Permissions is a list of permissions for this role (format: \"resource:action\")\n\t// Example: [\"users:read\", \"users:write\"]\n\tPermissions []string `json:\"permissions,omitempty\" yaml:\"permissions,omitempty\"`\n\n\t// InheritsFrom lists roles this role inherits permissions from\n\t// Example: [\"viewer\"] - editor inherits all viewer permissions\n\tInheritsFrom []string `json:\"inheritsFrom,omitempty\" yaml:\"inheritsFrom,omitempty\"`\n}\n\n// EndpointMapping defines authorization requirements for an API endpoint.","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/rbac/config.go#L16-L52","documentation":"errRegexIndicatorNotSupported is returned by checkRegexIndicators when regex syntax characters are used outside variable constraints in an RBAC endpoint pattern (e.g. '[0-9]' or '.*' embedded in a path but not as a declared regex-style variable). GoFr RBAC accepts mux patterns, and regex indicators inside plain path segments are invalid and rejected during validation.","triggerScenarios":"Writing paths like '/files/[a-z]+/download' or '/a.*b' in the RBAC config where the regex syntax appears in the path rather than inside a supported variable constraint; checkRegexIndicators detects it during LoadPermissions.","commonSituations":"Attempting inline regex filtering in RBAC route patterns; partially converting a regex config where anchors were removed but character classes kept; misunderstanding which positions allow regex constraints.","solutions":["Move the regex expression into the mux variable constraint syntax, e.g. '/files/{name:[a-z]+}/download' if constraints are supported, or drop it entirely.","Simplify the pattern to plain path segments and mux variables.","Validate constraints only where the mux supports them; elsewhere use literal paths.","Run a pre-flight scan of your config for '[', ']', '*', '.' indicators before loading."],"exampleFix":"// before\n\"/files/[a-z]+/download\": {\"GET\": [\"user\"]}\n// after\n\"/files/{name}/download\": {\"GET\": [\"user\"]}","handlingStrategy":"validation","validationCode":"var regexIndicators = regexp.MustCompile(`[\\[\\]\\+\\.\\*]`)\nfunc hasRegexIndicatorOutsideVar(pattern string) bool {\n\t// strip {var:constraint} segments, then check the rest\n\tclean := muxVarPattern.ReplaceAllString(pattern, \"\")\n\treturn regexIndicators.MatchString(clean)\n}","typeGuard":null,"tryCatchPattern":"if err := checkRegexIndicators(pattern); err != nil {\n\treturn fmt.Errorf(\"regex indicator in %q not allowed: %w\", pattern, err)\n}","preventionTips":["Keep regex constraints inside supported variable syntax only.","Simplify patterns to literal segments plus {vars}.","Pre-scan configs for '[', '+', '*' outside braces in CI.","Train the team on the mux-pattern-only rule for RBAC routes."],"tags":["rbac","config","routing","gofr"],"backgroundTag":"unsupported-route-pattern","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}