Skip to content

fix(netlas): cap dl size to Community limits. - #1776

Merged
dogancanbakir merged 3 commits into
projectdiscovery:devfrom
x-stp:fix/netlas-community-cap
Apr 20, 2026
Merged

dogancanbakir merged 3 commits into
projectdiscovery:devfrom
x-stp:fix/netlas-community-cap

Conversation

@x-stp

@x-stp x-stp commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

"fixes #1765."; netlas source sets size: domainsCount.Count on 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:

  • non-200 branches reported "rate limited" regardless of status -> return the actual status code.
  • download status check ran after io.ReadAll -> moved before (don't read error bodies).
  • ressponse -> response typo x2.
  • 200 -> http.StatusOK.

Proof

Need a netlas subscription for this, leaving comment over in Issue for branching + test.

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • New Features

    • Implemented a download cap for community-tier accounts, limiting bulk domain requests to 200 per operation.
  • Bug Fixes

    • Improved handling of error responses to avoid misleading rate-limit errors and reduce failed request fallout.
    • Corrected a typo in response body error messages for clearer diagnostics.

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

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b4dbc9a5-b5c3-4893-9915-033695c2cf64

📥 Commits

Reviewing files that changed from the base of the PR and between d58cda0 and 3206a8b.

📒 Files selected for processing (1)
  • pkg/subscraping/sources/netlas/netlas.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/subscraping/sources/netlas/netlas.go

Walkthrough

Capped 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

Cohort / File(s) Summary
Netlas download & error handling
pkg/subscraping/sources/netlas/netlas.go
Added communityDownloadCap = 200 and use min(domainsCount.Count, communityDownloadCap) for POST size. On non-200 GET count responses and POST request errors, discard HTTP response and return immediately; removed explicit 429 branch for download path. Fixed "ressponse" → "response" typos in read-error messages.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I nibbled bytes and counted each thread,
Two hundred hops now cap what I spread,
I tidy responses, toss what I must,
Fix a typo, restore the trust.
Happy tails for Netlas—soft and quick as lead.

🚥 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 PR title 'fix(netlas): cap dl size to Community limits' directly describes the main change—capping download size to Community tier limits (200 subdomains)—which is the core objective of the PR.
Linked Issues check ✅ Passed The PR fully addresses issue #1765 by capping download size to min(count, 200) via the communityDownloadCap constant, preventing HTTP 402 errors for Community-tier accounts.
Out of Scope Changes check ✅ Passed All changes are within scope: download cap implementation, HTTP status handling refinement, response body discard optimization, and typo corrections (ressponse→response) are all directly related to fixing the Community limit issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@x-stp
x-stp marked this pull request as ready for review April 18, 2026 12:42
@neo-by-projectdiscovery-dev

neo-by-projectdiscovery-dev Bot commented Apr 18, 2026 •

Copy link
Copy Markdown

Neo - PR Security Review

No security issues found

Comment @pdneo help for available commands. · Open in Neo

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

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 | 🟠 Major

Body 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 — note httpRequestWrapper returns both a non-nil response and a non-nil err), the response body is never closed.

Move the defer above the status/error checks (or guard it with if 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 resp2 at lines 130-150, though there the defer is already before the status check; only the err != nil path 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a40086 and d58cda0.

📒 Files selected for processing (1)
  • pkg/subscraping/sources/netlas/netlas.go

@dogancanbakir
dogancanbakir merged commit 1cdef03 into projectdiscovery:dev Apr 20, 2026
10 checks passed
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.

[Issue] netlas api "Pricing Plan Limit Exceeded" error

2 participants