Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Headless protocol accesses flow protocol variables #6003

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

dogancanbakir
Copy link
Member

@dogancanbakir dogancanbakir commented Jan 24, 2025

Proposed changes

Closes #6001

$ go run . -u scanme.sh -t test_template.yaml --headless --debug

                     __     _
   ____  __  _______/ /__  (_)
  / __ \/ / / / ___/ / _ \/ /
 / / / / /_/ / /__/ /  __/ /
/_/ /_/\__,_/\___/_/\___/_/   v3.3.8

                projectdiscovery.io

[INF] Current nuclei version: v3.3.8 (latest)
[INF] Current nuclei-templates version: v10.1.2 (latest)
[WRN] Scan results upload to cloud is disabled.
[INF] New templates added in latest release: 52
[INF] Templates loaded for current scan: 1
[WRN] Loading 1 unsigned templates for scan. Use with caution.
[INF] Targets loaded for current scan: 1
[INF] Running httpx on input host
[INF] Found 1 URL from httpx
[JS] Running http protocol...
[INF] [test] Dumped HTTP request for https://scanme.sh?varFromFlow=works&varFromVariables=works

GET /?varFromFlow=works&varFromVariables=works HTTP/1.1
Host: scanme.sh
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0
Connection: close
Accept: */*
Accept-Language: en
Accept-Encoding: gzip

[DBG] [test] Dumped HTTP response https://scanme.sh?varFromFlow=works&varFromVariables=works

HTTP/1.1 200 OK
Connection: close
Content-Length: 2
Content-Type: text/plain; charset=utf-8
Date: Fri, 24 Jan 2025 08:35:51 GMT

ok
[JS] Running headless protocol...
[INF] [test] Dumped Headless request for https://scanme.sh?varFromFlow=works&varFromVariables=works
[DBG]   navigate => https://scanme.sh?varFromFlow=works&varFromVariables=works
[DBG] [test] Dumped Headless response for https://scanme.sh

<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">ok</pre></body></html>
[INF] No results found. Better luck next time!

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

  • Refactor
    • Updated internal variable handling in the request execution method
    • Renamed variables to improve clarity and consistency in data processing
    • Streamlined merging of variables and metadata in request execution logic

@auto-assign auto-assign bot requested a review from dwisiswant0 January 24, 2025 08:36
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

The changes in the pkg/protocols/headless/request.go file focus on modifying the ExecuteWithResults method's internal logic. The primary modification involves renaming the payloads variable to optionVars and adjusting the variable merging process. This change aims to improve how variables are handled and merged during the execution of headless protocol requests, potentially addressing issues with variable visibility and consistency across different protocol stages.

Changes

File Change Summary
pkg/protocols/headless/request.go - Renamed payloads variable to optionVars
- Modified variable merging logic
- Updated method calls to use new variable naming

Assessment against linked issues

Objective Addressed Explanation
Variables from flow protocol should be visible in headless protocol [#6001]
Resolve inconsistent variable population in headless protocol Requires further testing to confirm complete resolution

Poem

🐰 A rabbit's tale of code so bright,
Variables dancing left and right,
From flow to headless, they now take flight,
With optionVars set just right,
Debugging gremlins put to flight! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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 (1)
pkg/protocols/headless/request.go (1)

85-85: Consider precedence of merged maps
Merging value with vars may cause key collisions. If value is intended to take priority over the global vars, consider swapping the merge order or clarifying the logic to avoid unexpected overwrites.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a0c3075 and c5c1800.

📒 Files selected for processing (1)
  • pkg/protocols/headless/request.go (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Tests (macOS-latest)
  • GitHub Check: Tests (windows-latest)
  • GitHub Check: Tests (ubuntu-latest)
🔇 Additional comments (6)
pkg/protocols/headless/request.go (6)

55-55: Initialize optionVars with user-provided options
Renaming from payloads to optionVars improves clarity. This is a well-structured approach to incorporate the user's runtime options into the request workflow.


58-58: Double-check variable precedence
When merging vars, metadata, optionVars, and template context, be mindful that later maps can overshadow earlier ones. Confirm that the final order of merges reflects the intended precedence.


60-60: Evaluate user variables carefully
Evaluate(vars) can introduce or transform user-supplied data. Verify it correctly processes all variables and handles potential edge cases or security implications, especially if expansions can be influenced by untrusted inputs.


61-61: Confirm final constants ordering
Merging the evaluated variablesMap with request.options.Constants means constants override certain runtime variables. If this is your intended design, the current approach is good to go.


73-73: Validate fuzzing variable usage
When calling executeFuzzingRule, ensure vars contains all necessary flow protocol variables for fuzzing. Any overshadowed or missing keys might reduce the fuzzing effectiveness.


91-91: Confirm necessity of shallow clone
maps.Clone(vars) creates a shallow copy. If you anticipate nested structures or side effects through reference sharing, consider a deeper approach to avoid unintentional mutations.

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 doesn't see variables set in flow protocol.
2 participants