Repository navigation
Conversation
Passive sources read third-party (and, since TLS verification is skipped, potentially MITM'd) HTTP response bodies with unbounded io.ReadAll / json.Decoder / bufio.Scanner. The client Timeout bounds time, not size, so a malicious or compromised upstream could stream an effectively unbounded body and OOM the process. Cap the body centrally at the session layer (httpRequestWrapper) so every source inherits the limit regardless of how it consumes the body. The threatcrowd source issues a raw session.Client.Do, bypassing the wrapper, so it opts in explicitly via the exported LimitResponseBody helper. The wrapper preserves the original body's Close, so no body/connection leak. 50MB cap is generous enough that legitimate large subdomain lists are unaffected. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Jack Adams-Lovell <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds configurable response-body size limits for passive HTTP sources. The limit flows from runner options into sessions and applies to shared requests and the ThreatCrowd direct request path. Tests cover capped, unlimited, nil, and close-propagation behavior. ChangesResponse body limits
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/subscraping/agent.go (1)
30-53: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winConsider surfacing when truncation actually happened.
io.LimitReadertruncates silently — callers get exactlymaxResponseBodySizebytes and anio.EOF, with no way to tell "response was small" from "response got cut off at the cap." For any source whose body-consumption path doesn't strictly validate format (e.g., line-based scanners), a truncated response could yield partial results with no error. Worth considering a small wrapper that flags/logs when the cap was actually hit (e.g., track bytes read and compare to the limit, or peek one extra byte), so operators can distinguish "legit small body" from "cap enforced against an oversized/malicious response."♻️ Illustrative direction (not a full fix)
type limitedResponseBody struct { - io.Reader // io.LimitReader over the original body + *io.LimitedReader // exposes N (remaining bytes) so callers can detect truncation io.Closer // the original body's Close } func LimitResponseBody(response *http.Response) { if response == nil || response.Body == nil { return } + lr := &io.LimitedReader{R: response.Body, N: maxResponseBodySize} response.Body = &limitedResponseBody{ - Reader: io.LimitReader(response.Body, maxResponseBodySize), + LimitedReader: lr, Closer: response.Body, } }Callers/other helpers could then check
lr.N == 0after reading to know the cap was hit and log a warning.🤖 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/subscraping/agent.go` around lines 30 - 53, Update limitedResponseBody and LimitResponseBody to detect whether reads consume the full maxResponseBodySize and whether an additional byte exists, exposing that truncation state to callers after consumption. Preserve the existing reader and Close behavior while ensuring small responses are not marked truncated and capped oversized responses can be distinguished and logged by their callers.
🤖 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.
Inline comments:
In `@pkg/subscraping/agent_test.go`:
- Around line 93-94: Update the request setup in the test to use
http.NewRequestWithContext instead of http.NewRequest, supplying an appropriate
context and preserving the existing GET method, server URL, and error assertion;
add the context import required by this change.
---
Nitpick comments:
In `@pkg/subscraping/agent.go`:
- Around line 30-53: Update limitedResponseBody and LimitResponseBody to detect
whether reads consume the full maxResponseBodySize and whether an additional
byte exists, exposing that truncation state to callers after consumption.
Preserve the existing reader and Close behavior while ensuring small responses
are not marked truncated and capped oversized responses can be distinguished and
logged by their callers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 39717648-4017-4403-9017-a7e4ecaa7009
📒 Files selected for processing (3)
pkg/subscraping/agent.gopkg/subscraping/agent_test.gopkg/subscraping/sources/threatcrowd/threatcrowd.go
|
Thanks for the hardening PR. The central LimitReader on the session path is a clean place for this. Before merging:
|
subfinder 2.16.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><!-- Release notes generated using configuration in .github/release.yml at main --> ## What's Changed * feat(sources): honor -max-results across paginating sources by @Gerijacki in projectdiscovery/subfinder#1810 * fix(extractor): match the target domain literally and reject partial hosts by @Gerijacki in projectdiscovery/subfinder#1811 * fix(subscraping): cap untrusted source response bodies with a size limit by @adamsjack711-ux in projectdiscovery/subfinder#1809 * fix(subscraping): use DialContext instead of the deprecated Dial by @jonaslejon in projectdiscovery/subfinder#1835 * feat: add scanmalware passive source by @jonaslejon in projectdiscovery/subfinder#1834 * fix(crtsh): set statement_timeout via SQL query to avoid PgBouncer handshake rejection (#1828) by @gcoinstash-cmd in projectdiscovery/subfinder#1832 ## New Contributors * @J12934 made their first contribution in projectdiscovery/subfinder#1823 * @adamsjack711-ux made their first contribution in projectdiscovery/subfinder#1809 * @gcoinstash-cmd made their first contribution in projectdiscovery/subfinder#1832 **Full Changelog**: https://github.com/projectdiscovery/subfinder/compare/v2.15.0...v2.16.0</pre> <p>View the full release notes at <a href="https://github.com/projectdiscovery/subfinder/releases/tag/v2.16.0">https://github.com/projectdiscovery/subfinder/releases/tag/v2.16.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!17505
Summary
Passive-source HTTP responses were read with unbounded
io.ReadAll(resp.Body)(andjson.Decoder/bufio.Scanner) across the source implementations. A malicious, compromised, or MITM'd upstream API returning a very large body can drive the process to OOM — the client timeout bounds time, not size (andNewSessionsetsInsecureSkipVerify: true).This caps response bodies centrally at the session layer so every source inherits the limit regardless of how it reads the body.
Changes
pkg/subscraping/agent.go: addedmaxResponseBodySize = 50 * 1024 * 1024(50MB) and aLimitResponseBodyhelper that wrapsresp.Bodyin anio.LimitReaderwhile preservingClose. Applied in the sharedhttpRequestWrapper(coversGet/SimpleGet/Post/SimplePost/HTTPRequest).pkg/subscraping/sources/threatcrowd/threatcrowd.go: applied the same helper to its rawsession.Client.Docall, which bypasses the wrapper.pkg/subscraping/agent_test.go: unit tests for the cap (oversized body truncated, small body untouched, nil-safe, Close propagation).50MB is generous enough that legitimate large subdomain lists are unaffected. No timeout, concurrency, or source logic changed.
Testing
go build ./...andgo test ./pkg/...pass.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
--response-size-read/-rsrconfiguration, with unlimited reading by default.Bug Fixes
Documentation
Tests