-
Notifications
You must be signed in to change notification settings - Fork 30.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: add test for http transfer encoding smuggling
Refs: nodejs-private/node-private#228 Refs: https://hackerone.com/bugs?report_id=1002188&subject=nodejs PR-URL: nodejs-private/node-private#236 Reviewed-By: Fedor Indutny <[email protected]>
- Loading branch information
1 parent
92d4309
commit 4a30ac8
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
test/parallel/test-http-transfer-encoding-smuggling-legacy.js
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,47 @@ | ||
// Flags: --http-parser=legacy | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
const msg = [ | ||
'POST / HTTP/1.1', | ||
'Host: 127.0.0.1', | ||
'Transfer-Encoding: chunked', | ||
'Transfer-Encoding: chunked-false', | ||
'Connection: upgrade', | ||
'', | ||
'1', | ||
'A', | ||
'0', | ||
'', | ||
'GET /flag HTTP/1.1', | ||
'Host: 127.0.0.1', | ||
'', | ||
'', | ||
].join('\r\n'); | ||
|
||
// Verify that the server is called only once even with a smuggled request. | ||
|
||
const server = http.createServer(common.mustCall((req, res) => { | ||
res.end(); | ||
}, 1)); | ||
|
||
function send(next) { | ||
const client = net.connect(server.address().port, 'localhost'); | ||
client.setEncoding('utf8'); | ||
client.on('error', common.mustNotCall()); | ||
client.on('end', next); | ||
client.write(msg); | ||
client.resume(); | ||
} | ||
|
||
server.listen(0, common.mustCall((err) => { | ||
assert.ifError(err); | ||
send(common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); |