Commit Graph

98 Commits

Author SHA1 Message Date
Dogan Can Bakir
1d3a279466 Merge pull request #5972 from meme-lord/multioptions
allow WithNetworkConfig and WithInteractshOptions to be used by NewThreadSafeNucleiEngineCtx
2026-01-12 20:07:26 +07:00
Mzack9999
942f9f09f5 Merge branch 'dev' into 6594_init_exec_id 2026-01-08 14:13:03 +04:00
Dwi Siswanto
bb79a061bc perf(generators): optimize MergeMaps to reduce allocs
`MergeMaps` accounts for 11.41% of allocs (13.8
GB) in clusterbomb mode. With 1,305 combinations
per target, this function is called millions of
times in the hot path.

RCA:
* Request generator calls `MergeMaps` with single
  arg on every payload combination, incurring
  variadic overhead.
* Build request merges same maps multiple times
  per request.
* `BuildPayloadFromOptions` recomputes static CLI
  options on every call.
* Variables calls `MergeMaps` $$2×N$$ times per
  variable evaluation (once in loop, once in
  `evaluateVariableValue`)

Changes:

Core optimizations in maps.go:
* Pre-size merged map to avoid rehashing (30-40%
  reduction)
* Add `CopyMap` for efficient single-map copy
  without variadic overhead.
* Add `MergeMapsInto` for in-place mutation when
  caller owns destination.

Hot path fixes:
* Replace `MergeMaps(r.currentPayloads)` with
  `CopyMap(r.currentPayloads)` to eliminates
  allocation on every combination iteration.
* Pre-allocate combined map once, extend in-place
  during `ForEach` loop instead of creating new
  map per variable (eliminates $$2×N$$ allocations
  per request).

Caching with concurrency safety:
* Cache `BuildPayloadFromOptions` computation in
  `sync.Map` keyed by `types.Options` ptr, but
  return copy to prevent concurrent modification.
* Cost: shallow copy of ~10-20 entries vs. full
  merge of vars + env (85-90% savings in typical
  case)
* Clear cache in `closeInternal()` to prevent
  memory leaks when SDK instances are created or
  destroyed.

Estimated impact: 40-60% reduction in `MergeMaps`
allocations (5.5-8.3 GB savings from original
13.8 GB). Safe for concurrent execution and SDK
usage with multiple instances.

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-12-19 20:19:43 +07:00
Dwi Siswanto
2b9c985818 fix(lib): segfault when init engine with EnableHeadlessWithOpts (#6602)
* fix(lib): segfault when init engine with `EnableHeadlessWithOpts`

The panic was caused by attempting to log a
sandbox warning before the logger was initialized.

RCA:
* SDK option funcs were exec'd before logger init.
* `EnableHeadlessWithOpts()` attempted to create
  browser instance & log warnings during the
  config phase.
* `Logger` was only init'd later in `init()`
  phase.
* This caused nil pointer dereference when
  `MustDisableSandbox()` returned true (root on
  Linux/Unix or Windows).

Changes:
* Init `Logger` in `types.DefaultOptions()` to
  ensure it's always available before any option
  functions execute.
* Init `Logger` field in both
  `NewNucleiEngineCtx()` and
  `NewThreadSafeNucleiEngineCtx()` from
  `defaultOptions.Logger`.
* Move browser instance creation from
  `EnableHeadlessWithOpts()` to the `init()` phase
  where `Logger` is guaranteed to be available.
* Simplify logger sync logic in `init()` to only
  update if changed by `WithLogger` option.
* Add test case to verify headless initialization
  works without panic.

The fix maintains backward compatibility while
make sure the logger is always available when
needed by any SDK option function.

Fixes #6601.

Signed-off-by: Dwi Siswanto <git@dw1.io>

* build(make): adds `-timeout 30m -count 1` GOFLAGS in `test` cmd

Signed-off-by: Dwi Siswanto <git@dw1.io>

* Revert "fix(lib): segfault when init engine with `EnableHeadlessWithOpts`"

let see if this pass flaky test.

This reverts commit 63fcb6a1cbe7a4db7a78be766affc70eb237e57e.

* test(engine): let see if this pass flaky test

Signed-off-by: Dwi Siswanto <git@dw1.io>

* Revert "Revert "fix(lib): segfault when init engine with `EnableHeadlessWithOpts`""

This reverts commit 62b4223803ccb1e93593e2e08e39923d76aa20b1.

* test(engine): increase `TestActionNavigate` timeout

Signed-off-by: Dwi Siswanto <git@dw1.io>

* Revert "test(engine): let see if this pass flaky test"

This reverts commit d27cd985cff1b06aa1965ea11f8aa32f00778ab5.

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-12-05 21:55:41 +07:00
Didier Durand
3447f09c9f [Doc] Fixing typos in various files 2025-12-05 07:17:14 +01:00
Didier Durand
9ec2e995d0 docs: fixing typos in multiple files (#6653)
* [Doc] Fixing typos in multiple files

* [Doc] Fixing js.go based in review suggestion
2025-12-05 12:29:19 +07:00
Doğan Can Bakır
683bc04106 Merge branch 'dev' into 6594_init_exec_id 2025-11-25 12:07:00 +09:00
Doğan Can Bakır
ce6070d979 remove redundant init 2025-11-21 16:51:48 +09:00
Niek den Breeje
8b8a3a11b6 refactor(sdk): don't create parentDir when configuring tmpDir 2025-11-18 17:31:01 +01:00
Doğan Can Bakır
6a1451f8b6 remove redundant init 2025-11-10 22:51:40 +09:00
Niek den Breeje
3eff4146e1 feat(sdk): create parent & tmp dir in WithTemporaryDirectory 2025-11-10 10:41:56 +01:00
Niek den Breeje
87d62d3a8f style(sdk): remove unnecessary else block 2025-11-10 08:18:14 +01:00
Niek den Breeje
efcc8e95c3 fix(sdk): init default engine tmpDir when unconfigured 2025-11-10 07:54:54 +01:00
Niek den Breeje
96bfb2bac1 feat(sdk): add tmpDir configuration option for SDK users 2025-11-10 07:31:18 +01:00
Niek den Breeje
7b0c6fb782 docs(sdk): update comment to more accurately reflect purpose 2025-11-07 12:14:45 +01:00
Niek den Breeje
2829fd30bb fix(sdk): configure tmpDir for SDK
Closes #6595.
2025-11-07 12:01:46 +01:00
meme-lord
b87715a191 Update config.go 2025-10-30 15:04:46 +00:00
meme-lord
eff7931ec2 Merge branch 'dev' into multioptions 2025-10-30 15:04:04 +00:00
Dwi Siswanto
dd8946d3f2 chore: satisfy lints
Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-10-30 09:41:01 +07:00
Mzack9999
089e2a4ee0 centralizing ratelimiter logic 2025-09-12 17:46:42 +02:00
Tarun Koyalwar
19247ae74b Path-Based Fuzzing SQL fix (#6400)
* setup claude

* migrate to using errkit

* fix unused imports + lint errors

* update settings.json

* fix url encoding issue

* fix lint error

* fix the path fuzzing component

* fix lint error
2025-08-25 13:36:58 +05:30
Sandeep Singh
b4644af80a Lint + test fixes after utils dep update (#6393)
* fix: remove undefined errorutil.ShowStackTrace

* feat: add make lint support and integrate with test

* refactor: migrate errorutil to errkit across codebase

- Replace deprecated errorutil with modern errkit
- Convert error declarations from var to func for better compatibility
- Fix all SA1019 deprecation warnings
- Maintain error chain support and stack traces

* fix: improve DNS test reliability using Google DNS

- Configure test to use Google DNS (8.8.8.8) for stability
- Fix nil pointer issue in DNS client initialization
- Keep production defaults unchanged

* fixing logic

* removing unwanted branches in makefile

---------

Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2025-08-20 05:28:23 +05:30
HD Moore
5b89811b90 Support concurrent Nuclei engines in the same process (#6322)
* support for concurrent nuclei engines

* clarify LfaAllowed race

* remove unused mutex

* update LfaAllowed logic to prevent races until it can be reworked for per-execution ID

* Update pkg/templates/parser.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* debug tests

* debug gh action

* fixig gh template test

* using atomic

* using synclockmap

* restore tests concurrency

* lint

* wiring executionId in js fs

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2025-07-19 00:10:58 +05:30
HD Moore
f26996cb89 Remove singletons from Nuclei engine (continuation of #6210) (#6296)
* introducing execution id

* wip

* .

* adding separate execution context id

* lint

* vet

* fixing pg dialers

* test ignore

* fixing loader FD limit

* test

* fd fix

* wip: remove CloseProcesses() from dev merge

* wip: fix merge issue

* protocolstate: stop memguarding on last dialer delete

* avoid data race in dialers.RawHTTPClient

* use shared logger and avoid race conditions

* use shared logger and avoid race conditions

* go mod

* patch executionId into compiled template cache

* clean up comment in Parse

* go mod update

* bump echarts

* address merge issues

* fix use of gologger

* switch cmd/nuclei to options.Logger

* address merge issues with go.mod

* go vet: address copy of lock with new Copy function

* fixing tests

* disable speed control

* fix nil ExecuterOptions

* removing deprecated code

* fixing result print

* default logger

* cli default logger

* filter warning from results

* fix performance test

* hardcoding path

* disable upload

* refactor(runner): uses `Warning` instead of `Print` for `pdcpUploadErrMsg`

Signed-off-by: Dwi Siswanto <git@dw1.io>

* Revert "disable upload"

This reverts commit 114fbe6663.

* Revert "hardcoding path"

This reverts commit cf12ca800e.

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
Co-authored-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: Dwi Siswanto <25837540+dwisiswant0@users.noreply.github.com>
2025-07-10 01:17:26 +05:30
Jose De La O Hernandez
285c5e1442 fixing panic caused by uninitialized colorizer (#6315) 2025-07-09 04:34:05 +05:30
Dwi Siswanto
7e2ec686ae fix(lib): scans didn't stop on ctx cancellation (#6310)
* fix(lib): scans didn't stop on ctx cancellation

Signed-off-by: Dwi Siswanto <git@dw1.io>

* Update lib/sdk_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix(lib): wait resources to be released b4 return

Signed-off-by: Dwi Siswanto <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-07-09 01:04:16 +07:00
Eric Gruber
b95b04fc4d feat: add EnableMatcherStatus function to configure matcher status in NucleiEngine (#6191) 2025-06-17 05:08:01 +05:30
Dogan Can Bakir
357fe9efa7 add resume option to sdk (#6083) 2025-03-07 16:53:55 +05:30
meme-lord
08c46ffaeb Added WithResponseReadSize function to allow SDK users to modify max response read opt (#5961)
* added WithResponseReadSize function to allow SDK users to modify max response read opt

* Update lib/config.go

improved comment, changed casing of param name, added negative input check

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fixing rabbitai commit >:(

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-01-14 15:35:12 +05:30
meme-lord
e3c6849a6c allow WithNetworkConfig and WithInteractshOptions to be used by NewThreadSafeNucleiEngineCtx 2025-01-09 14:29:45 +00:00
chuu
258f38f72d fix(sdk): NoHostErrors not set (#5783) 2025-01-02 17:48:36 +05:30
Mzack9999
1e87ca82c8 fix missing browser init (#5896)
* fix missing browser init

* .

* using lazy init

* updating test with new web ui

* go mod

* sandbox test

* non fatal error
2024-12-17 15:38:42 +05:30
Shubham Rasal
be1f634eae Add Alive Proxy into Options (#5903)
* Move proxy variable from global to options

- Provides ability to pass diff proxy in single nuclei instance using sdk

* add type check (resolve comments)
2024-12-13 04:23:27 +05:30
Dwi Siswanto
3a07fa9c22 feat: add -enable-global-matchers flag (#5857)
* feat: add `-enable-global-matchers` flag

Signed-off-by: Dwi Siswanto <git@dw1.io>

* refactor(templates): use embedded `types.Options` in `Template`

Signed-off-by: Dwi Siswanto <git@dw1.io>

* feat(lib): add `EnableGlobalMatchersTemplates` SDK opt

Signed-off-by: Dwi Siswanto <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2024-11-27 14:37:59 +05:30
Dogan Can Bakir
63687c2ce0 disable self-contained and file protocol templates as default (#5825)
* disable self-contained and file protocol templates as default

* make excluding default

* add config funcs

* fix wrn display

* fix integration tests

* enable self-contained templates when code templates are enabled

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2024-11-19 22:00:28 +05:30
Dwi Siswanto
3e4ec90cea ci: refactor workflows (#5818)
* ci: refactor workflows

Signed-off-by: Dwi Siswanto <git@dw1.io>

* chore: structured build outputs

Signed-off-by: Dwi Siswanto <git@dw1.io>

* feat: use `go-ci`

Signed-off-by: Dwi Siswanto <git@dw1.io>

* chore(make): misused var for `vet` cmd

Signed-off-by: Dwi Siswanto <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2024-11-14 19:19:49 +07:00
Dogan Can Bakir
7547f1a5c3 Merge pull request #5678 from alban-stourbe-wmx/feature/sdk-add-vars
Add vars with SDK
2024-11-08 15:11:58 +03:00
chuu
8a4be44631 perf(sdk): sdk functions to access workflow store 2024-10-24 14:34:50 +08:00
Dogan Can Bakir
92213e1335 Merge pull request #5733 from projectdiscovery/fix_template_loading_logic
fix template loading logic
2024-10-15 13:52:47 +03:00
chuu
aab2cadb64 fix: input helper in executor options (#5712) 2024-10-14 19:22:52 +05:30
Doğan Can Bakır
4ef058758c fix template loading logic 2024-10-14 15:53:53 +03:00
alban.stourbe stourbe
ed3e06a701 Add checkerr on runtimeVars & Add a new TestSDK 2024-10-01 09:29:43 +02:00
alban.stourbe stourbe
d0463e8ca3 Add vars with SDK 2024-09-30 16:52:54 +02:00
Dogan Can Bakir
a45e4bbd19 move code around (#5626) 2024-09-12 17:05:32 +05:30
Doğan Can Bakır
50023428d0 fix lint 2024-08-19 23:09:07 +03:00
Tarun Koyalwar
1c76398aea lint error fixes (#5531)
* lint error fixes

* chore: satisfy non-constant format str in call lint (govet)

Signed-off-by: Dwi Siswanto <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: Dwi Siswanto <git@dw1.io>
2024-08-16 20:31:23 +05:30
alban-stourbe-wmx
0787ff29e0 Add Workflows SDK scan (#5409)
* Add Workflows SDK scan

* minor

---------

Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2024-08-03 23:13:31 +05:30
Dogan Can Bakir
1fa0e2b473 disable http probe when passive mode is enabled (#5418) 2024-07-22 18:25:02 +05:30
Dogan Can Bakir
6c32eb7d1e add sdk option to disable update check (#5346) 2024-07-15 18:51:16 +05:30
Douglas Danger Manley
e61ca0c42d Use fs.FS when explicitly given (#5312)
* Use the `templateFS` if it's there when calling `OpenFile`

* Add a new constructor

* More refactoring

* Both of my use cases are working

* Fix for legacy assumptions

* minor update: remove gologger debug stmts

---------

Co-authored-by: Tarun Koyalwar <tarun@projectdiscovery.io>
2024-06-23 01:12:01 +05:30