diff --git a/v2/pkg/templates/compile.go b/v2/pkg/templates/compile.go index 15f498096..1dbfabc56 100644 --- a/v2/pkg/templates/compile.go +++ b/v2/pkg/templates/compile.go @@ -51,13 +51,13 @@ func Parse(filePath string, options protocols.ExecuterOptions) (*Template, error } matchWithTags := false if len(options.Options.Tags) > 0 { - if err := matchTemplateWithTags(types.ToString(templateTags), types.ToString(template.Info["severity"]), options.Options); err != nil { + if err := matchTemplateWithTags(types.ToString(templateTags), types.ToString(template.Info["severity"]), options.Options.Tags); err != nil { return nil, nil } matchWithTags = true } if len(options.Options.ExcludeTags) > 0 && !matchWithTags { - if err := matchTemplateWithTags(types.ToString(templateTags), types.ToString(template.Info["severity"]), options.Options); err == nil { + if err := matchTemplateWithTags(types.ToString(templateTags), types.ToString(template.Info["severity"]), options.Options.ExcludeTags); err == nil { return nil, nil } } @@ -207,7 +207,7 @@ func (t *Template) parseWorkflowTemplate(workflow *workflows.WorkflowTemplate, o } // matchTemplateWithTags matches if the template matches a tag -func matchTemplateWithTags(tags, severity string, options *types.Options) error { +func matchTemplateWithTags(tags, severity string, tagsInput []string) error { actualTags := strings.Split(tags, ",") if severity != "" { actualTags = append(actualTags, severity) // also add severity to tag @@ -215,7 +215,7 @@ func matchTemplateWithTags(tags, severity string, options *types.Options) error matched := false mainLoop: - for _, t := range options.Tags { + for _, t := range tagsInput { commaTags := strings.Split(t, ",") for _, tag := range commaTags { tag = strings.TrimSpace(tag) diff --git a/v2/pkg/templates/compile_test.go b/v2/pkg/templates/compile_test.go index 7eb722794..6ce605f7a 100644 --- a/v2/pkg/templates/compile_test.go +++ b/v2/pkg/templates/compile_test.go @@ -3,40 +3,39 @@ package templates import ( "testing" - "github.com/projectdiscovery/nuclei/v2/pkg/types" "github.com/stretchr/testify/require" ) func TestMatchTemplateWithTags(t *testing.T) { - err := matchTemplateWithTags("php,linux,symfony", "", &types.Options{Tags: []string{"php"}}) + err := matchTemplateWithTags("php,linux,symfony", "", []string{"php"}) require.Nil(t, err, "could not get php tag from input slice") - err = matchTemplateWithTags("lang:php,os:linux,cms:symfony", "", &types.Options{Tags: []string{"cms:symfony"}}) + err = matchTemplateWithTags("lang:php,os:linux,cms:symfony", "", []string{"cms:symfony"}) require.Nil(t, err, "could not get php tag from input key value") - err = matchTemplateWithTags("lang:php,os:linux,symfony", "", &types.Options{Tags: []string{"cms:symfony"}}) + err = matchTemplateWithTags("lang:php,os:linux,symfony", "", []string{"cms:symfony"}) require.NotNil(t, err, "could get key value tag from input key value") - err = matchTemplateWithTags("lang:php,os:linux,cms:jira", "", &types.Options{Tags: []string{"cms:symfony"}}) + err = matchTemplateWithTags("lang:php,os:linux,cms:jira", "", []string{"cms:symfony"}) require.NotNil(t, err, "could get key value tag from input key value") t.Run("space", func(t *testing.T) { - err = matchTemplateWithTags("lang:php, os:linux, cms:symfony", "", &types.Options{Tags: []string{"cms:symfony"}}) + err = matchTemplateWithTags("lang:php, os:linux, cms:symfony", "", []string{"cms:symfony"}) require.Nil(t, err, "could get key value tag from input key value with space") }) t.Run("comma-tags", func(t *testing.T) { - err = matchTemplateWithTags("lang:php,os:linux,cms:symfony", "", &types.Options{Tags: []string{"test,cms:symfony"}}) + err = matchTemplateWithTags("lang:php,os:linux,cms:symfony", "", []string{"test,cms:symfony"}) require.Nil(t, err, "could get key value tag from input key value with comma") }) t.Run("severity", func(t *testing.T) { - err = matchTemplateWithTags("lang:php,os:linux,cms:symfony", "low", &types.Options{Tags: []string{"low"}}) + err = matchTemplateWithTags("lang:php,os:linux,cms:symfony", "low", []string{"low"}) require.Nil(t, err, "could get key value tag for severity") }) t.Run("blank-tags", func(t *testing.T) { - err = matchTemplateWithTags("", "low", &types.Options{Tags: []string{"jira"}}) + err = matchTemplateWithTags("", "low", []string{"jira"}) require.NotNil(t, err, "could get value tag for blank severity") }) }