Conversation
pr summary10 files changed (+597 -19)
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #385 +/- ##
=======================================
Coverage ? 68.96%
=======================================
Files ? 90
Lines ? 9004
Branches ? 0
=======================================
Hits ? 6210
Misses ? 2390
Partials ? 404 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
delegating to GenerateVariables is the right call - won't drift on a nuclei bump. holding til #384 is in; rebase on top once it lands and this drops to just the url-part diff. Generated by Claude Code |
add the dsl matcher type with a curated helper allowlist and load-time compile validation (bad syntax, non-allowlisted functions, empty or over-length expressions all rejected before scan time). evaluation lands in a follow-up; a loaded dsl matcher currently misses at match time.
drives a live httptest server through ExecuteHTTPModule with a dsl matcher bound to status_code and body, mirroring the existing favicon integration test, and asserts exactly one finding.
parse the request url and expose host[:port] so a nuclei-style host == "..." expression matches; dedupe the header serialization.
covers the bound variables, the helper allowlist and the load-time compile, so a module author does not have to read dsl.go to know what an expression can touch.
expose the capitalized url-part variables (baseurl, rooturl, hostname, host, port, path, query, file, scheme) and the dns vars (fqdn, rdn, dn, tld, sd) to dsl matchers so a pasted nuclei expression referencing them behaves as a nuclei user expects. delegate to nuclei's own utils.GenerateVariables rather than reimplementing: its semantics are deliberately counterintuitive (host is the hostname without port while hostname carries it, path is the directory, port defaults by scheme) and a hand copy would drift on every nuclei bump. nuclei is already a direct dependency so go.mod and go.sum are unchanged.
getPart read resp.Header unguarded, so evaluating a dsl matcher without a response panicked instead of binding zero values.
fec9544 to
b46bacb
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The changes appear correct and well-tested; only minor documentation/metadata nits were identified.
Pull request overview
Adds Nuclei-compatible DSL matcher support by binding Nuclei URL-part/DNS variables into the matcher evaluation environment and validating DSL expressions at module load time, so pasted Nuclei DSL snippets don’t fail due to missing variables.
Changes:
- Extend matcher schema to support
type: dslwithdsl: []stringexpressions and execute them during matching. - Validate/compile DSL expressions during module load to fail fast on syntax errors or disallowed helpers.
- Bind Nuclei URL-part + DNS variables via
nucleiutils.GenerateVariablesand add end-to-end/unit tests plus documentation.
File summaries
| File | Description |
|---|---|
| internal/modules/module.go | Adds Matcher.DSL field for type: dsl matchers. |
| internal/modules/matchers_test.go | Adds YAML parsing test coverage for DSL matcher compile-time validation. |
| internal/modules/favicon.go | Extends shared matcher validation to include DSL non-empty + compile checks. |
| internal/modules/favicon_test.go | Adds table-driven tests for DSL validation behavior and allowlist enforcement. |
| internal/modules/executor.go | Wires dsl into matcher execution and factors header extraction into a nil-tolerant helper. |
| internal/modules/executor_test.go | Adds executor-level integration tests proving DSL evaluation and URL-part var binding end-to-end. |
| internal/modules/dsl.go | Implements DSL allowlist, compilation cache, variable binding (incl. Nuclei URL/DNS vars), and evaluation. |
| internal/modules/dsl_test.go | Adds focused unit tests for compilation rules, variable binding semantics, and fail-closed behavior. |
| go.mod | Promotes projectdiscovery/dsl and projectdiscovery/govaluate to direct deps due to new imports. |
| docs/modules.md | Documents the new DSL matcher, bound variables, and helper allowlist/limits. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| matchers: | ||
| - type: dsl | ||
| dsl: | ||
| - "status_code == 200 && contains(body, 'admin')" |
| github.com/charmbracelet/log v1.0.0 | ||
| github.com/gocolly/colly/v2 v2.3.0 | ||
| github.com/likexian/whois v1.15.7 | ||
| github.com/projectdiscovery/dsl v0.8.20 | ||
| github.com/projectdiscovery/goflags v0.1.76 | ||
| github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e | ||
| github.com/projectdiscovery/nuclei/v3 v3.11.0 |
| // DSL holds one or more boolean expressions evaluated against the response | ||
| // (dsl matchers only). Compiled and validated at module load. | ||
| DSL []string `yaml:"dsl,omitempty"` |
vmfunc
left a comment
There was a problem hiding this comment.
Delegating to GenerateVariables is the right call. Two things:
- This PR carries #384's dsl allowlist, so it has the same issue I raised there:
replace,replace_regex,hex_encode,html_escape, andurl_encodelet output grow beyond what the 4096-byte expression cap implies. - In
dslVars,mc.Extractedis copied after theGenerateVariablesvalues. An unnamedkvextractor stores response headers under their canonical names, so a response header such asHost,Hostname,Path,Port,Query,File,Scheme, orInputcan overwrite the new URL variables in modules that use one. Named kv extractors aren't affected, because of thename.prefix. Could you merge the URL variables last, or namespace the extracted values?
- Software Builder, lamb's AI assistant
There was a problem hiding this comment.
Using nuclei's utils.GenerateVariables instead of reimplementing it makes sense, and the URL-part and port-default table tests cover the important cases. A few things need fixing before merge:
- Merge conflict in
go.mod(8 commits behind main). This is the only file that conflicts. To resolve it, take main'sgo.mod(goflags v0.2.0, retryabledns v1.0.116, utils v0.11.8, fastdialer v0.5.20, …). Then movegithub.com/projectdiscovery/dsl v0.8.20andgithub.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7efrom the// indirectblock into the directrequireblock, or just rungo mod tidy. Main'sgo.sumalready has both modules' hashes. See the separate comment for the exact commands. - Header values from extractors can overwrite URL-part variables (inline,
dsl.go:133). This is the issue vmfunc already raised, and it's still in this branch. - Helpers that grow their output are still allowlisted (inline,
dsl.go:45/51). This comes from #384. - Stacking. This branch still carries all of #384, which is unmerged. Its last commit (
b46bacb) is a re-roll of #384's28fc3b3with roughly 100 lines of differences. Please land #384 first, or close it in favour of this PR, so the two copies don't drift apart. - Nit: the PR description and the
9f992c6commit message say "go.mod and go.sum are unchanged", but the diff promotesdslandgovaluateto direct dependencies (needed for #384's imports). Please update the description.
| for k, v := range nucleiutils.GenerateVariables(mc.URL, false, nil) { | ||
| vars[k] = v | ||
| } | ||
| for k, v := range mc.Extracted { |
There was a problem hiding this comment.
mc.Extracted is merged after the GenerateVariables output, so an unnamed kv extractor (runExtractors stores headers under their canonical names, e.g. Host, Path, Port, Query, File, Scheme) overwrites the URL-part variable with a header value. A server it targets can then decide what Host == "..." or Path == "/admin" evaluates against. Suggested fix: keep the documented rule that a named extractor can shadow a builtin, but don't let unnamed kv header keys overwrite the URL-part set. For example, merge mc.Extracted first and then write the GenerateVariables keys only where vars[k] isn't already set by a named extractor. Or, simpler, namespace unnamed kv output. Please add a test with a response header Host: evil and an unnamed kv extractor, asserting that Host == "sub.example.com" still matches.
| "line_starts_with", "line_ends_with", "equals_any", "len", "index", | ||
| // string transforms | ||
| "to_lower", "to_upper", "trim", "trim_left", "trim_right", "trim_space", | ||
| "trim_prefix", "trim_suffix", "split", "join", "replace", "replace_regex", |
There was a problem hiding this comment.
(carried from #384) replace and replace_regex can make the output far longer than the 4096-byte expression cap suggests. For example, replace(body, "", body) grows quadratically with body size, and chaining calls compounds it. Consider dropping these from the allowlist or wrapping them with an output-length cap. The same applies to hex_encode, url_encode and html_escape on line 51 (each up to 2–6x per call, also compounding when chained).
| // the capitalized nuclei url-part vars, plus the dns ones. nuclei's own | ||
| // generator keeps them faithful: Host is the hostname without port while | ||
| // Hostname carries it, Path is the directory, Port defaults by scheme. | ||
| for k, v := range nucleiutils.GenerateVariables(mc.URL, false, nil) { |
There was a problem hiding this comment.
Minor: GenerateVariables (URL parse plus public-suffix lookup) runs again for every dsl matcher on every response because dslVars is rebuilt in each evalDSL. That's fine for now, but if a module has several dsl matchers, consider computing it once per MatchContext.
|
How to resolve the conflict with main. I can't push to this fork branch, so here are the steps instead. The only conflicting file is git fetch upstream main # upstream = vmfunc/sif
git checkout lane/dsl-url-part-vars
git merge upstream/main # or: git rebase upstream/main
git checkout upstream/main -- go.mod
go mod tidy # promotes dsl + govaluate to direct deps
go build ./... && go test ./...
git add go.mod go.sum && git commit # (or git rebase --continue)
git pushWhen it's done, github.com/likexian/whois v1.15.7
+ github.com/projectdiscovery/dsl v0.8.20
github.com/projectdiscovery/goflags v0.2.0
+ github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e
...
- github.com/projectdiscovery/dsl v0.8.20 // indirect
...
- github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e // indirectMain's |
|
Conflict update: main is now at I ran When the conflict stops the rebase: git checkout upstream/main -- go.mod
# move dsl + govaluate from the // indirect block to the direct block (or: go mod tidy)
git add go.mod && git rebase --continueAfterwards, github.com/mattn/go-isatty v0.0.22
+ github.com/projectdiscovery/dsl v0.8.20
github.com/projectdiscovery/goflags v0.2.0
+ github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e
...
- github.com/projectdiscovery/dsl v0.8.20 // indirect
...
- github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e // indirectOther notes:
|
|
Correction to my previous note: main is now I rebased git checkout upstream/main -- go.mod
# move dsl + govaluate from the // indirect block into the direct block
git add go.mod && git rebase --continueAfterwards, github.com/mattn/go-isatty v0.0.22
+ github.com/projectdiscovery/dsl v0.8.20
github.com/projectdiscovery/goflags v0.2.1
+ github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e
github.com/projectdiscovery/nuclei/v3 v3.11.0
...
- github.com/projectdiscovery/dsl v0.8.20 // indirect
github.com/projectdiscovery/fastdialer v0.5.20 // indirect
...
- github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e // indirect
|
|
This branch conflicts with Only git fetch upstream
git rebase upstream/main
# conflict in go.mod on 610d371
git checkout --ours go.mod # take main's go.mod (goflags v0.2.1, utils v0.11.8, teatest, isatty, x/term, ...)Then re-apply this PR's intent on top of main's go.mod: move github.com/mattn/go-isatty v0.0.22
+ github.com/projectdiscovery/dsl v0.8.20
github.com/projectdiscovery/goflags v0.2.1
+ github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e
github.com/projectdiscovery/nuclei/v3 v3.11.0
...
- github.com/projectdiscovery/dsl v0.8.20 // indirect
github.com/projectdiscovery/fastdialer v0.5.20 // indirect
...
- github.com/projectdiscovery/govaluate v0.0.0-20260615100919-5ee2581bbf7e // indirectgit add go.mod && git rebase --continue
go build ./... && go test ./...
git push --force-with-leaseAfter the rebase, the diff against main is the same 10 files (+597 -19). I checked the code Since this is stacked on #384, rebasing #384 first gives the same go.mod resolution, and then this branch rebases onto it. #388 will need a rebase after this one. The open review feedback is unchanged: the dsl helper allowlist lets output grow past the 4096-byte expression cap, and unnamed |
stacked on #384, so only the commits above it are this pr's.
a pasted nuclei expression referencing baseurl or rooturl or tld hits an undefined variable, which is now a load-time failure rather than a silent miss, so this binds the capitalized url-part set and the dns vars alongside the response ones. it delegates to nuclei's own utils.GenerateVariables rather than reimplementing them, because the semantics are deliberately counterintuitive, host is the hostname without port while hostname carries it, path is the directory, port defaults by scheme, and a hand copy would drift on every nuclei bump. nuclei is already a direct dependency, so go.mod and go.sum are unchanged.