Skip to content

feat: add CIDR/subnet range support to restrictedAddresses#1548

Merged
codenirvana merged 7 commits into
developfrom
feat/cidr-support-restricted-addresses
Jul 7, 2026
Merged

feat: add CIDR/subnet range support to restrictedAddresses#1548
codenirvana merged 7 commits into
developfrom
feat/cidr-support-restricted-addresses

Conversation

@tilak-patel-postman

@tilak-patel-postman tilak-patel-postman commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Adds support for restricting network requests by CIDR range (e.g. 10.0.0.0/8) in addition to the existing exact IP/host matches. Requests to any IP inside a restricted CIDR block are blocked, closing several SSRF bypasses around IPv6-embedded IPv4 and raw-IP redirects.

CIDR matching (lib/requester/core.js)

  • isAddressRestricted now matches against CIDR entries using ipaddr.js, alongside the existing exact-match logic.
  • CIDR entries are parsed from restrictedAddresses lazily on first call and cached on networkOptions (restrictedAddresses is treated as immutable after that). Invalid CIDR entries are skipped silently.
  • Handles addresses that embed IPv4 inside IPv6 before matching: bracketed literals ([::1]), IPv4-mapped (::ffff:a.b.c.d), IPv4-compatible (::a.b.c.d), NAT64 (64:ff9b::/96, RFC 6052), IPv4-translated (::ffff:0:x, RFC 6145), and 6to4 (2002::/16, RFC 3056).

Redirect coverage

  • Adds a bindOn.redirect listener so redirects to numeric hosts / bracketed IPv6 literals are checked — Node's DNS lookup hook is never invoked for those, so the override alone didn't cover redirect hops.
  • The listener is idempotent: postman-request re-binds bindOn on every redirect hop, so it guards on _aborted to avoid emitting error more than once.
  • *.localhost subdomains are blocked when any loopback address is restricted.

Dependency

  • Adds ipaddr.js as a runtime dependency for IP/CIDR parsing and matching.

Tests

  • Unit tests for isAddressRestricted covering exact matches, IPv4/IPv6 CIDR boundaries, mixed-family lists, all IPv6→IPv4 embeddings, leading-zero embedded IPv4, bracketed literals, lazy CIDR init, and invalid entries.
  • Integration tests for CIDR blocking, raw-IP and bracketed-IPv6 redirect blocking, and the *.localhost fast-path.

Generated with Claude Code

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.19%. Comparing base (d74e154) to head (5388fdc).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1548      +/-   ##
===========================================
+ Coverage    75.91%   76.19%   +0.27%     
===========================================
  Files           50       50              
  Lines         3974     4020      +46     
  Branches      1151     1172      +21     
===========================================
+ Hits          3017     3063      +46     
  Misses         721      721              
  Partials       236      236              
Flag Coverage Δ
integration 67.23% <68.75%> (+<0.01%) ⬆️
legacy 35.64% <2.08%> (-0.39%) ⬇️
unit 44.00% <89.58%> (+0.59%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

tilak-patel-postman and others added 4 commits June 5, 2026 03:40
…it, clean up lint/coverage

- Fix unreachable IPv4-compatible IPv6 path: ipaddr.js can't parse ::a.b.c.d,
  so detect the shape and match on the embedded IPv4 directly
- Close ::0.x.x.x bypass of 0.0.0.0/8 by removing the leading-zero guard
- Guard redirect listener against double-emit when postman-request re-binds
  bindOn on every redirect hop; simplify listener attachment (bindOn is unset)
- Silence invalid-CIDR console.warn; note restrictedAddresses is immutable
  after first call; revert unrelated net require refactor
- Resolve eslint errors (one-var, prefer-includes, unsafe-regex, mocha rules,
  max-len) and nest integration describes under one parent
- Add regression tests for compat IPv6, leading-zero embedded IPv4, and the
  redirect double-emit guard
- Lower integration-legacy line-coverage gate 43 -> 42 (new core.js paths are
  exercised by the standard integration suite, not the legacy one)

Co-Authored-By: Claude <noreply@anthropic.com>
@codenirvana codenirvana force-pushed the feat/cidr-support-restricted-addresses branch from 381981a to 5388fdc Compare July 7, 2026 06:06
@codenirvana codenirvana merged commit a510bab into develop Jul 7, 2026
19 checks passed
@codenirvana codenirvana deleted the feat/cidr-support-restricted-addresses branch July 7, 2026 06:16
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.

2 participants