Skip to content

Comments

fix: prevent DNS rebinding bypass in SSRF protection (CWE-918)#186

Open
quangtran88 wants to merge 1 commit intoConway-Research:mainfrom
quangtran88:fix/ssrf-dns-rebinding
Open

fix: prevent DNS rebinding bypass in SSRF protection (CWE-918)#186
quangtran88 wants to merge 1 commit intoConway-Research:mainfrom
quangtran88:fix/ssrf-dns-rebinding

Conversation

@quangtran88
Copy link
Contributor

Summary

Prevent DNS rebinding attacks that bypass SSRF protection in agent card fetching. The previous implementation checked hostnames against a blocklist but didn't resolve DNS first — an attacker could register a domain resolving to 127.0.0.1 and bypass the check.

Changes

src/registry/discovery.ts:

  1. isInternalNetwork() — enhanced blocklist:

    • Normalize IPv6-mapped IPv4 addresses (::ffff:127.0.0.1127.0.0.1)
    • Detect and block decimal IP notation (2130706433127.0.0.1)
    • Original regex blocklist unchanged (backward compatible)
  2. resolveAndCheckHost() — new async DNS resolver:

    • Resolves hostname to IP via dns.lookup() before checking blocklist
    • Fail-closed: DNS resolution failure → blocked (not allowed)
    • Exported for use in other modules
  3. fetchAgentCard() — added DNS rebinding check:

    • After the sync isAllowedUri() check, performs async DNS resolution
    • Blocks requests where the resolved IP is internal
    • Both checks must pass (defense-in-depth)

Backward Compatibility

  • isAllowedUri() remains synchronous — no API change for existing callers
  • isInternalNetwork() signature unchanged — enhanced detection is additive
  • All 990 existing tests pass without modification

Security Impact

Before: https://evil.attacker.com/card.json passes SSRF check even if evil.attacker.com resolves to 127.0.0.1, 10.0.0.1, etc.

After: DNS is resolved and the actual IP is checked against the blocklist. Additionally blocks IPv6-mapped IPv4 and decimal IP evasion techniques.

Closes #183

Add DNS resolution before IP blocklist check in fetchAgentCard to prevent
attackers from using domains that resolve to private IPs. Also block
IPv6-mapped IPv4 addresses (::ffff:x.x.x.x) and decimal IP notation
in isInternalNetwork. Fail-closed on DNS resolution failure.

Closes Conway-Research#183
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.

Security: DNS rebinding bypass in SSRF protection (CWE-918)

1 participant