Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/catalog/config/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strings"

"github.com/projectdiscovery/nuclei/v3/pkg/templates/extensions"
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/catalog/config/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions pkg/catalog/disk/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/fs"
"os"
"path/filepath"
"slices"
"strings"

"github.com/logrusorgru/aurora/v4"
Expand All @@ -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
Expand Down Expand Up @@ -54,14 +55,18 @@ 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)
}
}

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.
Expand Down
15 changes: 14 additions & 1 deletion pkg/catalog/disk/find_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package disk

import (
"testing/fstest"
"path/filepath"
"testing"
"testing/fstest"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -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)
}
}
3 changes: 0 additions & 3 deletions pkg/catalog/disk/known-files.go

This file was deleted.

Loading