{"record":{"id":"5b1b6d1af9386a54","repo":"go-playground/validator","slug":"alias-s-either-contains-restricted-characters-o","errorCode":null,"errorMessage":"Alias '%s' either contains restricted characters or is the same as a restricted tag needed for normal operation","messagePattern":"Alias '(.+?)' either contains restricted characters or is the same as a restricted tag needed for normal operation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"validator_instance.go","lineNumber":244,"sourceCode":"// allowing context.Context validation support.\nfunc (v *Validate) RegisterValidationCtx(tag string, fn FuncCtx, callValidationEvenIfNull ...bool) error {\n\tvar nilCheckable bool\n\tif len(callValidationEvenIfNull) > 0 {\n\t\tnilCheckable = callValidationEvenIfNull[0]\n\t}\n\treturn v.registerValidation(tag, fn, false, nilCheckable)\n}\n\n// RegisterAlias registers a mapping of a single validation tag that\n// defines a common or complex set of validation(s) to simplify adding validation\n// to structs.\n//\n// NOTE: this function is not thread-safe it is intended that these all be registered prior to any validation\nfunc (v *Validate) RegisterAlias(alias, tags string) {\n\t_, ok := restrictedTags[alias]\n\n\tif ok || strings.ContainsAny(alias, restrictedTagChars) {\n\t\tpanic(fmt.Sprintf(restrictedAliasErr, alias))\n\t}\n\n\tv.aliases[alias] = tags\n}\n\n// RegisterStructValidation registers a StructLevelFunc against a number of types.\n//\n// NOTE:\n// - this method is not thread-safe it is intended that these all be registered prior to any validation\nfunc (v *Validate) RegisterStructValidation(fn StructLevelFunc, types ...interface{}) {\n\tv.RegisterStructValidationCtx(wrapStructLevelFunc(fn), types...)\n}\n\n// RegisterStructValidationCtx registers a StructLevelFuncCtx against a number of types and allows passing\n// of contextual validation information via context.Context.\n//\n// NOTE:\n// - this method is not thread-safe it is intended that these all be registered prior to any validation","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/go-playground/validator/blob/facf128d2eecf42bd4ff447adc961aa21bb64aed/validator_instance.go#L226-L262","documentation":"validator_instance.go:244 panics in RegisterAlias when the alias name is either listed in restrictedTags (a baked-in tag name like `required`, `email`) or contains restrictedTagChars (characters such as '-', '=', '.', ',' used as tag grammar). Aliases must be new, safe identifiers because the tag parser would otherwise become ambiguous or break normal tag operation. The panic is fail-fast at registration time, not validation time.","triggerScenarios":"v.RegisterAlias(\"required\", \"min=1\") — overriding a baked-in tag; v.RegisterAlias(\"my-alias\", \"...\") or any alias containing '=', '.', ',', '|', '-' characters; registering an alias whose name collides with any restricted tag in the denylist.","commonSituations":"Choosing kebab-case names for aliases out of habit; attempting to intentionally override built-in behavior via alias (not allowed — use RegisterValidation with bakedIn=false path restrictions similarly); renaming an existing alias to something containing a dash during cleanup; generating alias names programmatically from user input that includes restricted characters.","solutions":["Rename the alias to a restricted-char-free identifier that is not a baked-in tag (e.g. use camelCase or snake_case: myAlias, my_alias).","Check the name against the restrictedTags list in baked_in.go before registering.","Sanitize programmatically generated alias names (strip characters in restrictedTagChars).","If the goal is to change built-in tag behavior, wrap it differently: register your own tag name and use that in tags instead of aliasing the restricted name.","Register aliases at startup before validation so the panic surfaces early."],"exampleFix":"// before\nv.RegisterAlias(\"required\", \"min=1\")      // restricted tag\nv.RegisterAlias(\"is-positive-num\", \"gt=0\") // contains '-'\n\n// after\nv.RegisterAlias(\"isPositiveNum\", \"gt=0\")","handlingStrategy":"validation","validationCode":"func safeRegisterAlias(v *validator.Validate, alias, tags string) (err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"invalid alias %q: %v\", alias, r)\n        }\n    }()\n    v.RegisterAlias(alias, tags)\n    return nil\n}","typeGuard":"var validAliasRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)\n\nfunc isSafeAlias(name string) bool {\n    return validAliasRe.MatchString(name)\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"RegisterAlias rejected %q: %v\", alias, r)\n    }\n}()\nv.RegisterAlias(alias, tags)","preventionTips":["Name aliases with letters, digits, and underscore only — never kebab-case.","Check the proposed name against the restrictedTags denylist in baked_in.go first.","Do all alias registration in package init so conflicts surface at boot.","Never attempt to alias a baked-in tag name; register a new tag name instead."],"tags":["go","validator","alias","panic","restricted-tags"],"backgroundTag":"restricted-tag-name","analyzedSha":"facf128d2eecf42bd4ff447adc961aa21bb64aed","analyzedAt":"2026-09-02T10:19:04.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}