Merge pull request #6774 from projectdiscovery/dwisiswant0/fix/templates/segfault-in-workflow-parsing-with-global-matchers-templates

fix(templates): segfault in workflow parsing with global-matchers templates
This commit is contained in:
Mzack9999
2026-01-21 16:10:55 +04:00
committed by GitHub
4 changed files with 51 additions and 0 deletions

View File

@@ -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()

View File

@@ -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"

View File

@@ -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

View File

@@ -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