Repository navigation
fix(netlas): cap dl size to Community limits. - #1776
Conversation
Widens two 429-only branches to any non-200, moves status status check before ReadAll, and addresses "ressponse" typos; no compat breaking introductions; see projectdiscovery#1765.
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughCapped Netlas download requests at 200 entries, adjusted HTTP error handling to discard responses and simplify 429 handling for count and download endpoints, and fixed a typo in response-body read error messages. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Neo - PR Security ReviewNo security issues found Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/subscraping/sources/netlas/netlas.go (1)
77-91:⚠️ Potential issue | 🟠 MajorBody leak on early-return paths for
resp1.The
defer resp1.Body.Close()on lines 86-91 is registered after the two early-return branches on lines 77-85. When the count endpoint errors out (including the non-200 path — notehttpRequestWrapperreturns both a non-nilresponseand a non-nilerr), the response body is never closed.Move the
deferabove the status/error checks (or guard it withif resp1 != nil):Proposed fix
resp1, err := session.HTTPRequest(ctx, http.MethodGet, countUrl, "", map[string]string{ "accept": "application/json", "X-API-Key": randomApiKey, }, nil, subscraping.BasicAuth{}) + if resp1 != nil { + defer func() { + if cerr := resp1.Body.Close(); cerr != nil { + results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: cerr} + s.errors++ + } + }() + } if err != nil { results <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err} s.errors++ return } else if resp1.StatusCode != http.StatusOK { ... } - defer func() { - if err := resp1.Body.Close(); err != nil { - ... - } - }()The same pattern applies to
resp2at lines 130-150, though there thedeferis already before the status check; only theerr != nilpath at 134-138 leaks.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/subscraping/sources/netlas/netlas.go` around lines 77 - 91, The response body for resp1 (and similarly resp2) can leak on early-return error paths because the defer to close resp1.Body is registered after error/status checks; move the defer registration immediately after the http request returns (right after the call that assigns resp1 from httpRequestWrapper) and before any early returns (or alternatively guard: if resp1 != nil { defer resp1.Body.Close() }), so that resp1.Body is always closed on all paths; apply the same fix for the resp2 handling around its httpRequestWrapper call and error checks.
🧹 Nitpick comments (1)
pkg/subscraping/sources/netlas/netlas.go (1)
37-38: Hardcoded 200 cap also penalizes paid-tier NetLAS users.Users on paid plans can download more than 200 in a single request; this change forces them down to the Community ceiling too. Consider making it configurable (e.g., via env var, config, or allowing
0/unset ⇒ uncapped) so paid users aren't silently rate-limited by the client.Minimum viable improvement: allow override via env:
Suggested refactor
// Community-tier download cap; see `#1765`. Override with NETLAS_MAX_SIZE. const communityDownloadCap = 200 func downloadCap() int { if v := os.Getenv("NETLAS_MAX_SIZE"); v != "" { if n, err := strconv.Atoi(v); err == nil && n > 0 { return n } } return communityDownloadCap }Then
"size": min(domainsCount.Count, downloadCap()).Not a blocker given the PR's scope is fixing the 402 for Community users, but worth noting before merge.
Also applies to: 117-117
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/subscraping/sources/netlas/netlas.go` around lines 37 - 38, The hardcoded communityDownloadCap (const communityDownloadCap = 200) forces paid NetLAS users to the community ceiling; add a small helper (e.g., downloadCap()) that reads NETLAS_MAX_SIZE from the environment (use os.Getenv and strconv.Atoi), treat empty/zero as "uncapped" (return a sentinel like 0 meaning no cap) and then replace the current cap usage with logic that uses min(domainsCount.Count, downloadCap()) only when downloadCap() > 0, otherwise allow domainsCount.Count uncapped; update references in netlas.go where communityDownloadCap is applied so paid users can override the limit via NETLAS_MAX_SIZE.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/subscraping/sources/netlas/netlas.go`:
- Around line 81-85: The new status-code checks after calling
session.HTTPRequest are unreachable because HTTPRequest uses httpRequestWrapper
to return a non-nil error for any non-200 response; remove the redundant "else
if resp1.StatusCode != http.StatusOK" and the analogous resp2 block (and their
subscraping.Result error sends and s.errors increments) from netlas.go, or
alternatively wrap/augment the error returned by session.HTTPRequest (e.g., in
the resp1 and resp2 handling) before sending the subscraping.Result so you
provide Netlas-specific context while preserving the original status-code text
from the wrapper.
---
Outside diff comments:
In `@pkg/subscraping/sources/netlas/netlas.go`:
- Around line 77-91: The response body for resp1 (and similarly resp2) can leak
on early-return error paths because the defer to close resp1.Body is registered
after error/status checks; move the defer registration immediately after the
http request returns (right after the call that assigns resp1 from
httpRequestWrapper) and before any early returns (or alternatively guard: if
resp1 != nil { defer resp1.Body.Close() }), so that resp1.Body is always closed
on all paths; apply the same fix for the resp2 handling around its
httpRequestWrapper call and error checks.
---
Nitpick comments:
In `@pkg/subscraping/sources/netlas/netlas.go`:
- Around line 37-38: The hardcoded communityDownloadCap (const
communityDownloadCap = 200) forces paid NetLAS users to the community ceiling;
add a small helper (e.g., downloadCap()) that reads NETLAS_MAX_SIZE from the
environment (use os.Getenv and strconv.Atoi), treat empty/zero as "uncapped"
(return a sentinel like 0 meaning no cap) and then replace the current cap usage
with logic that uses min(domainsCount.Count, downloadCap()) only when
downloadCap() > 0, otherwise allow domainsCount.Count uncapped; update
references in netlas.go where communityDownloadCap is applied so paid users can
override the limit via NETLAS_MAX_SIZE.
🪄 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: 94b2e665-b09a-40e4-8b9b-8089095657b4
📒 Files selected for processing (1)
pkg/subscraping/sources/netlas/netlas.go
Addresses CodeRabbit review.
"fixes #1765."; netlas source sets
size: domainsCount.Counton the download call; hits 402 "Pricing Plan Limit Exceeded" on Community-tier keys (free default) when count > 200.Proposed changes
clamp at
min(count, 200).Also in the same file:
io.ReadAll-> moved before (don't read error bodies).ressponse->responsetypo x2.200->http.StatusOK.Proof
Need a netlas subscription for this, leaving comment over in Issue for branching + test.
Checklist
Summary by CodeRabbit
New Features
Bug Fixes