mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 20:15:27 +00:00
* fix: remove undefined errorutil.ShowStackTrace * feat: add make lint support and integrate with test * refactor: migrate errorutil to errkit across codebase - Replace deprecated errorutil with modern errkit - Convert error declarations from var to func for better compatibility - Fix all SA1019 deprecation warnings - Maintain error chain support and stack traces * fix: improve DNS test reliability using Google DNS - Configure test to use Google DNS (8.8.8.8) for stability - Fix nil pointer issue in DNS client initialization - Keep production defaults unchanged * fixing logic * removing unwanted branches in makefile --------- Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
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) {
|
|
validateErrors = append(validateErrors, ErrMandatoryFieldMissingFmt("name"))
|
|
}
|
|
|
|
if info.Authors.IsEmpty() {
|
|
validateErrors = append(validateErrors, ErrMandatoryFieldMissingFmt("author"))
|
|
}
|
|
|
|
if template.ID == "" {
|
|
validateErrors = append(validateErrors, ErrMandatoryFieldMissingFmt("id"))
|
|
} else if !ReTemplateID.MatchString(template.ID) {
|
|
validateErrors = append(validateErrors, ErrInvalidField("id", ReTemplateID.String()))
|
|
}
|
|
|
|
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()) {
|
|
warnings = append(warnings, ErrWarningFieldMissing("severity"))
|
|
}
|
|
|
|
if len(warnings) > 0 {
|
|
return errors.Join(warnings...)
|
|
}
|
|
|
|
return nil
|
|
}
|