Commit Graph

268 Commits

Author SHA1 Message Date
Mzack9999
c73906b405 Merge pull request #6691 from stringscut/dev
chore: execute goimports to format the code
2025-12-15 14:37:56 +04:00
Mzack9999
8891d70d42 Merge pull request #6687 from projectdiscovery/dwisiswant0/fix/headless/data-race-when-reading-page-history
fix(headless): data race when reading page history
2025-12-15 13:13:23 +04:00
Dwi Siswanto
cf3b5bf449 fix: body loss on retries/redirects in remaining paths (#6693)
Continue the fix from #6666 by converting
remaining direct Body assignments to use setter
methods:

* pkg/fuzz/component/body.go:139: use
  `SetBodyReader()` in transfer-encoding path.
* pkg/protocols/http/request.go:694: use
  `SetBodyString()` in fuzz component `Rebuild()`.

Fixes #6692.

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-12-13 22:37:39 +07:00
Dwi Siswanto
b63a23bd5c fix(http): pass dynamicValues to EvaluateWithInteractsh (#6685)
* fix(http): pass `dynamicValues` to `EvaluateWithInteractsh`

When `LazyEval` is true (triggered by `variables`
containing `BaseURL`, `Hostname`,
`interactsh-url`, etc.), variable expressions are not
eval'ed during YAML parsing & remain as raw exprs
like "{{rand_base(5)}}".

At request build time, `EvaluateWithInteractsh()`
checks if a variable already has a value in the
passed map before re-evaluating its expression.
But, `dynamicValues` (which contains the template
context with previously eval'ed values) was not
being passed, causing exprs like `rand_*` to be
re-evaluated on each request, producing different
values.

Fixes #6684 by including `dynamicValues` in the
map passed to `EvaluateWithInteractsh()`, so
variables evaluated in earlier requests retain
their values in subsequent requests.

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

* chore(http): rm early eval in `(*Request).ExecuteWithResults()`

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

* test: adds variables-threads-previous integration test

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

* test: adds constants-with-threads integration test

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

* test: adds race-with-variables integration test

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

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-12-12 14:37:59 +07:00
stringscut
7fb1fe7bf2 chore: execute goimports to format the code
Signed-off-by: stringscut <stringscut@outlook.jp>
2025-12-12 15:10:22 +08:00
Dwi Siswanto
3e93996471 fix(headless): data race when reading page history
The `(*Page).HistoryData` was being read w/o
holding the mutex lock after
`(*Page).ExecuteActions()` returns, while the
background hijack goroutine could still be writing
to it via `(*Page).addToHistory()`.

Copy the first history item by value while holding
RLock to avoid racing with concurrent append ops.

Fixes #6686.

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-12-11 05:57:28 +07:00
Dwi Siswanto
8e535f625d fix(http): cache resp strings to reduce memory allocs (#6679)
Prev, `FullResponseString()`, `BodyString()`, and
`HeadersString()` were called multiple times per
HTTP response iteration, each call allocating a
new string copy of the response data.

For a 10MB response, this resulted in ~60MB of
redundant string allocs/response (6 calls x 10MB).

Cache the string representations once per `Fill()`
cycle and reuse them throughout the response
processing loop. This reduces allocs from 6 to 3
per response, cutting memory usage by ~50% for
response string handling.

Profiling showed these functions accounting for
~89% of heap allocs (5.7GB out of 6.17GB) during
large scans.

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-12-10 18:25:18 +07:00
Dwi Siswanto
df74ff3edf fix: enable all template types for template list/display (#6668)
* fix: enable all template types for template list/display

When using `-tl` or `-td`, explicitly enable all
template types (`code`, `file`, `self-contained`,
`global-matchers`, `headless`, `dast`) to ensure
all templates are listed w/o requiring extra flags.

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

* chore: cleanup messy messy messy

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

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-12-08 14:26:24 +07:00
Dwi Siswanto
56b6d42723 fix(http): lost request body on retries & redirects (#6666)
* fix(http): lost request body on retries & redirects

Updates the HTTP protocol to use
`(*retryablehttp.Request).SetBodyString` instead
of direct `Body` assignment.

This fixes #6665 where the request body was
dropped during retries or 307/308 redirects
because `GetBody` was not being populated.

Thanks to @zzyjsj for reporting the bug in the
upstream dependency and the hints!

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

* empty: add co-author

Co-authored-by: zzy <zzyjsj@users.noreply.github.com>
Signed-off-by: Dwi Siswanto <git@dw1.io>

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: zzy <zzyjsj@users.noreply.github.com>
2025-12-06 16:27:57 +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
7f56dc27c1 Update pkg/protocols/http/http.go
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-12-05 07:32:13 +01: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
dependabot[bot]
7e151de8a3 chore: bump PD modules & update httputil calls (#6629)
* chore(deps): bump the modules group across 1 directory with 11 updates

Bumps the modules group with 11 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [github.com/projectdiscovery/fastdialer](https://github.com/projectdiscovery/fastdialer) | `0.4.16` | `0.4.17` |
| [github.com/projectdiscovery/hmap](https://github.com/projectdiscovery/hmap) | `0.0.95` | `0.0.96` |
| [github.com/projectdiscovery/retryabledns](https://github.com/projectdiscovery/retryabledns) | `1.0.108` | `1.0.109` |
| [github.com/projectdiscovery/retryablehttp-go](https://github.com/projectdiscovery/retryablehttp-go) | `1.0.131` | `1.0.132` |
| [github.com/projectdiscovery/gologger](https://github.com/projectdiscovery/gologger) | `1.1.60` | `1.1.61` |
| [github.com/projectdiscovery/networkpolicy](https://github.com/projectdiscovery/networkpolicy) | `0.1.28` | `0.1.29` |
| [github.com/projectdiscovery/tlsx](https://github.com/projectdiscovery/tlsx) | `1.2.1` | `1.2.2` |
| [github.com/projectdiscovery/useragent](https://github.com/projectdiscovery/useragent) | `0.0.102` | `0.0.103` |
| [github.com/projectdiscovery/utils](https://github.com/projectdiscovery/utils) | `0.6.1` | `0.7.1` |
| [github.com/projectdiscovery/wappalyzergo](https://github.com/projectdiscovery/wappalyzergo) | `0.2.55` | `0.2.56` |
| [github.com/projectdiscovery/cdncheck](https://github.com/projectdiscovery/cdncheck) | `1.2.10` | `1.2.11` |



Updates `github.com/projectdiscovery/fastdialer` from 0.4.16 to 0.4.17
- [Release notes](https://github.com/projectdiscovery/fastdialer/releases)
- [Commits](https://github.com/projectdiscovery/fastdialer/compare/v0.4.16...v0.4.17)

Updates `github.com/projectdiscovery/hmap` from 0.0.95 to 0.0.96
- [Release notes](https://github.com/projectdiscovery/hmap/releases)
- [Commits](https://github.com/projectdiscovery/hmap/compare/v0.0.95...v0.0.96)

Updates `github.com/projectdiscovery/retryabledns` from 1.0.108 to 1.0.109
- [Release notes](https://github.com/projectdiscovery/retryabledns/releases)
- [Commits](https://github.com/projectdiscovery/retryabledns/compare/v1.0.108...v1.0.109)

Updates `github.com/projectdiscovery/retryablehttp-go` from 1.0.131 to 1.0.132
- [Release notes](https://github.com/projectdiscovery/retryablehttp-go/releases)
- [Commits](https://github.com/projectdiscovery/retryablehttp-go/compare/v1.0.131...v1.0.132)

Updates `github.com/projectdiscovery/gologger` from 1.1.60 to 1.1.61
- [Release notes](https://github.com/projectdiscovery/gologger/releases)
- [Commits](https://github.com/projectdiscovery/gologger/compare/v1.1.60...v1.1.61)

Updates `github.com/projectdiscovery/networkpolicy` from 0.1.28 to 0.1.29
- [Release notes](https://github.com/projectdiscovery/networkpolicy/releases)
- [Commits](https://github.com/projectdiscovery/networkpolicy/compare/v0.1.28...v0.1.29)

Updates `github.com/projectdiscovery/tlsx` from 1.2.1 to 1.2.2
- [Release notes](https://github.com/projectdiscovery/tlsx/releases)
- [Changelog](https://github.com/projectdiscovery/tlsx/blob/main/.goreleaser.yml)
- [Commits](https://github.com/projectdiscovery/tlsx/compare/v1.2.1...v1.2.2)

Updates `github.com/projectdiscovery/useragent` from 0.0.102 to 0.0.103
- [Release notes](https://github.com/projectdiscovery/useragent/releases)
- [Commits](https://github.com/projectdiscovery/useragent/compare/v0.0.102...v0.0.103)

Updates `github.com/projectdiscovery/utils` from 0.6.1 to 0.7.1
- [Release notes](https://github.com/projectdiscovery/utils/releases)
- [Changelog](https://github.com/projectdiscovery/utils/blob/main/CHANGELOG.md)
- [Commits](https://github.com/projectdiscovery/utils/compare/v0.6.1...v0.7.1)

Updates `github.com/projectdiscovery/wappalyzergo` from 0.2.55 to 0.2.56
- [Release notes](https://github.com/projectdiscovery/wappalyzergo/releases)
- [Commits](https://github.com/projectdiscovery/wappalyzergo/compare/v0.2.55...v0.2.56)

Updates `github.com/projectdiscovery/cdncheck` from 1.2.10 to 1.2.11
- [Release notes](https://github.com/projectdiscovery/cdncheck/releases)
- [Changelog](https://github.com/projectdiscovery/cdncheck/blob/main/.goreleaser.yaml)
- [Commits](https://github.com/projectdiscovery/cdncheck/compare/v1.2.10...v1.2.11)

---
updated-dependencies:
- dependency-name: github.com/projectdiscovery/fastdialer
  dependency-version: 0.4.17
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/hmap
  dependency-version: 0.0.96
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/retryabledns
  dependency-version: 1.0.109
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/retryablehttp-go
  dependency-version: 1.0.132
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/gologger
  dependency-version: 1.1.61
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/networkpolicy
  dependency-version: 0.1.29
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/tlsx
  dependency-version: 1.2.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/useragent
  dependency-version: 0.0.103
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/utils
  dependency-version: 0.7.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/wappalyzergo
  dependency-version: 0.2.56
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: modules
- dependency-name: github.com/projectdiscovery/cdncheck
  dependency-version: 1.2.11
  dependency-type: indirect
  update-type: version-update:semver-patch
  dependency-group: modules
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: update utils.httputil calls

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

* chore(deps): bump github.com/projectdiscovery/utils => v0.7.3

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

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Dwi Siswanto <git@dw1.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dwi Siswanto <git@dw1.io>
2025-12-01 02:07:25 +07:00
ledigang
29977358d7 chore: omit unnecessary reassignment (#6622)
Signed-off-by: ledigang <shuangcui@msn.com>
2025-11-24 19:01:30 +07:00
Dogan Can Bakir
c32cff8521 Merge pull request #6493 from projectdiscovery/dwisiswant0/fix/restore-parallel-processing-in-workflow-file-proto
fix: restore parallel processing in file proto
2025-11-23 23:34:35 +09:00
Dwi Siswanto
d5d8d50ab7 fix(interactsh): skip DNS lookups on interactsh domains (#6614)
* fix(interactsh): skip DNS lookups on interactsh domains

to prevent false positives.

Prevents nuclei from resolving interactsh domains
injected in Host headers, which would cause
self-interactions to be incorrectly reported as
matches.

Changes:
* Add `GetHostname()` method to `interactsh.Client`
  to expose active server domain.
* Skip CNAME DNS lookups in
  `(*http.Request).addCNameIfAvailable` when
  hostname matches the
  `(*interactsh.Client).GetHostname`.

Fixes #6613

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

* fix(http): prevent false `interactshDomain` matches

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

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-11-21 21:11:59 +05:30
Dwi Siswanto
ad1e6f8d75 feat(variables): check for undefined params for lazy eval (#6618)
* feat(variables): check for undefined params for lazy eval

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

* test(variables): add TestCheckForLazyEval

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

* fix(variables): fail safe on err compile expr

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

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-11-21 12:53:58 +07:00
Mzack9999
4e8843a7cd Merge branch 'dev' into multiport-js 2025-11-18 22:24:21 +04:00
Mzack9999
9b37f1b441 adding test case 2025-11-18 21:43:28 +04:00
Mzack9999
aecef0ab75 Merge branch 'dev' into feat-gozero-virtual 2025-11-08 06:01:01 +04:00
Dwi Siswanto
d7da0e0914 fix(http): resolve timeout config issues (#6562)
across multiple layers

Fixes timeout configuration conflicts where HTTP
requests would timeout prematurely despite
configured values in `@timeout` annotations or
`-timeout` flags.

RCA:
* `retryablehttp` pkg overriding with default
  30s timeout.
* Custom timeouts not propagating to
  `retryablehttp` layer.
* Multiple timeout layers not sync properly.

Changes:
* Propagate custom timeouts from `@timeout`
  annotations to `retryablehttp` layer.
* Adjust 5-minute maximum cap to prevent DoS via
  extremely large timeouts.
* Ensure `retryableHttpOptions.Timeout` respects
  `ResponseHeaderTimeout`.
* Add comprehensive tests for timeout capping
  behavior.

This allows templates to override global timeout
via `@timeout` annotations while preventing abuse
thru unreasonably large timeout values.

Fixes #6560.

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-11-04 08:51:17 +07:00
Dwi Siswanto
e60f4158ea chore(file): satisfy lints
Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-11-02 21:24:27 +07:00
Dwi Siswanto
984deac200 test: adds Test(FileProtocol|Workflows)ConcurrentExecution tests
Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-11-02 21:24:27 +07:00
Dwi Siswanto
17360cb6e4 fix: restore parallel processing in workflow & file proto
add missing `go` keyword to anonymous funcs that
were intended to run as goroutines but were
executing synchronously instead.

Fixes #6492

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-11-02 21:24:26 +07:00
Deamhan
f3181b9a2a fix(headless): fixed memory leak issue during page initialization (#6569)
* fix(headless): fixed memory leak issue during page initialization

* fix(headless): typo fix and added comment

* fix(headless): one more typo fix
2025-11-02 00:33:25 +07:00
Mzack9999
e535e0126f adding tests 2025-10-28 14:19:12 +04:00
Mzack9999
9d59fd0188 adding xpath + json extractors 2025-10-28 14:19:06 +04:00
Mzack9999
3384606dea adding support for execution in docker 2025-10-25 00:31:03 +04:00
Dwi Siswanto
d2ae3521cc refactor(disk): templates catalog (#5914)
* refactor(disk): templates catalog

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

* feat(disk): drying err

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

* feat(disk): simplify `DiskCatalog.OpenFile` method

since `BackwardsCompatiblePaths` func is already
deprecated.

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

* test: update functional test cases

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

* feat: reuse error

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

* fix(disk): handle glob errors consistently

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

* fix(disk): use forward slashes for fs.FS path ops

to fix Windows compat.

The io/fs package requires forward slashes ("/")
as path separators regardless of the OS. Using
[filepath.Separator] or [os.PathSeparator] breaks
[fs.Open] and [fs.Glob] ops on Windows where the
separator is backslash ("\").

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

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-10-24 07:31:35 +07:00
Ice3man
f3298323f3 fix: populate req_url_pattern before event creation (#6547) 2025-10-24 03:06:12 +05:30
Dogan Can Bakir
ae52ef04c9 Merge pull request #6545 from projectdiscovery/bugfix-6329-clientpool
clean up pools after 24hours inactivity
2025-10-22 22:41:20 +03:00
Mzack9999
b9ce0c2226 fixing syntax 2025-10-22 19:11:26 +04:00
Mzack9999
5557f4eae3 fixing lint 2025-10-21 16:57:26 +04:00
Mzack9999
f6efa9da6c clean up pools after 24hours inactivity 2025-10-21 16:41:26 +04:00
Mzack9999
5b7b83618c fixing failing integration tests 2025-10-21 14:29:15 +04:00
Dogan Can Bakir
e6c1a80498 Merge pull request #6528 from projectdiscovery/6523_make_verbose
log failed expr compilations
2025-10-14 18:40:01 +03:00
Dogan Can Bakir
dcdc7ebc32 Merge pull request #6521 from pstoeckle/dev
chore(typos): fix typos
2025-10-14 13:45:09 +03:00
chuu
0974d7fd04 fix(variable): global variable not same between two request in flow mode (#6395)
* fix(variable): global variable not same between two request in flow mode(#6337)

* update gitignore

---------

Co-authored-by: chuu <7704684+lizhi3n@user.noreply.gitee.com>
Co-authored-by: PDTeamX <8293321+ehsandeep@users.noreply.github.com>
Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
2025-10-14 15:27:53 +05:30
Doğan Can Bakır
cc1d646347 log failed expr compilations 2025-10-13 14:41:27 +03:00
Patrick Stoeckle
bfef42f9e3 chore(typos): fix typos 2025-10-10 17:32:54 +02:00
Mzack9999
8c560523e3 better error handling 2025-10-06 21:29:56 +02:00
Mzack9999
07590268c1 restoring basic sequential multiport support 2025-10-06 16:10:58 +02:00
pussycat0x
7e04181391 minor -changes 2025-09-27 21:14:20 +05:30
pussycat0x
6a6de384fc Multi Port Support Added - JS 2025-09-27 21:00:13 +05:30
Nakul Bharti
93be3b8291 fix: improve cleanup in parallel execution (#6490) 2025-09-24 01:12:43 +05:30
Nakul Bharti
c4fa2c74c1 cache, goroutine and unbounded workers management (#6420)
* Enhance matcher compilation with caching for regex and DSL expressions to improve performance. Update template parsing to conditionally retain raw templates based on size constraints.

* Implement caching for regex and DSL expressions in extractors and matchers to enhance performance. Introduce a buffer pool in raw requests to reduce memory allocations. Update template cache management for improved efficiency.

* feat: improve concurrency to be bound

* refactor: replace fmt.Sprintf with fmt.Fprintf for improved performance in header handling

* feat: add regex matching tests and benchmarks for performance evaluation

* feat: add prefix check in regex extraction to optimize matching process

* feat: implement regex caching mechanism to enhance performance in extractors and matchers, along with tests and benchmarks for validation

* feat: add unit tests for template execution in the core engine, enhancing test coverage and reliability

* feat: enhance error handling in template execution and improve regex caching logic for better performance

* Implement caching for regex and DSL expressions in the cache package, replacing previous sync.Map usage. Add unit tests for cache functionality, including eviction by capacity and retrieval of cached items. Update extractors and matchers to utilize the new cache system for improved performance and memory efficiency.

* Add tests for SetCapacities in cache package to ensure cache behavior on capacity changes

- Implemented TestSetCapacities_NoRebuildOnZero to verify that setting capacities to zero does not clear existing caches.
- Added TestSetCapacities_BeforeFirstUse to confirm that initial cache settings are respected and not overridden by subsequent capacity changes.

* Refactor matchers and update load test generator to use io package

- Removed maxRegexScanBytes constant from match.go.
- Replaced ioutil with io package in load_test.go for NopCloser usage.
- Restored TestValidate_AllowsInlineMultiline in load_test.go to ensure inline validation functionality.

* Add cancellation support in template execution and enhance test coverage

- Updated executeTemplateWithTargets to respect context cancellation.
- Introduced fakeTargetProvider and slowExecuter for testing.
- Added Test_executeTemplateWithTargets_RespectsCancellation to validate cancellation behavior during template execution.
2025-09-15 23:48:02 +05:30
Mzack9999
5c8da8d88b code from https://github.com/projectdiscovery/nuclei/pull/6427 2025-09-12 10:29: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
Dwi Siswanto
309018fbf4 fix: segfault in template caching logic (#6421)
* fix: segfault in template caching logic

when templates had no executable requests after
option updates.

the cached templates could end up with 0 requests
and no flow execution path, resulting in a nil
engine pointer that was later derefer w/o
validation.

bug seq:
caching template (w/ valid requests) -> get cached
template -> `*ExecutorOptions.Options` copied and
modified (inconsistent) -> requests updated (with
new options -- some may be invalid, and without
recompile) -> template returned w/o validation ->
`compileProtocolRequests` -> `NewTemplateExecuter`
receive empty requests + empty flow = nil engine
-> `*TemplateExecuter.{Compile,Execute}` invoked
on nil engine = panic.

RCA:
1. `*ExecutorOptions.ApplyNewEngineOptions`
   overwriting many fields.
2. copy op pointless; create a copy of options and
   then immediately replace it with original
   pointer.
3. missing executable requests validation after
   cached templates is reconstructed with updated
   options.

Thus, this affected `--automatic-scan` mode where
tech detection templates often have conditional
requests that may be filtered based on runtime
options.

Fixes #6417

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

* fix(templates): recompile workflow with `tplCopy.Options`

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

* fix(templates): strengthen cache hit guard

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

* fix(protocols): skips template-specific fields

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

---------

Signed-off-by: Dwi Siswanto <git@dw1.io>
2025-08-23 20:01:23 +05:30