Skip to content

fixing dns vars - #7379

Merged
dogancanbakir merged 3 commits into
devfrom
bugfix-7374-dns-vars
May 6, 2026
Merged

fixing dns vars#7379
dogancanbakir merged 3 commits into
devfrom
bugfix-7374-dns-vars

Conversation

@Mzack9999

@Mzack9999 Mzack9999 commented May 4, 2026

Copy link
Copy Markdown
Member

Proposed changes

Closes #7374

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Bug Fixes
    • DNS client construction now preserves evaluated resolvers and defers unresolved templated entries to runtime, avoiding failures at compile time.
  • Tests
    • Added DNS tests for templated-resolver behavior at compile time and runtime.
  • Refactor
    • Improved JSON GraphQL decoding to better handle pointer fields; migrated map utilities to standard library map helpers.
  • Chores
    • Adjusted a utility generic signature to use a different ordered constraint.

@Mzack9999 Mzack9999 self-assigned this May 4, 2026
@Mzack9999 Mzack9999 added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label May 4, 2026
@auto-assign
auto-assign Bot requested a review from dogancanbakir May 4, 2026 22:06
@neo-by-projectdiscovery-dev

neo-by-projectdiscovery-dev Bot commented May 4, 2026

Copy link
Copy Markdown

Neo - PR Security Review

No security issues found

Comment @pdneo help for available commands. · Open in Neo

@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 38045a25-b305-4ddf-aca1-862c9b142e8c

📥 Commits

Reviewing files that changed from the base of the PR and between 10831d6 and 7926e22.

📒 Files selected for processing (2)
  • internal/runner/runner.go
  • pkg/js/compiler/pool.go

Walkthrough

getDnsClient now builds the resolver list entry-by-entry: templated resolver expressions are evaluated only when runtime metadata (merged with per-request vars) is available, unresolved templated resolvers are skipped at compile time, and the final DNS client uses the preserved evaluated resolver list.

Changes

DNS Template Resolver Resolution

Layer / File(s) Summary
Data Shape / Imports
pkg/protocols/dns/request.go, pkg/fuzz/dataformat/kv.go, pkg/protocols/network/request.go, pkg/utils/utils.go
Replaced golang.org/x/exp/maps with stdlib maps and updated map copy/clone calls; switched generic constraint import from constraints to cmp for MapHash.
Core Logic
pkg/protocols/dns/dns.go
getDnsClient now iterates request.Resolvers to construct a resolvers slice: templated entries are evaluated only when metadata != nil; unresolved templated entries are skipped at compile time; assigns dnsClientOptions.Resolvers = resolvers.
Wiring / Integration
pkg/protocols/dns/request.go
execute now merges per-request vars with metadata (resolverVars := generators.MergeMaps(vars, metadata)) and passes that into request.getDnsClient, enabling runtime resolution from both vars and metadata; map copy usages updated to stdlib maps.
Decoding Pointer Handling
pkg/reporting/trackers/linear/jsonutil/jsonutil.go
GraphQL JSON unmarshaller updated to use reflect.Pointer checks, allocate nil pointer fields, and consistently dereference pointers across object/array decoding paths.
Small Pointer-kind Updates
internal/runner/runner.go, pkg/js/compiler/pool.go
Pointer-kind checks switched from reflect.Ptr to reflect.Pointer and adjusted dereference/unwrapping paths.
Tests
pkg/protocols/dns/dns_test.go
Added TestDNSCompileWithTemplatedResolver (compiling a DNS Request with a templated resolver should not fail and should build a dnsClient) and TestGetDnsClientResolvesTemplatedResolver (runtime resolution of templated resolvers via metadata while preserving static resolvers).

Sequence Diagram(s)

sequenceDiagram
    participant Exec as Request.Execute
    participant Vars as Vars+Metadata Merge
    participant Eval as Template Evaluator
    participant Pool as dnsclientpool.Get
    Exec->>Vars: build resolverVars (vars + metadata)
    Exec->>Eval: evaluate resolvers using resolverVars (skip unresolved if metadata nil)
    Eval-->>Exec: evaluated resolver list
    Exec->>Pool: dnsclientpool.Get(options with evaluated resolvers)
    Pool-->>Exec: dnsClient
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

A little rabbit hopped through code tonight,
Templates and resolvers set to right.
Compile-time skips, runtime lights gleam,
DNS queries chase the variable dream.
Hoppity hops—no more broken scheme! 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fixing dns vars' is vague and does not clearly convey what DNS variable-related issue is being fixed. Use a more descriptive title that specifies the core fix, such as 'Fix DNS resolver expression evaluation with template variables' or 'Support variable resolution in DNS resolver config'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #7374 by fixing the DNS resolver expression evaluation to support template variables and expressions in resolver configuration.
Out of Scope Changes check ✅ Passed All changes are scope-appropriate: DNS resolver handling fixes, supporting test cases, and related import updates to use stdlib maps package instead of exp/maps.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix-7374-dns-vars

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/protocols/dns/dns_test.go (1)

93-98: 💤 Low value

Test verifies success but not the resolved resolver values.

The test comment mentions covering "the bug where a static resolver placed alongside a templated one used to be dropped," but the assertions only check that no error occurred and the client is non-nil. Consider adding verification that the resulting client's resolver configuration contains both "1.1.1.1" (resolved) and "8.8.8.8" (static).

That said, this would require exposing internal state or refactoring getDnsClient to return the resolved list. If that's not straightforward, the current test still provides value as a regression guard for the happy path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/protocols/dns/dns_test.go` around lines 93 - 98, Update the test that
calls request.getDnsClient to assert the resolved resolver configuration
includes both the templated value "1.1.1.1" and the static "8.8.8.8": either (A)
if the returned client exposes resolver info (e.g., a Resolvers field or method
on the client object), add require.Contains/require.ElementsMatch assertions
against client.Resolvers for "1.1.1.1" and "8.8.8.8", or (B) if it does not,
refactor getDnsClient to also return the resolved slice (or provide an accessor)
and then assert the returned/resolved list contains both entries; reference
getDnsClient and the "test_resolver" input map when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/protocols/dns/dns_test.go`:
- Around line 93-98: Update the test that calls request.getDnsClient to assert
the resolved resolver configuration includes both the templated value "1.1.1.1"
and the static "8.8.8.8": either (A) if the returned client exposes resolver
info (e.g., a Resolvers field or method on the client object), add
require.Contains/require.ElementsMatch assertions against client.Resolvers for
"1.1.1.1" and "8.8.8.8", or (B) if it does not, refactor getDnsClient to also
return the resolved slice (or provide an accessor) and then assert the
returned/resolved list contains both entries; reference getDnsClient and the
"test_resolver" input map when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f456555-9414-46a1-a17c-52ab9a2d3840

📥 Commits

Reviewing files that changed from the base of the PR and between a4da890 and 637036e.

📒 Files selected for processing (3)
  • pkg/protocols/dns/dns.go
  • pkg/protocols/dns/dns_test.go
  • pkg/protocols/dns/request.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/protocols/dns/request.go (1)

178-184: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Trace path still uses request.dnsClient (compile-time client).

request.dnsClient is the client built at compile time, where templated resolvers were skipped (per dns.go's deferred-resolution logic). When request.Resolvers contains template expressions, Trace will run against a client built without the user's intended resolvers (potentially the system default), even though the main dns.Do call at line 163 correctly uses the locally-rebuilt dnsClient.

Consider using the locally resolved dnsClient for tracing as well:

♻️ Proposed change
-		traceData, err = request.dnsClient.Trace(domain, request.question, request.TraceMaxRecursion)
+		traceData, err = dnsClient.Trace(domain, request.question, request.TraceMaxRecursion)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/protocols/dns/request.go` around lines 178 - 184, The trace path
incorrectly calls request.dnsClient (the compile-time client) so when
request.Resolvers contains templates it uses the wrong resolver set; update the
Trace call to use the locally-built dnsClient used by dns.Do (the same variable
you build before calling dns.Do) instead of request.dnsClient so trace runs
against the resolved runtime client (replace request.dnsClient.Trace(...) with
dnsClient.Trace(...) and ensure dnsClient is in scope when request.Trace is
true).
🧹 Nitpick comments (1)
pkg/reporting/trackers/linear/jsonutil/jsonutil.go (1)

66-66: 💤 Low value

Unrelated scope — reflect.Ptrreflect.Pointer modernization in a PR titled "fixing dns vars".

reflect.Pointer is just an alias for reflect.Ptr (added in Go 1.18), so the change is behavior-preserving and safe. However, it's unrelated to the DNS resolver fix described in the PR objective and issue #7374 — consider splitting unrelated cleanups into their own PR to keep review surface focused. Not blocking.

Also applies to: 96-96, 126-126, 170-170, 179-179, 201-201, 206-206

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/reporting/trackers/linear/jsonutil/jsonutil.go` at line 66, The PR
includes unrelated modernization changes replacing reflect.Ptr with
reflect.Pointer in pkg/reporting/trackers/linear/jsonutil/jsonutil.go (several
occurrences) which should be split out; revert those reflect.Pointer edits back
to reflect.Ptr here (or move them into a separate cleanup PR) so this PR only
contains the DNS resolver fix—search for uses of reflect.Pointer in this file
and replace them with reflect.Ptr to keep this change focused.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/protocols/dns/request.go`:
- Around line 178-184: The trace path incorrectly calls request.dnsClient (the
compile-time client) so when request.Resolvers contains templates it uses the
wrong resolver set; update the Trace call to use the locally-built dnsClient
used by dns.Do (the same variable you build before calling dns.Do) instead of
request.dnsClient so trace runs against the resolved runtime client (replace
request.dnsClient.Trace(...) with dnsClient.Trace(...) and ensure dnsClient is
in scope when request.Trace is true).

---

Nitpick comments:
In `@pkg/reporting/trackers/linear/jsonutil/jsonutil.go`:
- Line 66: The PR includes unrelated modernization changes replacing reflect.Ptr
with reflect.Pointer in pkg/reporting/trackers/linear/jsonutil/jsonutil.go
(several occurrences) which should be split out; revert those reflect.Pointer
edits back to reflect.Ptr here (or move them into a separate cleanup PR) so this
PR only contains the DNS resolver fix—search for uses of reflect.Pointer in this
file and replace them with reflect.Ptr to keep this change focused.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed2c2431-f6b2-4410-91ce-7a2887b42435

📥 Commits

Reviewing files that changed from the base of the PR and between 637036e and 10831d6.

📒 Files selected for processing (5)
  • pkg/fuzz/dataformat/kv.go
  • pkg/protocols/dns/request.go
  • pkg/protocols/network/request.go
  • pkg/reporting/trackers/linear/jsonutil/jsonutil.go
  • pkg/utils/utils.go

@dogancanbakir
dogancanbakir merged commit 7148ff9 into dev May 6, 2026
20 checks passed
@dogancanbakir
dogancanbakir deleted the bugfix-7374-dns-vars branch May 6, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Can't use expressions/variables in DNS resolver config

2 participants