Skip to content

Commit 00c425e

Browse files
committed
[security] Fix ReDoS vulnerability
A specially crafted value of the `Sec-Websocket-Protocol` header could be used to significantly slow down a ws server. PoC and fix were sent privately by Robert McLaughlin from University of California, Santa Barbara.
1 parent 990306d commit 00c425e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/websocket-server.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class WebSocketServer extends EventEmitter {
286286
let protocol = req.headers['sec-websocket-protocol'];
287287

288288
if (protocol) {
289-
protocol = protocol.trim().split(/ *, */);
289+
protocol = protocol.split(',').map(trim);
290290

291291
//
292292
// Optionally call external protocol selection handler.
@@ -404,3 +404,15 @@ function abortHandshake(socket, code, message, headers) {
404404
socket.removeListener('error', socketOnError);
405405
socket.destroy();
406406
}
407+
408+
/**
409+
* Remove whitespace characters from both ends of a string.
410+
*
411+
* @param {String} str The string
412+
* @return {String} A new string representing `str` stripped of whitespace
413+
* characters from both its beginning and end
414+
* @private
415+
*/
416+
function trim(str) {
417+
return str.trim();
418+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy