fix(runner): split comma-separated targets from -l file and stdin (#859)#953
fix(runner): split comma-separated targets from -l file and stdin (#859)#953TheAuroraAI wants to merge 2 commits intoprojectdiscovery:mainfrom
Conversation
…ojectdiscovery#859) The -u flag accepts comma-separated hosts via CommaSeparatedStringSliceOptions, but the file-based -l (and stdin) path fed each raw line to processInputItem as a single string. A line like '192.168.1.0/24,192.168.2.0/24' was treated as one invalid host, producing: [WRN] Could not connect input 192.168.1.0/24,192.168.2.0/24:443 ... could not dial address <- no address found for host Fix: when reading lines from the input file or stdin, split each line on commas and trim whitespace before forwarding to processInputItem, so that the two input methods behave identically. A new table-driven unit test verifies that both entries are queued when the input file contains a comma-separated line. Fixes projectdiscovery#859. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Neo - PR Security ReviewNo security issues found Highlights
Hardening Notes
Comment |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe runner now splits comma-separated targets on each input line (from files and STDIN), trims whitespace, filters empties, and queues each item individually via a new helper, instead of treating the whole line as one input. Control flow and error handling otherwise unchanged. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/runner/runner.go (1)
443-448: Consider extracting duplicated comma-split logic into a helper.The same splitting logic appears in both the file and stdin paths. Extracting it improves maintainability.
♻️ Suggested helper extraction
+// processLineWithCommaSeparatedTargets splits a line by comma and queues each non-empty item. +func (r *Runner) processLineWithCommaSeparatedTargets(text string, inputs chan taskInput) { + for _, item := range strings.Split(text, ",") { + if item = strings.TrimSpace(item); item != "" { + r.processInputItem(item, inputs) + } + } +}Then replace both occurrences:
if text != "" { - // Support comma-separated targets on a single line, matching the -u flag behaviour. - for _, item := range strings.Split(text, ",") { - if item = strings.TrimSpace(item); item != "" { - r.processInputItem(item, inputs) - } - } + r.processLineWithCommaSeparatedTargets(text, inputs) }Also applies to: 457-462
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/runner/runner.go` around lines 443 - 448, Duplicate comma-splitting + trimming logic should be extracted into a small helper method on the runner (e.g., r.splitAndProcessInput or r.processCommaSeparatedInputs) that takes the raw text and the inputs collection, performs strings.Split(text, ","), trims each item, skips empties, and calls r.processInputItem(item, inputs) for each; replace both occurrences (the file path handling and the stdin handling) with calls to this new helper so the behavior is identical and maintenance is centralized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/runner/runner_test.go`:
- Around line 433-436: Rename the test function
Test_CommaSeperatedInputList_normalizeAndQueueInputs to
Test_CommaSeparatedInputList_normalizeAndQueueInputs and update the leading
comment text to use "Separated" instead of "Seperated" so both the function name
and its comment read "Separated" (ensure you update every occurrence, including
the test declaration and the comment that begins "//
Test_CommaSeperatedInputList_normalizeAndQueueInputs ...").
---
Nitpick comments:
In `@internal/runner/runner.go`:
- Around line 443-448: Duplicate comma-splitting + trimming logic should be
extracted into a small helper method on the runner (e.g., r.splitAndProcessInput
or r.processCommaSeparatedInputs) that takes the raw text and the inputs
collection, performs strings.Split(text, ","), trims each item, skips empties,
and calls r.processInputItem(item, inputs) for each; replace both occurrences
(the file path handling and the stdin handling) with calls to this new helper so
the behavior is identical and maintenance is centralized.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a184f78e-9e53-46d6-bb21-f499b77b6fcb
📒 Files selected for processing (2)
internal/runner/runner.gointernal/runner/runner_test.go
- Rename Test_CommaSeperatedInputList → Test_CommaSeparatedInputList (typo fix) - Extract processCommaSeparatedTargets helper to deduplicate comma-split logic from file and stdin reading paths
|
Hi @dogancanbakir — this PR adds comma-separated target support to the -l flag, matching the -u flag behavior. Neo security review shows no issues. Would appreciate a review! |
Summary
The
-uflag accepts comma-separated hosts natively viagoflags.CommaSeparatedStringSliceOptions. The-lfile path (and stdin) did not: every raw line was handed directly toprocessInputItem, so a file containing192.168.1.0/24,192.168.2.0/24was treated as a single, invalid host:Fixes #859.
Root cause
normalizeAndQueueInputsreads the file (and stdin) line-by-line and callsprocessInputItem(text, inputs)on the full raw line. There was no splitting step.The
-upath goes throughgoflags.CommaSeparatedStringSliceOptionswhich splits at flag-parse time, so the runner never sees the commas.Fix
After reading each line from the file / stdin, split on
,and trim whitespace before forwarding toprocessInputItem. This makes the two input methods behave identically.The same fix is applied to both the file path and the stdin path.
Test
Added
Test_CommaSeperatedInputList_normalizeAndQueueInputswhich writes a temporary file with a single comma-separated line, runsnormalizeAndQueueInputs, and asserts that both hosts are queued individually.Summary by CodeRabbit
New Features
Tests