Skip to content

feat(runner): machine-readable source listing with -ls -oJ - #1812

Merged
dogancanbakir merged 2 commits into
projectdiscovery:devfrom
Gerijacki:feat/list-sources-json
Jul 30, 2026
Merged

dogancanbakir merged 2 commits into
projectdiscovery:devfrom
Gerijacki:feat/list-sources-json

Conversation

@Gerijacki

@Gerijacki Gerijacki commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

-ls prints 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 -ls is combined with -oJ, subfinder now emits one JSON object per source instead:

$ subfinder -ls -oJ | head -3
{"name":"alienvault","default":true,"recursive":true,"keyRequirement":"required"}
{"name":"anubis","default":true,"recursive":false,"keyRequirement":"none"}
{"name":"bevigil","default":true,"recursive":false,"keyRequirement":"required"}

Each object exposes name, default, recursive and keyRequirement (required / optional / none), all derived from the existing Source interface methods. Output is JSONL, consistent with -oJ elsewhere, and sorted by name for determinism.

The default human-readable -ls output 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

    • Improved JSON output for listed sources, including source name, default status, recursion support, and key requirements.
    • JSON results are now emitted consistently for each source.
  • Documentation

    • Updated command help and usage documentation to clarify that JSON output is enabled with -oJ.

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.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

listSources now emits each passive source as a JSON object when JSON mode is enabled, including name, defaults, recursion, and key requirements. CLI help and README text now reference -oJ for JSON output.

Changes

JSON source listing

Layer / File(s) Summary
JSON list-sources execution path
pkg/runner/options.go, README.md
listSources encodes source metadata directly to the configured output in JSON mode, handles encoding failures fatally, and updates the related CLI documentation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 1818 — Directly describes machine-readable subfinder -ls -oJ source metadata output.

Poem

A bunny hops through JSON bright,
Listing sources line by line;
Names and keys all tucked in tight,
With recursive flags that neatly shine.
“-oJ,” I cheer, “the output’s fine!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: machine-readable source listing for -ls with -oJ output.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dogancanbakir

Copy link
Copy Markdown
Member

Just curious, what is your use-case for this? Are you trying to filter the one not requiring keys?

@Gerijacki

Copy link
Copy Markdown
Contributor Author

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)
Select only the ones that are "recursive" or "default" depending on your needs
Avoid having to manually parse the human-readable output with regex or workarounds

For example, with JSONL you can easily do:
subfinder -ls -oJ | jq 'select(.keyRequirement == "none")' | # use only these

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.

@dogancanbakir

Copy link
Copy Markdown
Member

@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.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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


@dogancanbakir: Created and assigned the tracking issue: #1818.

You are interacting with an AI system.

@dogancanbakir

Copy link
Copy Markdown
Member

@Gerijacki Thanks for the reply and PR!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/runner/options.go (1)

232-256: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c5fb9a and 55590bd.

📒 Files selected for processing (2)
  • README.md
  • pkg/runner/options.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

@dogancanbakir dogancanbakir linked an issue Jul 30, 2026 that may be closed by this pull request
5 tasks
@dogancanbakir
dogancanbakir merged commit cee010b into projectdiscovery:dev Jul 30, 2026
9 checks passed
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
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
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.

Track machine-readable source metadata for subfinder -ls -oJ

2 participants