fix(server): catch invalid URL in HTTP handler to prevent XSS-probe crashes
new URL() throws ERR_INVALID_URL on malformed inputs like XSS probe requests (e.g. //brusEYkk%22%3E%3Cscript%3E...). Uncaught exception caused memory leak and process restarts. Return HTTP 400 instead.
This commit is contained in:
parent
98b5cb1843
commit
f8578a2176
10
server.js
10
server.js
@ -967,8 +967,14 @@ const server = http.createServer(async (req, res) => {
|
|||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = new URL(req.url, "http://localhost");
|
let url, reqPath;
|
||||||
const reqPath = url.pathname;
|
try {
|
||||||
|
url = new URL(req.url, "http://localhost");
|
||||||
|
reqPath = url.pathname;
|
||||||
|
} catch (_urlErr) {
|
||||||
|
res.writeHead(400);
|
||||||
|
return res.end("Bad Request");
|
||||||
|
}
|
||||||
|
|
||||||
// Serve static files
|
// Serve static files
|
||||||
if (reqPath === "/" || reqPath === "/index.html") {
|
if (reqPath === "/" || reqPath === "/index.html") {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user