Skip to content

Commit 3ca3c16

Browse files
authored
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
2 parents 39f67ed + 2619822 commit 3ca3c16

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

pkg/templates/compile_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/projectdiscovery/nuclei/v3/pkg/progress"
2323
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
2424
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/generators"
25+
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/globalmatchers"
2526
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/variables"
2627
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/http"
2728
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
@@ -184,6 +185,26 @@ func Test_ParseWorkflow(t *testing.T) {
184185
require.Equal(t, len(expectedTemplate.Workflows), len(got.Workflows))
185186
}
186187

188+
func Test_ParseWorkflowWithGlobalMatchers(t *testing.T) {
189+
setup()
190+
previousGlobalMatchers := executerOpts.Options.EnableGlobalMatchersTemplates
191+
executerOpts.Options.EnableGlobalMatchersTemplates = true
192+
defer func() {
193+
executerOpts.Options.EnableGlobalMatchersTemplates = previousGlobalMatchers
194+
executerOpts.GlobalMatchers = nil
195+
}()
196+
executerOpts.GlobalMatchers = globalmatchers.New()
197+
198+
filePath := "tests/workflow-global-matchers.yaml"
199+
got, err := templates.Parse(filePath, nil, executerOpts)
200+
require.NoError(t, err, "could not parse workflow template")
201+
require.NotNil(t, got, "workflow template should not be nil")
202+
require.NotNil(t, got.CompiledWorkflow, "compiled workflow should not be nil")
203+
require.Len(t, got.CompiledWorkflow.Workflows, 2)
204+
require.Len(t, got.CompiledWorkflow.Workflows[0].Executers, 1)
205+
require.Len(t, got.CompiledWorkflow.Workflows[1].Executers, 0)
206+
}
207+
187208
func Test_WrongTemplate(t *testing.T) {
188209
setup()
189210

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
id: global-matcher-test
2+
3+
info:
4+
name: Global Matcher Test Template
5+
author: pdteam
6+
severity: info
7+
8+
http:
9+
- method: GET
10+
path:
11+
- "{{BaseURL}}"
12+
global-matchers: true
13+
matchers:
14+
- type: word
15+
part: body
16+
words:
17+
- "test"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
id: workflow-global-matchers
2+
3+
info:
4+
name: Workflow With Global Matchers
5+
author: pdteam
6+
severity: info
7+
8+
workflows:
9+
- template: tests/match-1.yaml
10+
- template: tests/global-matcher.yaml

pkg/templates/workflows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func parseWorkflowTemplate(workflow *workflows.WorkflowTemplate, preprocessor Pr
7777
gologger.Warning().Msgf("Could not parse workflow template %s: %v\n", path, err)
7878
continue
7979
}
80+
if template == nil {
81+
continue
82+
}
8083
if template.Executer == nil {
8184
gologger.Warning().Msgf("Could not parse workflow template %s: no executer found\n", path)
8285
continue

0 commit comments

Comments
 (0)