Skip to content

Commit

Permalink
Fix tempalte-id validation (#5261)
Browse files Browse the repository at this point in the history
* Fix tempalte-id validation

* Add checks to mandatory fields

* misc update
  • Loading branch information
RamanaReddy0M authored Jun 15, 2024
1 parent 4720d8c commit 0eddafe
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/websocket"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/whois"
"github.com/projectdiscovery/nuclei/v3/pkg/templates/types"
"github.com/projectdiscovery/nuclei/v3/pkg/utils"
"github.com/projectdiscovery/nuclei/v3/pkg/workflows"
errorutil "github.com/projectdiscovery/utils/errors"
fileutil "github.com/projectdiscovery/utils/file"
Expand Down Expand Up @@ -326,6 +327,17 @@ func (template *Template) UnmarshalYAML(unmarshal func(interface{}) error) error
}
*template = Template(*alias)

if !ReTemplateID.MatchString(template.ID) {
return errorutil.New("template id must match expression %v", ReTemplateID).WithTag("invalid template")
}
info := template.Info
if utils.IsBlank(info.Name) {
return errorutil.New("no template name field provided").WithTag("invalid template")
}
if info.Authors.IsEmpty() {
return errorutil.New("no template author field provided").WithTag("invalid template")
}

if len(template.RequestsHTTP) > 0 || len(template.RequestsNetwork) > 0 {
_ = deprecatedProtocolNameTemplates.Set(template.ID, true)
}
Expand Down

0 comments on commit 0eddafe

Please sign in to comment.