Skip to content

Conversation

@triepod-ai
Copy link

Summary

Adds SSRF (Server-Side Request Forgery) protection to URL validation by blocking requests to private/internal IP addresses.

Changes

  • Add isPrivateHostname() helper with comprehensive private IP detection:
    • Localhost variants (localhost, 127.x.x.x)
    • IPv4 private ranges (10.x, 172.16-31.x, 192.168.x, 169.254.x, 0.x)
    • IPv6 private ranges (::1, fe80::, fc00::, fd00::)
    • Cloud metadata endpoints (169.254.169.254, metadata.*)
  • Update validateRedirectUrl() to block private IPs by default
  • Add allowPrivateIPs option for backward compatibility
  • Add isPrivateUrl() utility function for checking without throwing
  • Add 18 unit tests for SSRF protection

Security Impact

  • Prevents SSRF attacks via OAuth redirect URLs
  • Blocks access to cloud metadata endpoints (AWS/GCP)
  • Covers IPv4 and IPv6 private ranges

Test plan

  • Build passes (npm run build)
  • 42 URL validation tests pass (18 new SSRF tests)
  • Existing URL validation functionality preserved
  • allowPrivateIPs: true allows private IPs for backward compatibility

🤖 Generated with Claude Code

- Add isPrivateHostname() helper with comprehensive private IP detection:
  - Localhost variants (localhost, 127.x.x.x)
  - IPv4 private ranges (10.x, 172.16-31.x, 192.168.x, 169.254.x, 0.x)
  - IPv6 private ranges (::1, fe80::, fc00::, fd00::)
  - Cloud metadata endpoints (169.254.169.254, metadata.*)
- Update validateRedirectUrl() to block private IPs by default
- Add allowPrivateIPs option for backward compatibility
- Add isPrivateUrl() utility function for checking without throwing
- Add 18 unit tests for SSRF protection

Security Impact:
- Prevents SSRF attacks via OAuth redirect URLs
- Blocks access to cloud metadata endpoints (AWS/GCP)
- Covers IPv4 and IPv6 private ranges

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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