diff --git a/pkg/catalog/config/template.go b/pkg/catalog/config/template.go index fa90df080c..df0ac345f6 100644 --- a/pkg/catalog/config/template.go +++ b/pkg/catalog/config/template.go @@ -5,6 +5,7 @@ import ( "io" "os" "path/filepath" + "slices" "strings" "github.com/projectdiscovery/nuclei/v3/pkg/templates/extensions" @@ -78,7 +79,7 @@ func IsTemplateWithRoot(fpath, rootDir string) bool { fname := filepath.Base(fpath) fext := strings.ToLower(filepath.Ext(fpath)) - if stringsutil.ContainsAny(fname, GetKnownConfigFiles()...) { + if slices.Contains(GetKnownConfigFiles(), fname) { return false } diff --git a/pkg/catalog/config/template_test.go b/pkg/catalog/config/template_test.go index 1d8c6f1894..1c7d14c426 100644 --- a/pkg/catalog/config/template_test.go +++ b/pkg/catalog/config/template_test.go @@ -89,6 +89,12 @@ func TestIsTemplate(t *testing.T) { rootDir: "", want: false, }, + { + name: "template name containing config filename", + fpath: "http/cves.json.yaml", + rootDir: "", + want: true, + }, } for _, tt := range tests { diff --git a/pkg/catalog/disk/find.go b/pkg/catalog/disk/find.go index 1267309fcc..98b2c01238 100644 --- a/pkg/catalog/disk/find.go +++ b/pkg/catalog/disk/find.go @@ -5,6 +5,7 @@ import ( "io/fs" "os" "path/filepath" + "slices" "strings" "github.com/logrusorgru/aurora/v4" @@ -26,7 +27,7 @@ func (c *DiskCatalog) GetTemplatesPath(definitions []string) ([]string, map[stri erred := make(map[string]error) for _, t := range definitions { - if stringsutil.ContainsAny(t, knownConfigFiles...) { + if isKnownConfigFile(t) { // TODO: this is a temporary fix to avoid treating these files as templates // this should be replaced with more appropriate and robust logic continue @@ -54,7 +55,7 @@ func (c *DiskCatalog) GetTemplatesPath(definitions []string) ([]string, map[stri for _, v := range allTemplates { // TODO: this is a temporary fix to avoid treating these files as templates // this should be replaced with more appropriate and robust logic - if !stringsutil.ContainsAny(v, knownConfigFiles...) { + if !isKnownConfigFile(v) { filteredTemplates = append(filteredTemplates, v) } } @@ -62,6 +63,10 @@ func (c *DiskCatalog) GetTemplatesPath(definitions []string) ([]string, map[stri return filteredTemplates, erred } +func isKnownConfigFile(path string) bool { + return slices.Contains(config.GetKnownConfigFiles(), filepath.Base(path)) +} + // GetTemplatePath parses the specified input template path and returns a compiled // list of finished absolute paths to the templates evaluating any glob patterns // or folders provided as in. diff --git a/pkg/catalog/disk/find_test.go b/pkg/catalog/disk/find_test.go index 408ac76a8e..04b285caa4 100644 --- a/pkg/catalog/disk/find_test.go +++ b/pkg/catalog/disk/find_test.go @@ -1,9 +1,9 @@ package disk import ( - "testing/fstest" "path/filepath" "testing" + "testing/fstest" "github.com/stretchr/testify/require" ) @@ -56,3 +56,16 @@ func TestFindGlobPathMatchesResolvesContainedPath(t *testing.T) { require.NoError(t, err) require.Equal(t, []string{"http/test.yaml"}, matches) } + +func TestGetTemplatesPathAllowsNamesContainingKnownConfigFiles(t *testing.T) { + const templatePath = "http/cves.json.yaml" + catalog := NewFSCatalog(fstest.MapFS{ + templatePath: {Data: []byte("id: test")}, + }, t.TempDir()) + + for _, definitions := range [][]string{{templatePath}, {"http"}} { + templates, errs := catalog.GetTemplatesPath(definitions) + require.Empty(t, errs) + require.Equal(t, []string{templatePath}, templates) + } +} diff --git a/pkg/catalog/disk/known-files.go b/pkg/catalog/disk/known-files.go deleted file mode 100644 index 6660363a12..0000000000 --- a/pkg/catalog/disk/known-files.go +++ /dev/null @@ -1,3 +0,0 @@ -package disk - -var knownConfigFiles = []string{"cves.json", "contributors.json", "TEMPLATES-STATS.json"}