{"record":{"id":"68867811d37c9928","repo":"projectdiscovery/nuclei","slug":"validation-failed-for-these-fields-688678","errorCode":null,"errorMessage":"validation failed for these fields","messagePattern":"validation failed for these fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/utils/yaml/yaml_decode_wrapper.go","lineNumber":171,"sourceCode":"\n// DecodeAndValidate is a wrapper for yaml Decode adding struct validation\nfunc DecodeAndValidate(r io.Reader, v interface{}) error {\n\tif err := NewDecoder(r).Decode(v); err != nil {\n\t\treturn err\n\t}\n\tif validate == nil {\n\t\tvalidate = validator.New()\n\t}\n\n\tif err := validate.Struct(v); err != nil {\n\t\tif _, ok := err.(*validator.InvalidValidationError); ok {\n\t\t\treturn err\n\t\t}\n\t\terrs := []string{}\n\t\tfor _, err := range err.(validator.ValidationErrors) {\n\t\t\terrs = append(errs, err.Namespace()+\": \"+err.Tag())\n\t\t}\n\t\treturn errors.Wrap(errors.New(strings.Join(errs, \", \")), \"validation failed for these fields\")\n\t}\n\treturn nil\n}\n\nfunc normalizeDupMappingKeys(node *yaml.Node) {\n\tnode = unwrapDoc(node)\n\tif node == nil {\n\t\treturn\n\t}\n\n\tswitch node.Kind {\n\tcase yaml.DocumentNode:\n\t\tfor _, child := range node.Content {\n\t\t\tnormalizeDupMappingKeys(child)\n\t\t}\n\tcase yaml.SequenceNode:\n\t\tfor _, child := range node.Content {\n\t\t\tnormalizeDupMappingKeys(child)","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/utils/yaml/yaml_decode_wrapper.go#L153-L189","documentation":"After YAML decoding, the wrapper (pkg/utils/yaml/yaml_decode_wrapper.go:171) runs go-playground/validator's validate.Struct and collects every violation as `Namespace(): Tag()` pairs, wrapped as 'validation failed for these fields'. The YAML parsed successfully; one or more struct `validate` tags (required, oneof, min, etc.) were violated. The namespaces in the message name the exact failing field paths and the tag that failed.","triggerScenarios":"Decoding a template/config struct through the yaml decode wrapper where a required field is empty, an enum (oneof) field holds an out-of-list value, or a numeric min/max/dive constraint fails.","commonSituations":"Templates missing required info fields or with typo'd enum values (e.g. severity); schema drift after upgrading nuclei adds new validate tags to old templates; hand-built config structs decoded with the wrapper.","solutions":["Read the namespace list — each entry names the failing field path and the failed tag","Fix the named field (e.g. set the enum value to one of the allowed choices)","Run `nuclei -validate` to catch violations before scanning","Re-validate existing template sets after nuclei upgrades"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := yaml.DecodeStrict(bytes.NewReader(data), &v); err != nil {\n    var vErrs validator.ValidationErrors\n    if errors.As(err, &vErrs) {\n        for _, fe := range vErrs {\n            log.Printf(\"field %s failed %s\", fe.Namespace(), fe.Tag())\n        }\n    }\n    return err\n}","preventionTips":["Treat the namespace list in the message as the fix list: address each named field","Run nuclei -validate in CI to catch constraint violations pre-scan","After upgrading nuclei, re-validate templates because validate tags evolve"],"tags":["go","nuclei","yaml","validation","templates"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}