NemoClaw icon indicating copy to clipboard operation
NemoClaw copied to clipboard

Incomplete SSRF validation in `config set` — missing CGNAT, IPv6, and IPv4-mapped ranges

Open Siddhartha-singh01 opened this issue 7 months ago • 2 comments

Description

sandbox-config.ts contains a lightweight isPrivateIp() function (L228–L234) used by validateUrlValue() to prevent SSRF via nemoclaw config set. This check is significantly weaker than the canonical isPrivateIp() in nemoclaw/src/blueprint/ssrf.ts, which uses proper CIDR matching and handles IPv6 comprehensively.

What's missing from the sandbox-config.ts check:

Address range RFC ssrf.ts sandbox-config.ts
100.64.0.0/10 (CGNAT shared space) RFC 6598 ✅ ❌
198.18.0.0/15 (Benchmark testing) RFC 2544 ✅ ❌
fc00::/7 (IPv6 unique local) RFC 4193 ✅ ❌
fe80::/10 (IPv6 link-local) RFC 4291 ✅ ❌
ff00::/8 (IPv6 multicast) RFC 4291 ✅ ❌
::ffff:127.0.0.1 (IPv4-mapped IPv6) RFC 4291 ✅ ❌
DNS resolution pinning (TOCTOU rebinding) — ✅ ❌

Impact: A user running nemoclaw config set --key inference.endpoint --value "http://100.64.1.1:8080/internal" passes validation and injects a CGNAT address into the sandbox config. On cloud VPCs (AWS, GCP, Azure), 100.64.0.0/10 addresses often reach internal metadata services and adjacent workloads. Similarly, http://[fe80::1%25eth0]:8080 bypasses validation entirely since only the literal [::1] is checked.

Expected behavior: validateUrlValue() should reject all RFC-defined private/reserved address ranges, matching the coverage already provided by ssrf.ts.

Root cause: sandbox-config.ts duplicates the private IP check instead of reusing the existing isPrivateIp() from nemoclaw/src/blueprint/ssrf.ts. The duplicate is a string-prefix check that cannot handle CIDR ranges, IPv6 expansion, or IPv4-mapped IPv6 addresses.

Suggested fix: Replace the local isPrivateIp() in sandbox-config.ts with an import of the canonical implementation from nemoclaw/src/blueprint/ssrf.ts, or add the missing address ranges and IPv6 handling to the local copy. Add corresponding test cases to test/config-set.test.ts.

Reproduction Steps

  1. Set up a NemoClaw sandbox with any provider (nemoclaw onboard)
  2. Run: nemoclaw config set --key inference.endpoint --value "http://100.64.1.1:8080"
  3. Observe: no SSRF error — the URL is accepted and written to the sandbox config
  4. Compare with a private range that IS caught: nemoclaw config set --key inference.endpoint --value "http://10.0.0.1:8080" → correctly rejected with "URL points to private/internal address"

Additional bypass vectors (all should be rejected but are not):

  • http://198.18.0.1:80 (RFC 2544 benchmark range)
  • http://[fc00::1]:8080 (IPv6 unique local address)
  • http://[fe80::1]:8080 (IPv6 link-local address)
  • http://[::ffff:127.0.0.1]:8080 (IPv4-mapped IPv6 loopback)

Environment

  • OS: Windows 11 + WSL2 (applies to all platforms)
  • Node.js: v24.14.0
  • Docker: Not required for reproduction (static code analysis finding)
  • NemoClaw: v0.1.0 (tip of main as of 2026-04-23)
  • Affected file: src/lib/sandbox-config.ts (L224–L255)
  • Reference file: nemoclaw/src/blueprint/ssrf.ts (L12–L121)

Debug Output

Not applicable — this is a static code analysis finding, not a runtime failure.

The gap is visible by comparing these two functions:

# sandbox-config.ts L228-L234 (incomplete — only 5 IPv4 prefixes, no IPv6)
function isPrivateIp(hostname: string): boolean {
  if (hostname === "localhost" || hostname === "[::1]") return true;
  for (const prefix of PRIVATE_IP_PREFIXES) {
    if (hostname.startsWith(prefix)) return true;
  }
  if (PRIVATE_IP_172_RE.test(hostname)) return true;
  return false;
}

# ssrf.ts L104-L121 (comprehensive — CIDR matching, IPv6, IPv4-mapped)
export function isPrivateIp(addr: string): boolean {
  if (isIPv4(addr)) {
    const ipBytes = parseIPv4(addr);
    return PRIVATE_NETWORKS.some((range) => ipInCidr(ipBytes, range));
  }
  if (isIPv6(addr)) {
    const ipBytes = parseIPv6(addr);
    if (isIPv4Mapped(ipBytes)) {
      const ipv4Bytes = ipBytes.slice(12);
      return PRIVATE_NETWORKS.some((range) => ipInCidr(ipv4Bytes, range));
    }
    return PRIVATE_NETWORKS.some((range) => ipInCidr(ipBytes, range));
  }
  return false;
}

Logs

Existing test suite in test/config-set.test.ts confirms the coverage gap:

Tested (passing):
- IPv4 loopback 127.0.0.1 ✅
- IPv4 private 10.x.x.x ✅
- IPv4 private 192.168.x.x ✅
- IPv4 private 172.16-31.x.x ✅
- IPv6 loopback [::1] ✅
- localhost ✅

NOT tested (missing — all bypass validation):
- CGNAT 100.64.x.x ❌
- Benchmark 198.18.x.x ❌
- IPv6 unique-local fc00::/7 ❌
- IPv6 link-local fe80::/10 ❌
- IPv6 multicast ff00::/8 ❌
- IPv4-mapped IPv6 ::ffff:127.0.0.1 ❌

Checklist

  • [x] I confirmed this bug is reproducible
  • [x] I searched existing issues and this is not a duplicate

Siddhartha-singh01 avatar Apr 22 '26 21:04 Siddhartha-singh01

✨ Thanks for submitting this issue that identifies a security concern with the SSRF validation and proposes a fix — this could help improve the security and reliability of NemoClaw.

wscurran avatar Apr 22 '26 21:04 wscurran

Hi NemoClaw team! I'm submitting this PR to close a security gap I identified in the CLI's SSRF validation logic. While auditing the codebase, I noticed that src/lib/sandbox-config.ts was using a string-prefix check for private IPs that was significantly weaker than the canonical CIDR-based implementation in the plugin (nemoclaw/src/blueprint/ssrf.ts).

Key Technical Details:

  • Divergence Fixed: The CLI now has full parity with the plugin's SSRF protection, specifically adding coverage for CGNAT (RFC 6598), Benchmark ranges (RFC 2544), and comprehensive IPv6 handling (Unique-local, Link-local, Multicast).
  • Implementation: Instead of simple string prefixes, I've implemented proper CIDR matching using Uint8Array byte comparisons. This ensures that boundary cases (like 172.15.x.x being allowed while 172.16.x.x is blocked) are handled correctly.
  • IPv4-Mapped IPv6: The fix specifically handles ::ffff:x.x.x.x notation by extracting the embedded IPv4 address and re-validating it against the IPv4 CIDR ranges, preventing a common bypass vector.
  • Testing: I've added 13 new test cases to test/config-set.test.ts to verify the new ranges and ensure no regressions for public IP space.

Verified locally with npm test and node_modules\.bin\tsc. Happy to adjust the implementation if you'd prefer I consolidate this into a shared library instead of the local implementation used here!

Siddhartha-singh01 avatar Apr 22 '26 22:04 Siddhartha-singh01