The analysis of the provided patch commit reveals two primary vulnerabilities in SvelteKit. The first is a Server-Side Request Forgery (SSRF) in the @sveltejs/adapter-node package, and the second is a Denial of Service (DoS) in the @sveltejs/kit package, which can also be used to facilitate the SSRF.
The SSRF vulnerability existed in the get_origin function within packages/adapter-node/src/handler.js. This function was responsible for determining the origin of a request, but it did so by unsafely trusting HTTP headers such as x-forwarded-proto and x-forwarded-host. An attacker could manipulate these headers to force the server to construct a URL pointing to an internal service. When SvelteKit subsequently used this URL to fetch resources, it would result in an SSRF attack.
The DoS vulnerability was located in the internal_respond function within packages/kit/src/runtime/server/respond.js. This function had flawed logic for handling prerendered pages. A specially crafted URL could trick the server into treating an external URL as a local, prerendered resource. The server would then attempt to fetch this URL. If the fetch failed (for example, if the URL pointed to a closed port or a slow server), the resulting unhandled promise rejection would crash the entire server process, leading to a denial of service. This mechanism could also be used to trigger the SSRF by forcing a fetch to a URL constructed via the get_origin vulnerability.
The patch addresses these issues by:
- Adding robust validation in the
get_origin function to ensure that the protocol, host, and port headers contain valid and expected values.
- Correcting the path comparison logic in
internal_respond to properly handle URL-encoded characters.
- Wrapping the
fetch call in internal_respond within a try...catch block to gracefully handle errors and prevent the server from crashing.