Skip to content

fix(oauth): SSRF-harden issuer discovery and introspection requests (SEC-976) - #260

Open
Gerardo Sabetta (gerardosabetta) wants to merge 1 commit into
mainfrom
sec-976-harden-url-safety
Open

Gerardo Sabetta (gerardosabetta) wants to merge 1 commit into
mainfrom
sec-976-harden-url-safety

Conversation

@gerardosabetta

@gerardosabetta Gerardo Sabetta (gerardosabetta) commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

SEC-976. assertSafeHttpUrl guarded 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.1 and foo.localhost all 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

  • Address classification (lib/outbound-address.mts): node:net BlockList refuses unspecified, loopback, link-local, RFC 1918, CGNAT, 0.0.0.0/8, multicast, documentation, benchmarking and class E IPv4; IPv6 outside 2000::/3 (::, ::1, ULA, link-local, multicast, NAT64), plus 6to4, Teredo and documentation ranges. IPv4-mapped and IPv4-compatible addresses are unwrapped first. localhost and *.localhost are refused.
  • Pinned connection (lib/outbound-http.mts, safeHttpRequest): a custom net lookup resolves the host with dns.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: false keeps a pooled socket from skipping the lookup. The resolver is injectable for tests.
  • Redirects: discovery follows up to 5, re-running the URL check and the pinned lookup on each hop and dropping authorization/cookie cross-origin. Introspection refuses redirects.
  • Both call sites (oauth-discovery.mts, oauth.mts) use safeHttpRequest. assertSafeHttpUrl keeps its signature and the SOCKET_DEBUG localhost override.

Heads-up for reviewers

  • An issuer or introspection host that resolves to a private address (an IdP inside a VPC) now fails. There is no override besides SOCKET_DEBUG, which opens localhost/loopback only. If hosted MCP or a customer needs that, we should add an explicit allowlist before merging.
  • Introspection no longer follows redirects (before, same-origin redirects resent Basic credentials).
  • These two calls move from @socketsecurity/lib httpRequest to node:http(s), with a 30 s idle timeout and a 1 MiB body cap. No new dependencies.
  • Out of scope: other outbound calls (Socket API, Sentry, stdio login) use operator-configured URLs, not issuer-supplied ones.

Tests

  • New test/repo/unit/outbound-http.test.mts (84 tests) with a stubbed resolver, no real DNS: localtest.me and *.127.0.0.1.nip.io resolving 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.
  • 3 new OAuth tests: discovery redirect to an internal address, introspection redirect refused, introspection_endpoint on [::].
  • pnpm test: 827/827 pass. pnpm run check (format, oxlint, tsc, build, versions, scan) passes.

Slides

cover

gap

evidence

flow

headsup

verify

…(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.
Gerardo Sabetta (gerardosabetta) added a commit that referenced this pull request Dec 2, 2026
@gerardosabetta
Gerardo Sabetta (gerardosabetta) marked this pull request as ready for review December 3, 2026 17:20
@cursor

cursor Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes OAuth credential-bearing outbound HTTP (discovery and introspection) and tightens what issuers/hostnames are allowed; a VPC-private IdP that resolves to RFC1918 now fails unless localhost debug is enabled.

Overview
Replaces hostname-regex URL checks with structured IP classification (outbound-address.mts) and a new safeHttpRequest path (outbound-http.mts) for OAuth metadata discovery and token introspection.

assertSafeHttpUrl now blocks localhost / *.localhost and IP literals via classifyAddress, with clearer refusal reasons; hostnames are still re-checked at connect time. Discovery uses safeHttpRequest with DNS resolve-and-pin (refuse if any answer is non-public), up to 5 vetted redirects, and credential stripping on cross-origin hops. Introspection uses the same client but does not follow redirects, so bearer tokens and the introspection client secret cannot be sent to an unvetted URL.

OAuth flows move from shared httpRequest to node:http(s) with custom lookup, agent: false, timeouts, and a 1 MiB body cap. A large unit suite covers rebinding-style hostnames, mixed DNS answers, redirect SSRF, and introspection edge cases.

Reviewed by Cursor Bugbot for commit 0315072. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Triggered by learned rule: Test listen fixtures reject on bind error

Reviewed by Cursor Bugbot for commit 0315072. Configure here.

This branch has not been deployed

No deployments
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.

1 participant