diff --git a/.changeset/itchy-scissors-suffer.md b/.changeset/itchy-scissors-suffer.md new file mode 100644 index 000000000000..096868f5fc8f --- /dev/null +++ b/.changeset/itchy-scissors-suffer.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-node': patch +--- + +fix: return 400 response if request construction fails diff --git a/packages/adapter-node/src/handler.js b/packages/adapter-node/src/handler.js index d73b1c874831..5586e5169622 100644 --- a/packages/adapter-node/src/handler.js +++ b/packages/adapter-node/src/handler.js @@ -90,11 +90,20 @@ function serve_prerendered() { /** @type {import('polka').Middleware} */ const ssr = async (req, res) => { - const request = await getRequest({ - base: origin || get_origin(req.headers), - request: req, - bodySizeLimit: body_size_limit - }); + /** @type {Request} */ + let request; + + try { + request = await getRequest({ + base: origin || get_origin(req.headers), + request: req, + bodySizeLimit: body_size_limit + }); + } catch { + res.statusCode = 400; + res.end('Bad Request'); + return; + } setResponse( res,