-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: fix parsing of binary upgrade response body
Fix a bug where a connection upgrade response with a Transfer-Encoding header and a body whose first byte is > 127 causes said byte to be dropped on the floor when passing the remainder of the message to the 'upgrade' event listeners. Fixes: #17789 PR-URL: #17806 Fixes: #17789 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
1 parent
7a7e130
commit 3b9ef21
Showing
4 changed files
with
41 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
const { mustCall } = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
// https://github.com/nodejs/node/issues/17789 - a connection upgrade response | ||
// that has a Transfer-Encoding header and a body whose first byte is > 127 | ||
// triggers a bug where said byte is skipped over. | ||
net.createServer(mustCall(function(conn) { | ||
conn.write('HTTP/1.1 101 Switching Protocols\r\n' + | ||
'Connection: upgrade\r\n' + | ||
'Transfer-Encoding: chunked\r\n' + | ||
'Upgrade: websocket\r\n' + | ||
'\r\n' + | ||
'\u0080', 'latin1'); | ||
this.close(); | ||
})).listen(0, mustCall(function() { | ||
http.get({ | ||
host: this.address().host, | ||
port: this.address().port, | ||
headers: { 'Connection': 'upgrade', 'Upgrade': 'websocket' }, | ||
}).on('upgrade', mustCall((res, conn, head) => { | ||
assert.strictEqual(head.length, 1); | ||
assert.strictEqual(head[0], 128); | ||
conn.destroy(); | ||
})); | ||
})); |