Summary
Self-hosted Next.js applications running the built-in Node.js server between versions 13.4.13 and before 15.5.16, and 16.x before 16.2.5, can be abused to perform server-side request forgery (SSRF) via crafted WebSocket upgrade requests.
An attacker who can reach the application's HTTP interface may coerce the server into proxying traffic to arbitrary internal or external endpoints, potentially exposing internal services or sensitive cloud metadata APIs.
Affected context
This vulnerability affects self-hosted Next.js deployments that:
- Run the built-in Node.js server (as opposed to serverless or edge runtimes)
- Accept WebSocket connections or pass through upgrade requests
- Are reachable by an attacker over HTTP/HTTPS
In these environments, the HTTP server's handling of WebSocket upgrade requests can be coerced into initiating outbound requests to attacker-specified destinations, including internal network services or cloud provider metadata endpoints. Managed Vercel-hosted Next.js deployments are not impacted because they do not expose the vulnerable server behavior.
Exploit preconditions
- Attack surface: Public or internal HTTP(S) endpoint of a self-hosted Next.js application using the built-in Node.js server.
- Required access: Ability to send crafted HTTP requests (including
Upgrade: websocketheaders) to the Next.js server; no direct access to internal services is required. - Trigger point: WebSocket handshake / upgrade handling, where the server interprets or forwards connection details in a way that allows outbound requests to attacker-chosen targets.
- Why exploitation is possible: The WebSocket upgrade path does not adequately restrict or validate target destinations and trust boundaries, allowing the server to act as a generic HTTP proxy into internal networks or metadata services.
Why this happens
The underlying issue is an SSRF flaw in how the built-in Node.js server in Next.js processes WebSocket upgrade requests.
Within this code path, user-controlled request parameters (such as headers or derived URLs) influence where the server initiates outbound connections, without sufficient validation, allowlisting, or separation between external input and internal destination configuration.
This maps to CWE-918: Server-Side Request Forgery (SSRF), where a server capable of making HTTP requests is tricked into contacting attacker-chosen endpoints, often bypassing network-layer controls and exposing internal resources.
Potential impact
- Access to internal HTTP services that are not directly reachable from the internet
- Retrieval of sensitive cloud instance metadata from metadata endpoints (e.g., IAM credentials, tokens, configuration)
- Enumeration of internal network topology and services via response differences and timing
- Use of the Next.js server as a pivot point for further attacks inside the infrastructure
- Potential data exfiltration from internal APIs exposed over HTTP/HTTPS
General mitigation guidance
Effective mitigation patterns focus on constraining where the server can connect and how WebSocket upgrades are handled:
- Introduce strict allowlists or explicit routing rules for any outbound requests initiated during WebSocket upgrades or proxy-like behavior.
- Separate configuration for internal service communication from user-controlled inputs, ensuring that external requests cannot influence internal target addresses.
- Harden network boundaries so that application servers have limited or no direct access to highly sensitive services, especially cloud metadata endpoints.
- Terminate WebSocket connections at a reverse proxy or gateway that enforces destination restrictions, rather than at the application server itself.
- Apply the principle of least privilege to network access: avoid granting application servers broad access to internal networks or management planes when not needed.
How teams detect issues like this
Detection can combine code-level and operational techniques:
- Static analysis rules that flag patterns where outbound requests are constructed from HTTP request fields (headers, query parameters, paths) in WebSocket or upgrade-handling logic.
- Code review checklists that call out SSRF risks in any proxying, tunneling, or upgrade-handling paths, especially around configurable destinations.
- Runtime monitoring and logging of outbound HTTP requests from application servers, including destination hostnames, IP ranges, and protocols, to spot anomalous or unexpected endpoints (e.g., metadata service IPs).
- Network-level controls and IDS/IPS signatures watching for traffic from application servers to sensitive internal ranges or metadata endpoints that would not normally be accessed.
- Use of application security testing tools (DAST/IAST) that specifically probe SSRF behavior via WebSocket upgrade requests and other upgrade-related endpoints.

