-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
1 parent
c897815
commit d2a884e
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(); | ||
})); | ||
})); |