From 11df6da209dba622bab8f3065d17ea9c71a29e5b Mon Sep 17 00:00:00 2001 From: mzack Date: Fri, 14 Jan 2022 11:20:19 +0100 Subject: [PATCH] Excluding non yaml file from new additions loading --- v2/internal/runner/runner.go | 15 +++++++++++++-- v2/pkg/templates/templates.go | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index ce463730..80fe29db 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -38,6 +38,7 @@ import ( "github.com/projectdiscovery/nuclei/v2/pkg/utils" "github.com/projectdiscovery/nuclei/v2/pkg/utils/stats" yamlwrapper "github.com/projectdiscovery/nuclei/v2/pkg/utils/yaml" + "github.com/projectdiscovery/stringsutil" ) // Runner is a client for running the enumeration process. @@ -452,7 +453,9 @@ func (r *Runner) readNewTemplatesFile() ([]string, error) { if text == "" { continue } - templatesList = append(templatesList, text) + if isNewTemplate(text) { + templatesList = append(templatesList, text) + } } return templatesList, nil } @@ -476,11 +479,19 @@ func (r *Runner) countNewTemplates() int { if text == "" { continue } - count++ + + if isNewTemplate(text) { + count++ + } + } return count } +func isNewTemplate(filename string) bool { + return stringsutil.EqualFoldAny(filepath.Ext(filename), templates.TemplateExtension) +} + // SaveResumeConfig to file func (r *Runner) SaveResumeConfig() error { resumeCfg := types.NewResumeCfg() diff --git a/v2/pkg/templates/templates.go b/v2/pkg/templates/templates.go index ce3bdcaf..2680392b 100644 --- a/v2/pkg/templates/templates.go +++ b/v2/pkg/templates/templates.go @@ -21,6 +21,11 @@ import ( "gopkg.in/yaml.v2" ) +const ( + // TemplateExtension defines the template default file extension + TemplateExtension = ".yaml" +) + // Template is a YAML input file which defines all the requests and // other metadata for a template. type Template struct {