Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/sdk_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ func (e *NucleiEngine) loadIgnoreFile() error {
return err
}

// These templates are known to have weak matchers, so exclude their tags by default.
// .nuclei-ignore blocks templates that should not run by default, by tag
// (dos, fuzz, ...) and by path (templates known to have weak matchers, which
// would otherwise generate false positives). Both sections are applied, as
// the CLI runner does — applying only the tags leaves the `files` section
// inert for every SDK consumer.
e.opts.ExcludeTags = append(e.opts.ExcludeTags, ignoreFile.Tags...)
e.opts.ExcludedTemplates = append(e.opts.ExcludedTemplates, ignoreFile.Files...)

return nil
}
Expand Down
35 changes: 35 additions & 0 deletions lib/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

nuclei "github.com/projectdiscovery/nuclei/v3/lib"
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
"github.com/projectdiscovery/nuclei/v3/pkg/types"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -120,3 +121,37 @@ func TestWithOptionsRateLimitSetsRuntimeLimiter(t *testing.T) {
require.NotNil(t, execOpts.RateLimiter, "rate limiter should be initialized")
require.Equal(t, opts.RateLimit, int(execOpts.RateLimiter.GetLimit()), "runtime limiter should match rate limit from WithOptions")
}

// TestIgnoreFileFilesSectionIsApplied verifies the SDK applies BOTH sections of
// .nuclei-ignore, matching the CLI runner. The files section suppresses
// templates known to have weak matchers, so skipping it hands SDK consumers
// false positives the CLI would never report.
func TestIgnoreFileFilesSectionIsApplied(t *testing.T) {
previousConfigDir := config.DefaultConfig.GetConfigDir()
previousTemplatesDir := config.DefaultConfig.TemplatesDirectory
previousStateDir := config.DefaultConfig.GetStateDir()
t.Cleanup(func() {
config.DefaultConfig.SetConfigDir(previousConfigDir)
config.DefaultConfig.SetStateDir(previousStateDir)
config.DefaultConfig.SetTemplatesDir(previousTemplatesDir)
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.

dir := t.TempDir()
config.DefaultConfig.SetConfigDir(dir)
config.DefaultConfig.SetTemplatesDir(dir)

ignoreFile := "tags:\n - dos\nfiles:\n - http/fuzzing/wordpress-themes-detect.yaml\n"
require.NoError(t, os.WriteFile(config.DefaultConfig.GetActiveIgnoreFilePath(), []byte(ignoreFile), 0o600))

ne, err := nuclei.NewNucleiEngineCtx(context.Background(),
nuclei.WithOptions(types.DefaultOptions()),
nuclei.DisableUpdateCheck(),
)
require.NoError(t, err, "could not create nuclei engine")
defer ne.Close()

require.Contains(t, ne.Options().ExcludeTags, "dos",
"tags section should reach ExcludeTags")
require.Contains(t, ne.Options().ExcludedTemplates, "http/fuzzing/wordpress-themes-detect.yaml",
"files section should reach ExcludedTemplates")
}
Loading