Details
Lifecycle: generation-time. The fetch happens when the developer or CI pipeline runs swagger-typescript-api generate, not when the generated client is later imported.
Suggested fix:
Defense in depth at three layers, in priority order:
- Reject private / link-local / loopback addresses at the URL-validation layer. Resolve the URL's hostname, check the resulting IP against IPv4 ranges
127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16,0.0.0.0/8, and IPv6 equivalents (::1,fc00::/7,fe80::/10,::ffff:0:0/96). Re-resolve on every redirect to defeat DNS rebinding. - Use a custom undici dispatcher with `connect` hook that re-checks the resolved IP at TCP-connect time — the only reliable way to defeat DNS rebinding in Node's built-in
fetch. - Set `redirect: "manual"` in the `fetch` options and validate each redirect URL through the same allowlist before following it.
If full SSRF mitigation is too invasive for a code-generation tool, at minimum surface the threat: log every external URL the generator is about to fetch (so a developer can grep for unexpected hosts in the output) and add an opt-out flag like --no-external-refs that disables warmUpRemoteSchemasCache entirely.
Submitted by: Hamza Haroon (thegr1ffyn)