Repository navigation
fix(oauth): SSRF-harden issuer discovery and introspection requests (SEC-976) - #260
Gerardo Sabetta (gerardosabetta) wants to merge 1 commit into
Conversation
…(SEC-976) assertSafeHttpUrl only matched the URL's hostname text against a regex, so hostnames that resolve to loopback (localtest.me, *.127.0.0.1.nip.io) and IPv6 forms such as [::] and [::ffff:127.0.0.1] passed, and the underlying httpRequest followed redirects without re-checking them. A bad or MITM'd issuer could steer discovery or token introspection, which carries the caller's bearer token and the introspection client secret, at an internal host. - Classify IP literals with node:net BlockList: unspecified, loopback, link-local, RFC 1918, CGNAT, 0.0.0.0/8, multicast, documentation and other reserved ranges, IPv6 outside 2000::/3, ULA, 6to4/Teredo, and IPv4-mapped/compatible forms. Refuse localhost and *.localhost. - Send discovery and introspection through safeHttpRequest, whose per-connection lookup resolves the host once, refuses it if any answer is non-public, and connects only to the answers it vetted, so DNS rebinding cannot swap the address between check and use. - Re-check every redirect hop for discovery (max 5) and refuse redirects for introspection. Credentials are dropped on cross-origin hops.
PR SummaryHigh Risk Overview
OAuth flows move from shared Reviewed by Cursor Bugbot for commit 0315072. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0315072. Configure here.
| connections += 1 | ||
| }) | ||
| servers.push(server) | ||
| await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve)) |
There was a problem hiding this comment.
Test listen fixture swallows bind errors
Medium Severity
startServer waits on server.listen with a resolve-only promise and never listens for error, so a bind failure such as EADDRINUSE is swallowed. Setup then hangs until the test timeout (or server.address() is null) instead of failing with the bind error. The fixture also never drops an error listener after listen succeeds.
Triggered by learned rule: Test listen fixtures reject on bind error
Reviewed by Cursor Bugbot for commit 0315072. Configure here.


Summary
SEC-976.
assertSafeHttpUrlguarded OAuth issuer discovery and token introspection by matching the URL's hostname text against a regex. Hostnames that resolve to loopback (localtest.me,*.127.0.0.1.nip.io), IPv6 forms such as[::]and[::ffff:127.0.0.1],0.1.2.3,100.64.0.1andfoo.localhostall passed, and the HTTP client then followed up to five redirects without re-checking them. Introspection carries the introspection client secret and the caller's bearer token, so a bad or MITM'd issuer could steer those credentials to an internal host (SSRF).Approach
lib/outbound-address.mts):node:netBlockListrefuses unspecified, loopback, link-local, RFC 1918, CGNAT,0.0.0.0/8, multicast, documentation, benchmarking and class E IPv4; IPv6 outside2000::/3(::,::1, ULA, link-local, multicast, NAT64), plus 6to4, Teredo and documentation ranges. IPv4-mapped and IPv4-compatible addresses are unwrapped first.localhostand*.localhostare refused.lib/outbound-http.mts,safeHttpRequest): a customnetlookupresolves the host withdns.lookup({ all: true }), refuses it if any answer is non-public, and hands the socket only the answers it vetted. Check and use are the same resolution, so DNS rebinding cannot swap the address.agent: falsekeeps a pooled socket from skipping the lookup. The resolver is injectable for tests.authorization/cookiecross-origin. Introspection refuses redirects.oauth-discovery.mts,oauth.mts) usesafeHttpRequest.assertSafeHttpUrlkeeps its signature and theSOCKET_DEBUGlocalhost override.Heads-up for reviewers
SOCKET_DEBUG, which opens localhost/loopback only. If hosted MCP or a customer needs that, we should add an explicit allowlist before merging.@socketsecurity/libhttpRequesttonode:http(s), with a 30 s idle timeout and a 1 MiB body cap. No new dependencies.Tests
test/repo/unit/outbound-http.test.mts(84 tests) with a stubbed resolver, no real DNS: localtest.me and*.127.0.0.1.nip.ioresolving to 127.0.0.1,[::],[::ffff:127.0.0.1], 127.0.0.1, 169.254.169.254, 0.1.2.3, 100.64.0.1, RFC 1918, IPv6 loopback/ULA/link-local, mixed public+private answers, a public host,localhost/foo.localhost, and redirects to a link-local literal and to a hostname resolving to 10.x. Refusal tests aim at a real local server and assert it saw zero connections.introspection_endpointon[::].pnpm test: 827/827 pass.pnpm run check(format, oxlint, tsc, build, versions, scan) passes.Slides