122 Commits

Author SHA1 Message Date
Dogan Can Bakir 9330f0186d Merge pull request #7414 from projectdiscovery/chore/deps-bump-and-govaluate-switch
chore(deps): bump pdsec modules + govaluate/aurora migration
2026-05-19 21:18:09 +03:00
Doğan Can Bakır 1ec64a3f95 chore(deps): bump pdsec modules; switch to projectdiscovery/govaluate and aurora v4
Bumps clistats, fastdialer, retryablehttp-go, dsl, networkpolicy,
ratelimit, sarif, utils, wappalyzergo, cdncheck. dsl v0.8.18 moves to
the projectdiscovery/govaluate fork, and utils v0.11.0 pulls aurora v4,
so the corresponding imports and type references are migrated.

Refs #7380.
2026-05-18 17:14:29 +03:00
shubhamrasal 609cf3daba refactor(sdk): replace goflags overlay with RuntimeConfig struct
WithConfigFile/Bytes now decode YAML directly into a typed RuntimeConfig
struct and apply it via MergeOptions(opts). The goflags-backed reflection
overlay had too much surface area (266-line flag inventory duplicate plus
a flag-default vs DefaultOptions diff) for the actual SDK use case, which
is accepting a known set of scan knobs from cloud-shipped YAML.

RuntimeConfig schema covers tags/severity filtering, headers/vars,
interactsh, socks5-proxy, plus rate-limit/bulk-size/concurrency/timeout/
retries/rate-limit-host. Scalar knobs use *int so omitted keys preserve
the engine's existing value.

Drops internal/runner/flags.go (266 lines) and lib/config_load.go (86
lines). Reverts internal/runner/runner.go to dev (no SetupPDCPUpload
export; SDK inlines its own PDCP wrap). Keeps the LoadReportingOptionsFromBytes
extract in internal/runner/options.go for WithReportingConfigFile/Bytes.
2026-05-12 18:29:24 +05:30
shubhamrasal d5d9eed0e3 test(sdk): drop DisableUpdateCheck() from new lib/config_test.go
DisableUpdateCheck() mutates DefaultConfig process-globally. config_test.go
files run alphabetically before sdk_test.go, so my tests were disabling the
update-check globally and TestContextCancelNucleiEngine (which depends on
template auto-install) was hitting an empty template store on first run.

Drop the option from the seven test sites. First test in the binary now
triggers template install (sync.Once gated; subsequent tests free).
2026-05-12 16:16:38 +05:30
shubhamrasal 44c63a84d8 docs(sdk): trim PR comments, fix two review nits
- L1: sdk_private.go references SetupPDCPUpload (was lowercase).
- L2: config_test.go test comment describes how tmpEngine is constructed
  rather than incorrectly claiming "inherits from parent".
- Trim godocs and inline comments across the PR — drop restated WHAT,
  keep WHY and limitations.
2026-05-12 14:41:25 +05:30
shubhamrasal db156370c4 refactor(sdk): dedupe config loaders, drop threadSafePerScan mode
- Inline (*Runner).setupPDCPUpload — wrapper just delegated to the
  package-level SetupPDCPUpload. Call site inlines the three lines.
- Dedupe reporting-config file load: WithReportingConfigFile and
  loadImplicitReportingConfig share loadReportingConfigFromPath.
- Move config-overlay/load helpers (newConfigFlagSet, overlayConfigFromFile,
  applyOverlay, loadReportingConfigFromPath, loadImplicitReportingConfig)
  out of lib/config.go into lib/config_load.go.
- Drop threadSafePerScan engine mode and isThreadSafe helper. The four
  new With* options no longer gate per-scan use. pd-agent doesn't enter
  thread-safe mode; reintroducing the gate ships as a follow-up PR with
  its own scope.
2026-05-12 14:01:30 +05:30
shubhamrasal f3308fa1f3 feat(sdk): mirror -config, -report-config, -dashboard for SDK callers
SDK consumers had to rebuild types.Options by hand or shell out to the
CLI to get config-file parity. This shares BindOptionFlags,
LoadReportingOptionsFromBytes, ApplyExporterOptionsFromTypes, and
SetupPDCPUpload between cmd/nuclei and lib/ so both paths produce
identical engine state.

WithConfigFile/Bytes apply only YAML-set fields (reflection diff against
goflags defaults) so prior With* and DefaultOptions() values survive
YAML that omits them. Per-scan ExecuteNucleiWithOpts rejects these
options via a new threadSafePerScan mode, matching the pattern for
options that only make sense at construction.
2026-05-11 18:54:48 +05:30
Mzack9999 796d4302a5 Merge pull request #7342 from projectdiscovery/dwisiswant0/fix/sdk/respect-WithOptions-rate-limit
fix(sdk): respect `WithOptions` rate limit
2026-04-15 19:05:57 +03:00
Dwi Siswanto f893b6c0cb refactor: native tests (#7307)
Signed-off-by: Dwi Siswanto <git@dw1.io>
2026-04-15 05:27:07 +07:00
Dwi Siswanto a2a27e57b7 fix(sdk): respect WithOptions rate limit
when creating default limiter.

The engine could be set up with custom rate limits
through `WithOptions()`, but internal was still
hardcoding `e.rateLimiter` to 150 RPS when no
global limiter was explicitly set.

Now it builds the default limiter from the
resolved options:
1. Applies `RateLimitMinute` translation,
2. Defaults `RateLimitDuration` to 1s when
   `RateLimit > 0` and no duration is given, then
3. Creates the limiter via `GetRateLimiter()`.

Fixes #7341

Signed-off-by: Dwi Siswanto <git@dw1.io>
2026-04-14 20:29:56 +07:00
Mzack9999 4344080739 fix lint 2026-03-23 23:54:38 +01:00
Mzack9999 625d68301f fixing test 2026-03-23 23:48:41 +01:00
Mzack9999 3d259eb872 Merge branch 'dev' into pr/6944 2026-03-23 21:41:22 +01:00
Hussain Alsaibai 9caa62ebd5 fix: resolve auth secret file race condition using sync.Once (#6976)
This commit fixes a race condition where templates start executing before
the secret file's login flow completes when using -secret-file flag.

Changes:
- pkg/authprovider/authx/dynamic.go: Replace atomic.Bool-based synchronization
  with sync.Once to ensure fetch callback runs exactly once and all concurrent
  callers block until completion. This prevents the race where multiple goroutines
  would see fetching=true and return early with nil error before secrets were ready.

- internal/runner/runner.go: Always prefetch secrets when AuthProvider exists,
  removing the PreFetchSecrets flag check. This ensures authentication completes
  before scanning starts regardless of flag settings.

- lib/sdk_private.go: Same change as runner.go for SDK mode consistency.

- pkg/authprovider/file_test.go: Add test for concurrent dynamic secret access
  to verify fetch happens exactly once and all workers get authenticated.

- pkg/authprovider/authx/dynamic_test.go: Add concurrent fetch tests to verify
  proper synchronization behavior.

Fixes #6592

Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2026-03-20 01:16:28 +01:00
leo 63e5492ce3 ci: integrate typos spell checker into CI workflow
Add the crate-ci/typos GitHub Action to automatically catch spelling
errors in future PRs. This includes:

- New `.github/workflows/typos.yaml` workflow that runs on pushes to
  dev, pull requests, and manual dispatch
- `_typos.toml` configuration to suppress false positives from
  non-English READMEs, test fixtures, certificate data, CLI flag
  short names, and intentional identifiers
- Fix genuine typos found by the tool:
  - `PostReuestsHandlerRequest` -> `PostRequestsHandlerRequest`
  - `fiter` -> `filter`
  - `thant` -> `that`
  - `seperate` -> `separate`
  - `ExludedDastTmplStats` -> `ExcludedDastTmplStats`
  - `splitted` -> `split` (local variables)
  - `formated` -> `formatted` (local variables)
  - Rename `worflow_loader.go` -> `workflow_loader.go`

Fixes #6532
2026-03-08 22:11:26 -04:00
Dogan Can Bakir 70ac8bf72b Merge pull request #7018 from projectdiscovery/dwisiswant0/chore/go-fix
chore: `golangci-lint run --fix ./...`
2026-03-04 16:39:33 +03:00
Doğan Can Bakır 99c2fad3f3 Merge branch 'dev' into fix/replace-panic-with-error-handling 2026-03-03 21:22:12 +03:00
Yaron Niddam 73507cde1c Merge pull request #6788 from yaron12n/expose-cluster-ids-mapping-to-template-ids
Expose cluster ids mapping to template ids
2026-02-28 04:15:36 +05:30
Dwi Siswanto c27c47420f chore: golangci-lint run --fix ./...
Signed-off-by: Dwi Siswanto <git@dw1.io>
2026-02-26 22:03:14 +07:00
Doğan Can Bakır ef650defb6 Revert "fix(lint): use fmt.Fprintf for remaining WriteString(fmt.Sprintf(...)) calls"
This reverts commit 10421e9d00.
2026-02-26 14:45:25 +03:00
Doğan Can Bakır 10421e9d00 fix(lint): use fmt.Fprintf for remaining WriteString(fmt.Sprintf(...)) calls 2026-02-25 15:34:45 +03:00
Dwi Siswanto 002b58da7b test(lib): add TestThreadSafeNucleiEngineWithNoHostErrors
Signed-off-by: Dwi Siswanto <git@dw1.io>
2026-02-24 23:32:54 +07:00
maxim b31307605d fix panic 2026-02-24 23:00:24 +07:00
bimakw 75525ed431 fix(loader): replace panic with error handling in template loader
Replace panic with proper error return when dialers are missing,
allowing callers to handle the situation gracefully.

Changes:
- Modify LoadTemplatesWithTags to return ([]*templates.Template, error)
- Modify LoadTemplates to return ([]*templates.Template, error)
- Modify Load to return error
- Replace panic("dialers with executionId...") with fmt.Errorf
- Replace panic("could not create wait group") with fmt.Errorf
- Update all callers to handle the new error return

Callers updated:
- internal/runner/lazy.go
- internal/runner/runner.go
- internal/server/nuclei_sdk.go
- lib/multi.go
- lib/sdk.go
- cmd/integration-test/library.go
- pkg/protocols/common/automaticscan/util.go
- pkg/catalog/loader/loader_bench_test.go

Fixes #6674
2026-02-06 17:10:21 +07:00
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