Repository navigation
feat(runner): machine-readable source listing with -ls -oJ - #1812
Conversation
The -ls listing only prints source names with "*"/"~" markers, which is awkward for automation that wants to pick sources by property (key-less, recursive, default). When -ls is combined with -oJ, emit one JSON object per source with its name, default, recursive and keyRequirement fields. The default human-readable listing is unchanged. Add tests covering the metadata builder and the JSONL writer.
Walkthrough
ChangesJSON source listing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
Just curious, what is your use-case for this? Are you trying to filter the one not requiring keys? |
|
Hey @dogancanbakir ! Basically yes, it's to enable automated source selection. The main use-case is this: When you want to integrate subfinder into a pipeline or script, you want to be able to: Automatically filter sources that don't require keys (for enumeration runs without API credentials) For example, with JSONL you can easily do: Whereas with the current format (-ls alone) it's pretty awkward to automate since you're mixing markers (*, ~) with names. It's not just about keys—it's about treating sources as structured data instead of human-readable text. Useful for CI/CD, scripting, integrations... basically anything that needs to be predictable and machine-readable. |
|
@coderabbitai create an issue to track this pr |
Fold the source metadata emitter back into listSources instead of a separate file: the exported SourceInfo type had no consumer, and sorting AllSources (a compile-time array, already alphabetical) only made the JSON order differ from the human-readable listing. Drops the accompanying tests, which re-derived the struct from the same interface calls and asserted that json.Encoder emits JSON.
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
repo="projectdiscovery/subfinder"
pr_number="1812"
requester="dogancanbakir"
pr_url="https://github.com/${repo}/pull/${pr_number}"
comment_url="$(
gh api --paginate "repos/${repo}/issues/${pr_number}/comments" \
--jq '.[] | select(.user.login == "dogancanbakir" and (.body | contains("`@coderabbitai` create an issue to track this pr"))) | .html_url' \
| head -n 1
)"
body=$(cat <<EOF
## Summary
Track the addition and adoption of machine-readable source metadata for \`subfinder -ls -oJ\`.
The linked pull request adds JSONL output containing source \`name\`, \`default\`, \`recursive\`, and \`keyRequirement\` metadata, while preserving the current human-readable \`-ls\` output.
## Rationale
Structured source metadata lets scripts, CI/CD pipelines, and integrations reliably select sources—for example, sources that need no API key or sources that support recursive enumeration—without parsing human-oriented markers.
## Affected areas
- \`pkg/runner/listsources.go\`
- \`pkg/runner/options.go\`
- \`pkg/runner/listsources_test.go\`
- \`README.md\`
## Acceptance criteria
- [ ] \`subfinder -ls -oJ\` emits one valid JSON object per line.
- [ ] Each object exposes \`name\`, \`default\`, \`recursive\`, and \`keyRequirement\`.
- [ ] Source records are deterministically sorted by name.
- [ ] Existing human-readable \`subfinder -ls\` output remains unchanged.
- [ ] Source-list JSON output is covered by automated tests and documented.
## Backlinks
- Pull request: ${pr_url}
- Request from @${requester}: ${comment_url:-"${pr_url}`#issuecomment-unavailable`"}
EOF
)
gh issue create \
--repo "$repo" \
--title "Track machine-readable source metadata for subfinder -ls -oJ" \
--body "$body" \
--assignee "$requester"Length of output: 1972
You are interacting with an AI system. |
|
@Gerijacki Thanks for the reply and PR! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/runner/options.go (1)
232-256: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd regression coverage for the JSONL contract.
Please add or restore focused tests asserting one JSON object per line, the required fields and key labels, and deterministic source ordering. This output is intended for scripts and integrations, so these tests should guard the contract before future source changes silently break consumers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/runner/options.go` around lines 232 - 256, Add focused regression tests for listSources with JSON output enabled, asserting exactly one JSON object per line, presence of name/default/recursive/keyRequirement fields with the expected key labels, and deterministic ordering matching passive.AllSources. Reuse the existing options/output test helpers and cover the JSONL contract without changing non-JSON behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/runner/options.go`:
- Around line 232-256: Add focused regression tests for listSources with JSON
output enabled, asserting exactly one JSON object per line, presence of
name/default/recursive/keyRequirement fields with the expected key labels, and
deterministic ordering matching passive.AllSources. Reuse the existing
options/output test helpers and cover the JSONL contract without changing
non-JSON behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: dbd136f3-752a-447f-b25d-7e5142beb99c
📒 Files selected for processing (2)
README.mdpkg/runner/options.go
🚧 Files skipped from review as they are similar to previous changes (1)
- README.md
subfinder 2.15.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## What's Changed ### 🎉 New Features * Added shodanct passive source by @dogancanbakir in projectdiscovery/subfinder#1796 * Added Option `-vR`, `-virustotal-res` for VirusTotal source by @Bundy01 in projectdiscovery/subfinder#1719 * Added machine-readable source listing with `-ls -oJ` by @Gerijacki in projectdiscovery/subfinder#1812 ### 🐞 Bug Fixes * Fixed source leaks by @Mzack9999 in projectdiscovery/subfinder#1801 * Fixed drain source channels on cancel so source goroutines exit instead of leaking on a blocked send by @Mzack9999 in projectdiscovery/subfinder#1799 * Fixed crtsh's query by dropping unused certificate metadata from SQL query by @ChrisJr404 in projectdiscovery/subfinder#1787 * Fixed VirusTotal source by capping pagination and providing clearer 429 message by @ChrisJr404 in projectdiscovery/subfinder#1788 * Fixed Anubis source by switching subdomain API to anubisdb.com by @jatinder14 in projectdiscovery/subfinder#1815 ### Other Changes * Fixed lint issues by @dogancanbakir in projectdiscovery/subfinder#1820 * Refactored loadFromFile to use bufio.Scanner by @nandaanomi in projectdiscovery/subfinder#1791 ## New Contributors * @ChrisJr404 made their first contribution in projectdiscovery/subfinder#1787 * @Bundy01 made their first contribution in projectdiscovery/subfinder#1719 * @nandaanomi made their first contribution in projectdiscovery/subfinder#1791 * @jatinder14 made their first contribution in projectdiscovery/subfinder#1815 * @Gerijacki made their first contribution in projectdiscovery/subfinder#1812 **Full Changelog**: https://github.com/projectdiscovery/subfinder/compare/v2.14.0...v2.15.0</pre> <p>View the full release notes at <a href="https://github.com/projectdiscovery/subfinder/releases/tag/v2.15.0">https://github.com/projectdiscovery/subfinder/releases/tag/v2.15.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!16007
Summary
-lsprints source names with*/~markers, which is fine for humans but awkward for automation that wants to select sources by property (key-less, recursive, default).When
-lsis combined with-oJ, subfinder now emits one JSON object per source instead:Each object exposes
name,default,recursiveandkeyRequirement(required/optional/none), all derived from the existingSourceinterface methods. Output is JSONL, consistent with-oJelsewhere, and sorted by name for determinism.The default human-readable
-lsoutput is unchanged.Tests
Added tests covering the metadata builder (mirrors every source's interface methods) and the JSONL writer (every line is a valid standalone object).
Summary by CodeRabbit
New Features
Documentation
-oJ.