From 75e931f17e35cb7ed4bd2afc29964a470a46908f Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Mon, 19 Jan 2026 16:12:25 +0700 Subject: [PATCH 1/2] test(templates): adds `Test_ParseWorkflowWithGlobalMatchers` test Signed-off-by: Dwi Siswanto --- pkg/templates/compile_test.go | 21 +++++++++++++++++++ pkg/templates/tests/global-matcher.yaml | 17 +++++++++++++++ .../tests/workflow-global-matchers.yaml | 10 +++++++++ 3 files changed, 48 insertions(+) create mode 100644 pkg/templates/tests/global-matcher.yaml create mode 100644 pkg/templates/tests/workflow-global-matchers.yaml diff --git a/pkg/templates/compile_test.go b/pkg/templates/compile_test.go index 34c22b0f2d..81728d9c27 100644 --- a/pkg/templates/compile_test.go +++ b/pkg/templates/compile_test.go @@ -22,6 +22,7 @@ import ( "github.com/projectdiscovery/nuclei/v3/pkg/progress" "github.com/projectdiscovery/nuclei/v3/pkg/protocols" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/generators" + "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/globalmatchers" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/variables" "github.com/projectdiscovery/nuclei/v3/pkg/protocols/http" "github.com/projectdiscovery/nuclei/v3/pkg/templates" @@ -184,6 +185,26 @@ func Test_ParseWorkflow(t *testing.T) { require.Equal(t, len(expectedTemplate.Workflows), len(got.Workflows)) } +func Test_ParseWorkflowWithGlobalMatchers(t *testing.T) { + setup() + previousGlobalMatchers := executerOpts.Options.EnableGlobalMatchersTemplates + executerOpts.Options.EnableGlobalMatchersTemplates = true + defer func() { + executerOpts.Options.EnableGlobalMatchersTemplates = previousGlobalMatchers + executerOpts.GlobalMatchers = nil + }() + executerOpts.GlobalMatchers = globalmatchers.New() + + filePath := "tests/workflow-global-matchers.yaml" + got, err := templates.Parse(filePath, nil, executerOpts) + require.NoError(t, err, "could not parse workflow template") + require.NotNil(t, got, "workflow template should not be nil") + require.NotNil(t, got.CompiledWorkflow, "compiled workflow should not be nil") + require.Len(t, got.CompiledWorkflow.Workflows, 2) + require.Len(t, got.CompiledWorkflow.Workflows[0].Executers, 1) + require.Len(t, got.CompiledWorkflow.Workflows[1].Executers, 0) +} + func Test_WrongTemplate(t *testing.T) { setup() diff --git a/pkg/templates/tests/global-matcher.yaml b/pkg/templates/tests/global-matcher.yaml new file mode 100644 index 0000000000..34c6f30d00 --- /dev/null +++ b/pkg/templates/tests/global-matcher.yaml @@ -0,0 +1,17 @@ +id: global-matcher-test + +info: + name: Global Matcher Test Template + author: pdteam + severity: info + +http: + - method: GET + path: + - "{{BaseURL}}" + global-matchers: true + matchers: + - type: word + part: body + words: + - "test" diff --git a/pkg/templates/tests/workflow-global-matchers.yaml b/pkg/templates/tests/workflow-global-matchers.yaml new file mode 100644 index 0000000000..7ac7a04983 --- /dev/null +++ b/pkg/templates/tests/workflow-global-matchers.yaml @@ -0,0 +1,10 @@ +id: workflow-global-matchers + +info: + name: Workflow With Global Matchers + author: pdteam + severity: info + +workflows: + - template: tests/match-1.yaml + - template: tests/global-matcher.yaml From 261982203b4159bac0173cf07f38a5283d658f4c Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Mon, 19 Jan 2026 16:12:36 +0700 Subject: [PATCH 2/2] fix(templates): segfault in workflow parsing with global-matchers templates Add nil guard in `parseWorkflowTemplate` to handle global-matchers templates returning nil, preventing panic on dereference. Fixes #6751 Signed-off-by: Dwi Siswanto --- pkg/templates/workflows.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/templates/workflows.go b/pkg/templates/workflows.go index 771cdf4d9c..d50222a8a9 100644 --- a/pkg/templates/workflows.go +++ b/pkg/templates/workflows.go @@ -77,6 +77,9 @@ func parseWorkflowTemplate(workflow *workflows.WorkflowTemplate, preprocessor Pr gologger.Warning().Msgf("Could not parse workflow template %s: %v\n", path, err) continue } + if template == nil { + continue + } if template.Executer == nil { gologger.Warning().Msgf("Could not parse workflow template %s: no executer found\n", path) continue