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

fix(multiproto): missing previous InternalEvents output when ExecuteWithResults #5967

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

Conversation

dwisiswant0
Copy link
Member

@dwisiswant0 dwisiswant0 commented Jan 9, 2025

Proposed changes

Close #5748

Proof of Concept

# issue-5748-b.yaml
id: issue-5748-b

info:
  name: issue-5748-b
  author: dwisiswant0
  severity: high

code:
  - engine:
      - sh
      - bash
    source: id

http:
  - raw:
      - |
        GET /1 HTTP/1.1
        Host: {{Hostname}}

      - |
        GET /2 HTTP/1.1
        Host: {{Hostname}}

    extractors:
      - type: dsl
        dsl:
          - 'concat("status_code_1: ", status_code_1)'
          - 'concat("status_code_2: ", status_code_2)'
# digest: 490a0046304402202cd4baf19f0bf2337473efa63e99e086638f4732b283e43e2db30555cee6a09802207ee4b1ad6accfbff9c994531166ff65271211126922beb95dc22d6065f63dfdf:0acbc25bbf526ee86104fe7a57c5a13f
$ ./bin/nuclei -code -u http://scanme.sh -t issue-5748-b.yaml -silent
[issue-5748-c] [http] [high] http://scanme.sh/1 ["status_code_1: 200"]
[issue-5748-c] [http] [high] http://scanme.sh/2 ["status_code_1: 200","status_code_2: 200"]

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
    • Streamlined the result processing mechanism for multi-protocol execution
    • Improved dynamic value management and storage during protocol workflows
    • Enhanced inline function for handling protocol results with more efficient key construction

…teWithResults`

Signed-off-by: Dwi Siswanto <git@dw1.io>
@auto-assign auto-assign bot requested a review from dogancanbakir January 9, 2025 06:04
Copy link

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request modifies the ExecuteWithResults method in the MultiProtocol struct within the pkg/tmplexec/multiproto/multi.go file. The primary change involves replacing the existing multiProtoCallback with an inline function that maintains similar functionality for processing protocol results. The new implementation enhances dynamic value management by using a strings.Builder to construct keys for the previous map, allowing more flexible storage and access of protocol-specific values.

Changes

File Change Summary
pkg/tmplexec/multiproto/multi.go Replaced multiProtoCallback with an inline function in ExecuteWithResults method, improving dynamic value handling and key construction

Assessment against linked issues

Objective Addressed Explanation
DSL Responses for Code Protocol [#5748] Unable to definitively confirm without seeing full implementation details

Possibly related PRs

Suggested reviewers

  • ehsandeep
  • dogancanbakir

Poem

🐰 In the realm of code, where protocols dance,
A rabbit hops through lines with a glance,
Callbacks transformed, keys now bright,
Dynamic values take their flight,
Multiproto magic, a coding romance! 🚀

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.
    • 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.

@dwisiswant0 dwisiswant0 changed the title fix(multiproto): missing previous \InternalEvent\s output when \ExecuteWithResults\ fix(multiproto): missing previous InternalEvents output when ExecuteWithResults Jan 9, 2025
@dwisiswant0 dwisiswant0 requested a review from ehsandeep January 9, 2025 06:08
Copy link

@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/tmplexec/multiproto/multi.go (1)

96-102: Simplify key construction using fmt.Sprintf

Consider using fmt.Sprintf to construct the keys for the previous map. This simplifies the code and enhances readability by eliminating the need for a strings.Builder.

Apply this diff to simplify the key construction:

-				builder := &strings.Builder{}
 				for k, v := range event.InternalEvent {
-					builder.WriteString(ID)
-					builder.WriteString("_")
-					builder.WriteString(k)
-					_ = previous.Set(builder.String(), v)
-					builder.Reset()
+					key := fmt.Sprintf("%s_%s", ID, k)
+					_ = previous.Set(key, v)
 				}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 805cab4 and 957ea7a.

📒 Files selected for processing (1)
  • pkg/tmplexec/multiproto/multi.go (3 hunks)
🔇 Additional comments (6)
pkg/tmplexec/multiproto/multi.go (6)

5-5: Importing the strings package is necessary for key construction

The addition of the strings package is appropriate for string manipulation in the key construction logic.


13-13: Utilizing mapsutil and stringsutil enhances utility functions

Importing mapsutil and stringsutil provides necessary utility functions for map operations and string manipulations.


65-65: Thread-safe initialization of the previous map

Initializing the previous map with mapsutil.NewSyncLockMap[string, any]() ensures thread-safe operations, which is crucial for concurrent executions.


88-134: Effective inline callback to handle protocol results

The inline definition of the callback function within ExecuteWithResults improves code locality and clarity. Passing previous.GetAll() and updating the previous map within the callback effectively manages dynamic values between protocol executions.


108-129: Ensure proper handling of dynamic values with multiple entries

The current logic correctly handles dynamic values when there's more than one value by indexing them. Verify that all necessary cases are covered and that the indexing aligns with expected usage in subsequent protocols.


131-133: Re-evaluating variables after each protocol execution

Re-evaluating and merging the variables into the template context after each protocol ensures that any changes are appropriately reflected in subsequent executions.

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] DSL Responses Do Not Work Properly with Code Protocol
2 participants