2024-03-13 02:27:15 +01:00
|
|
|
package templates
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/templates/types"
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/utils"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// validateTemplateMandatoryFields validates the mandatory fields of a template
|
|
|
|
|
// return error from this function will cause hard fail and not proceed further
|
|
|
|
|
func validateTemplateMandatoryFields(template *Template) error {
|
|
|
|
|
info := template.Info
|
|
|
|
|
|
|
|
|
|
var validateErrors []error
|
|
|
|
|
|
|
|
|
|
if utils.IsBlank(info.Name) {
|
2025-08-20 05:28:23 +05:30
|
|
|
validateErrors = append(validateErrors, ErrMandatoryFieldMissingFmt("name"))
|
2024-03-13 02:27:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if info.Authors.IsEmpty() {
|
2025-08-20 05:28:23 +05:30
|
|
|
validateErrors = append(validateErrors, ErrMandatoryFieldMissingFmt("author"))
|
2024-03-13 02:27:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if template.ID == "" {
|
2025-08-20 05:28:23 +05:30
|
|
|
validateErrors = append(validateErrors, ErrMandatoryFieldMissingFmt("id"))
|
2024-03-13 02:27:15 +01:00
|
|
|
} else if !ReTemplateID.MatchString(template.ID) {
|
2025-08-20 05:28:23 +05:30
|
|
|
validateErrors = append(validateErrors, ErrInvalidField("id", ReTemplateID.String()))
|
2024-03-13 02:27:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(validateErrors) > 0 {
|
|
|
|
|
return errors.Join(validateErrors...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isTemplateInfoMetadataMatch(tagFilter *TagFilter, template *Template, extraTags []string) (bool, error) {
|
|
|
|
|
match, err := tagFilter.Match(template, extraTags)
|
|
|
|
|
|
|
|
|
|
if err == ErrExcluded {
|
|
|
|
|
return false, ErrExcluded
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return match, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// validateTemplateOptionalFields validates the optional fields of a template
|
|
|
|
|
// return error from this function will throw a warning and proceed further
|
|
|
|
|
func validateTemplateOptionalFields(template *Template) error {
|
|
|
|
|
info := template.Info
|
|
|
|
|
|
|
|
|
|
var warnings []error
|
|
|
|
|
|
|
|
|
|
if template.Type() != types.WorkflowProtocol && utils.IsBlank(info.SeverityHolder.Severity.String()) {
|
2025-08-20 05:28:23 +05:30
|
|
|
warnings = append(warnings, ErrWarningFieldMissing("severity"))
|
2024-03-13 02:27:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(warnings) > 0 {
|
|
|
|
|
return errors.Join(warnings...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|