Skip to content

fix(headless): incorrect last navigated URL#6278

Merged
ehsandeep merged 3 commits intodevfrom
dwisiswant0/fix/headless/incorrect-last-navigated-URL
Jun 24, 2025
Merged

fix(headless): incorrect last navigated URL#6278
ehsandeep merged 3 commits intodevfrom
dwisiswant0/fix/headless/incorrect-last-navigated-URL

Conversation

@dwisiswant0
Copy link
Member

@dwisiswant0 dwisiswant0 commented Jun 23, 2025

Proposed changes

Fixes #6274

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

  • New Features
    • Improved tracking of the last navigated URL during page navigation and lifecycle events.
  • Refactor
    • Streamlined internal map handling for request processing, resulting in more efficient data merging.

Signed-off-by: Dwi Siswanto <git@dw1.io>
for `ActionNavigate`, `WaitPageLifecycleEvent`, and
`WaitStable` based on latest navigation URL.

Signed-off-by: Dwi Siswanto <git@dw1.io>
@dwisiswant0 dwisiswant0 requested a review from Ice3man543 June 23, 2025 07:41
@auto-assign auto-assign bot requested a review from dogancanbakir June 23, 2025 07:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 23, 2025

Walkthrough

The changes introduce a new mechanism in the headless protocol engine to track and update the last navigated URL after navigation actions. This includes adding a field to the Page struct, updating internal state after navigation events, and refactoring map merging logic in request handling to use the standard library.

Changes

File(s) Change Summary
pkg/protocols/headless/engine/page.go Added lastActionNavigate field to Page; added updateLastNavigatedURL() method.
pkg/protocols/headless/engine/page_actions.go Invoked updateLastNavigatedURL() after navigation events; set lastActionNavigate after navigation.
pkg/protocols/headless/request.go Refactored map merging to use maps.Copy from the standard library.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Page
    participant Instance

    User->>Page: Trigger navigation action
    Page->>Page: Set lastActionNavigate
    Page->>Page: updateLastNavigatedURL()
    Page->>Instance: Update requestLog with final navigated URL
Loading

Assessment against linked issues

Objective Addressed Explanation
Report the final URL (after redirects) in the "matched-at" field for headless protocol (Issue #6274)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Refactor map merging logic to use maps.Copy (pkg/protocols/headless/request.go) This refactor is unrelated to the URL tracking or "matched-at" field objective in #6274.

Suggested reviewers

  • ehsandeep

Poem

In the warren of code, a hop and a leap,
URLs now follow where redirects creep.
No more confusion—matched-at is true,
The final address is reported to you!
With maps now copied in a single bound,
This rabbit ensures the right URLs are found.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60c0d5f and ce2715c.

📒 Files selected for processing (1)
  • pkg/protocols/headless/engine/page.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/protocols/headless/engine/page.go
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (ubuntu-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (macOS-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
pkg/protocols/headless/engine/page.go (2)

279-288: Consider thread safety for the new method.

The updateLastNavigatedURL() method correctly updates the request log mapping. However, consider thread safety concerns since the Page struct has a mutex but this method doesn't use it when accessing p.instance.requestLog.

If requestLog can be accessed concurrently, consider adding synchronization:

 func (p *Page) updateLastNavigatedURL() {
 	if p.lastActionNavigate == nil {
 		return
 	}
 
+	p.mutex.Lock()
+	defer p.mutex.Unlock()
+
 	templateURL := p.lastActionNavigate.GetArg("url")
 	p.instance.requestLog[templateURL] = p.URL()
 }

201-201: Remove commented debug code.

The commented debug print statement should be removed or properly implemented as conditional debug logging.

-		// fmt.Printf("firstItem.RawResponse: %v\n", firstItem.RawResponse)
pkg/protocols/headless/engine/page_actions.go (1)

674-674: Consider potential redundancy in URL state updates.

While updating the URL state after lifecycle events is appropriate, consider if this might result in redundant updates when multiple navigation-related actions are chained together.

The current approach ensures correctness but may result in multiple updates. If performance is a concern, consider debouncing or checking if an update is actually needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c242b11 and 60c0d5f.

📒 Files selected for processing (3)
  • pkg/protocols/headless/engine/page.go (3 hunks)
  • pkg/protocols/headless/engine/page_actions.go (5 hunks)
  • pkg/protocols/headless/request.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint
🔇 Additional comments (6)
pkg/protocols/headless/request.go (2)

193-194: LGTM! Map copying refactored to use standard library.

The refactoring from manual map iteration to maps.Copy is cleaner and more efficient. The behavior remains functionally equivalent while reducing code complexity.


5-5: ```shell
#!/bin/bash

Locate go.mod and extract Go version requirement

find . -maxdepth 2 -name 'go.mod' -print0 | while IFS= read -r -d '' file; do
echo "File: $file"
grep '^go ' "$file" || echo "No Go version specified in $file"
done


</details>
<details>
<summary>pkg/protocols/headless/engine/page.go (1)</summary>

`40-40`: **LGTM! New field for tracking navigation state.**

The `lastActionNavigate` field appropriately tracks the last navigation action for URL state management.

</details>
<details>
<summary>pkg/protocols/headless/engine/page_actions.go (3)</summary>

`81-81`: **LGTM! Correct placement of navigation state tracking.**

Setting `p.lastActionNavigate = act` after successful navigation ensures the state is only updated when navigation succeeds.

---

`417-417`: **LGTM! URL state updated after navigation.**

Calling `updateLastNavigatedURL()` immediately after navigation ensures the request log reflects the current page state.

---

`701-701`: **LGTM! URL state updated after page stabilization.**

Updating the URL state after `WaitStable` is appropriate since page redirects can occur during stabilization.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@ehsandeep ehsandeep merged commit 695a752 into dev Jun 24, 2025
35 of 36 checks passed
@ehsandeep ehsandeep deleted the dwisiswant0/fix/headless/incorrect-last-navigated-URL branch June 24, 2025 00:02
@ehsandeep ehsandeep added this to the nuclei v3.4.6 milestone Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] headless protocol outputs incorrect URL in "matched-at" field for targets with redirects

3 participants