Path: blob/dev/pkg/templates/parser_validate.go
2070 views
package templates12import (3"errors"45"github.com/projectdiscovery/nuclei/v3/pkg/templates/types"6"github.com/projectdiscovery/nuclei/v3/pkg/utils"7"github.com/projectdiscovery/utils/errkit"8)910// validateTemplateMandatoryFields validates the mandatory fields of a template11// return error from this function will cause hard fail and not proceed further12func validateTemplateMandatoryFields(template *Template) error {13info := template.Info1415var validateErrors []error1617if utils.IsBlank(info.Name) {18validateErrors = append(validateErrors, errkit.Newf("mandatory '%s' field is missing", "name"))19}2021if info.Authors.IsEmpty() {22validateErrors = append(validateErrors, errkit.Newf("mandatory '%s' field is missing", "author"))23}2425if template.ID == "" {26validateErrors = append(validateErrors, errkit.Newf("mandatory '%s' field is missing", "id"))27} else if !ReTemplateID.MatchString(template.ID) {28validateErrors = append(validateErrors, errkit.Newf("invalid field format for '%s' (allowed format is %s)", "id", ReTemplateID.String()))29}3031if len(validateErrors) > 0 {32return errors.Join(validateErrors...)33}3435return nil36}3738func isTemplateInfoMetadataMatch(tagFilter *TagFilter, template *Template, extraTags []string) (bool, error) {39match, err := tagFilter.Match(template, extraTags)4041if err == ErrExcluded {42return false, ErrExcluded43}4445return match, err46}4748// validateTemplateOptionalFields validates the optional fields of a template49// return error from this function will throw a warning and proceed further50func validateTemplateOptionalFields(template *Template) error {51info := template.Info5253var warnings []error5455if template.Type() != types.WorkflowProtocol && utils.IsBlank(info.SeverityHolder.Severity.String()) {56warnings = append(warnings, errkit.Newf("field '%s' is missing", "severity"))57}5859if len(warnings) > 0 {60return errors.Join(warnings...)61}6263return nil64}656667