Skip to content

Commit 406ad1a

Browse files
authored
Merge pull request projectdiscovery#6944 from maxwolf8852/fix/noHostErrors-panic
fix: remove nil interface set in createEphemeralObjects to avoid panic
2 parents e4edd5a + 4344080 commit 406ad1a

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

lib/multi.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@ type unsafeOptions struct {
2929
func createEphemeralObjects(ctx context.Context, base *NucleiEngine, opts *types.Options) (*unsafeOptions, error) {
3030
u := &unsafeOptions{}
3131
u.executerOpts = &protocols.ExecutorOptions{
32-
Output: base.customWriter,
33-
Options: opts,
34-
Progress: base.customProgress,
35-
Catalog: base.catalog,
36-
IssuesClient: base.rc,
37-
RateLimiter: base.rateLimiter,
38-
Interactsh: base.interactshClient,
39-
HostErrorsCache: base.hostErrCache,
40-
Colorizer: aurora.NewAurora(true),
41-
ResumeCfg: types.NewResumeCfg(),
42-
Parser: base.parser,
43-
Browser: base.browserInstance,
32+
Output: base.customWriter,
33+
Options: opts,
34+
Progress: base.customProgress,
35+
Catalog: base.catalog,
36+
IssuesClient: base.rc,
37+
RateLimiter: base.rateLimiter,
38+
Interactsh: base.interactshClient,
39+
Colorizer: aurora.NewAurora(true),
40+
ResumeCfg: types.NewResumeCfg(),
41+
Parser: base.parser,
42+
Browser: base.browserInstance,
4443
}
4544
if opts.ShouldUseHostError() && base.hostErrCache != nil {
4645
u.executerOpts.HostErrorsCache = base.hostErrCache

lib/sdk_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package nuclei_test
33
import (
44
"context"
55
"log"
6+
"os"
67
"testing"
78
"time"
89

910
nuclei "github.com/projectdiscovery/nuclei/v3/lib"
11+
"github.com/projectdiscovery/nuclei/v3/pkg/types"
1012
"github.com/stretchr/testify/require"
1113
)
1214

@@ -55,3 +57,49 @@ func TestHeadlessOptionInitialization(t *testing.T) {
5557

5658
defer ne.Close()
5759
}
60+
61+
func TestThreadSafeNucleiEngineWithNoHostErrors(t *testing.T) {
62+
tmpDir, err := os.MkdirTemp("", "nuclei-test-no-host-errors-*")
63+
require.NoError(t, err)
64+
65+
tempTemplate, err := os.CreateTemp(tmpDir, "thread-safe-no-host-errors.*.yaml")
66+
require.NoError(t, err)
67+
68+
_, err = tempTemplate.WriteString(`id: thread-safe-no-host-errors
69+
info:
70+
name: Thread Safe (NoHostErrors)
71+
author: nuclei-sdk-test
72+
severity: info
73+
http:
74+
- method: GET
75+
path:
76+
- "{{BaseURL}}/"
77+
matchers:
78+
- type: word
79+
words:
80+
- "ok"`)
81+
require.NoError(t, err)
82+
require.NoError(t, tempTemplate.Close())
83+
84+
options := types.DefaultOptions().Copy()
85+
options.NoHostErrors = true
86+
options.Timeout = 2
87+
options.Retries = 0
88+
options.BulkSize = 1
89+
options.TemplateThreads = 1
90+
options.Templates = append(options.Templates, tempTemplate.Name())
91+
92+
ne, err := nuclei.NewThreadSafeNucleiEngineCtx(context.TODO(), nuclei.WithOptions(options))
93+
require.NoError(t, err, "could not create nuclei engine")
94+
95+
defer func() {
96+
ne.Close()
97+
_ = os.RemoveAll(tmpDir)
98+
}()
99+
100+
err = ne.GlobalLoadAllTemplates()
101+
require.NoError(t, err, "could not load templates")
102+
103+
err = ne.ExecuteNucleiWithOptsCtx(context.TODO(), []string{"scanme.sh"})
104+
require.NoError(t, err, "nuclei execution should not return an error")
105+
}

0 commit comments

Comments
 (0)