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: URL parsing with lists & -scan-all-ips #5897

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

p-l-
Copy link
Contributor

@p-l- p-l- commented Dec 10, 2024

Proposed changes

For some reason, the cleaned (with strings.TrimSpace()) value URL is not used when -scan-all-ips is provided.

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

    • Improved input handling consistency in the ListInputProvider.
    • Enhanced error handling for DNS resolution failures and empty hostname checks.
  • New Features

    • Updated methods to ensure consistent assignment of input fields during set and delete operations.

@auto-assign auto-assign bot requested a review from dogancanbakir December 10, 2024 22:40
Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes made in the pkg/input/provider/list/hmap.go file primarily involve modifications to the ListInputProvider class. The Set and Del methods have been updated to ensure that the Input field of the metaInput object is assigned the trimmed URL variable, enhancing consistency in input handling. Additionally, error handling related to DNS resolution and empty hostname checks has been refined, while logging statements remain intact to provide operational feedback.

Changes

File Path Change Summary
pkg/input/provider/list/hmap.go Updated Set and Del methods to assign trimmed URL to metaInput.Input. Refined error handling for DNS resolution and empty hostnames. Logging statements preserved.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ListInputProvider
    participant MetaInput

    User->>ListInputProvider: Set(value)
    ListInputProvider->>MetaInput: Set Input to trimmed URL
    ListInputProvider->>User: Operation feedback (success or error)

    User->>ListInputProvider: Del(value)
    ListInputProvider->>MetaInput: Set Input to trimmed URL
    ListInputProvider->>User: Operation feedback (success or error)
Loading

🐇 "In the code where inputs play,
A trim and check now lead the way.
With logs to share what’s done and said,
Consistent paths where inputs tread.
A hop, a skip, through code we go,
Enhancing flows, making them glow!" 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Experiment)
  • @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

🧹 Outside diff range and nitpick comments (1)
pkg/input/provider/list/hmap.go (1)

Line range hint 187-194: Consider enhancing error handling and logging

While the core functionality is correct, consider the following improvements:

  1. Make error messages more specific and structured
  2. Consider downgrading some Warning logs to Debug level
  3. Add structured logging fields for better filtering

Example improvement:

-gologger.Debug().Msgf("scanAllIps: dns resolution failed: %v", err)
+gologger.Debug().
+    Str("url", URL).
+    Str("error", err.Error()).
+    Msg("scan-all-ips: DNS resolution failed")

-gologger.Warning().Msgf("target does not have ipv6 address falling back to ipv4 %v\n", err)
+gologger.Debug().
+    Str("url", URL).
+    Str("error", err.Error()).
+    Msg("IPv6 not available, falling back to IPv4")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c731126 and e35ca70.

📒 Files selected for processing (1)
  • pkg/input/provider/list/hmap.go (1 hunks)
🔇 Additional comments (2)
pkg/input/provider/list/hmap.go (2)

Line range hint 32-38: Verify DNS resolution timeout handling

The DNS resolution in scan-all-ips mode could potentially lead to timeouts or hanging. Consider:

  1. Adding explicit timeouts for DNS resolution
  2. Implementing retry logic with backoff
  3. Adding metrics for DNS resolution failures

Let's check for existing timeout implementations:

Also applies to: 187-194

✅ Verification successful

Let me analyze the DNS resolution implementation further by checking the dialer configuration.


DNS resolution timeout is properly implemented

The DNS resolution is handled by fastdialer with appropriate timeout configurations:

  1. Default dial timeout is set to 10 seconds and can be customized
  2. The timeout is propagated through the dialer chain:
    • Base dial timeout is configured in types.Timeouts
    • Fastdialer uses this timeout for DNS operations
    • Context cancellation is properly implemented for timeout handling

The implementation has proper timeout handling and does not require additional safeguards.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check DNS resolution timeout handling
# Look for timeout configurations and DNS resolution patterns

# Search for DNS timeout configurations
rg -B 5 -A 5 "GetDNSData"

# Search for context usage with DNS
rg -U "(?s)context.*?GetDNSData"

Length of output: 69592


Script:

#!/bin/bash
# Check DNS resolution timeout configuration in dialer

# Search for DNS timeout configurations in dialer
rg -B 5 -A 5 "fastdialer.*New"

# Search for DNS timeout related configurations
rg -B 2 -A 2 "DNSTimeout|DialTimeout|DialerTimeout"

Length of output: 3569


187-187: LGTM: Consistent usage of cleaned URL value

The change correctly uses the cleaned URL value (URL) instead of potentially uncleaned input, ensuring consistency with the URL cleaning done at the start of the method.

Let's verify the URL cleaning behavior across the codebase:

✅ Verification successful

Let me gather more information about the URL cleaning behavior by checking the code around this change.


Let me check the context around the specific line in question to understand the full scope of the change.


Based on the code context, I can now provide a final response:

LGTM: URL cleaning behavior is consistent

The change at line 187 using the cleaned URL value (URL) in metaInput.Input is correct and consistent with the codebase's URL handling pattern. The code shows that:

  1. URL cleaning via strings.TrimSpace() is consistently applied in all input handling methods (Set, SetWithExclusions, Del)
  2. The cleaned URL is used consistently for both regular inputs and when scan-all-ips is enabled
  3. The same cleaned URL value is used for all derived meta inputs (with different IPs)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent URL cleaning patterns
# Look for other instances where TrimSpace might be missing

# Search for URL assignments without TrimSpace
rg -U "(?s)(func.*?\{.*?URL\s*:=\s*[^T][^\n]*?\n)" 

# Search for direct value usage without cleaning
rg "metaInput\.Input\s*=\s*[^U][^\n]*$"

Length of output: 106446


Script:

#!/bin/bash
# Look for URL cleaning patterns in the file
rg -A 5 -B 5 "URL\s*:=\s*strings\.TrimSpace" pkg/input/provider/list/hmap.go

# Look for URL variable assignments and usage
rg -A 5 -B 5 "URL\s*:=.*$" pkg/input/provider/list/hmap.go

Length of output: 1615


Script:

#!/bin/bash
# Look for the context around line 187 in the file
rg -A 10 -B 10 "metaInput\.Input\s*=\s*URL" pkg/input/provider/list/hmap.go

Length of output: 3871

@GeorginaReeder
Copy link

Thanks so much for your contribution @p-l- ! :)

@p-l-
Copy link
Contributor Author

p-l- commented Dec 11, 2024

Is there a reason why all the tests fail @GeorginaReeder? Is it related to this change?

@ehsandeep ehsandeep requested review from Mzack9999 and removed request for dogancanbakir December 20, 2024 10:45
@ehsandeep ehsandeep merged commit ba253dc into projectdiscovery:dev Dec 20, 2024
17 of 18 checks passed
@p-l- p-l- deleted the fix-url-list-scanallips branch December 23, 2024 16:17
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.

4 participants