Skip to content

Commit 4a30ac8

Browse files
committedDec 23, 2020
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 <fedor.indutny@gmail.com>
1 parent 92d4309 commit 4a30ac8

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Flags: --http-parser=legacy
2+
'use strict';
3+
4+
const common = require('../common');
5+
6+
const assert = require('assert');
7+
const http = require('http');
8+
const net = require('net');
9+
10+
const msg = [
11+
'POST / HTTP/1.1',
12+
'Host: 127.0.0.1',
13+
'Transfer-Encoding: chunked',
14+
'Transfer-Encoding: chunked-false',
15+
'Connection: upgrade',
16+
'',
17+
'1',
18+
'A',
19+
'0',
20+
'',
21+
'GET /flag HTTP/1.1',
22+
'Host: 127.0.0.1',
23+
'',
24+
'',
25+
].join('\r\n');
26+
27+
// Verify that the server is called only once even with a smuggled request.
28+
29+
const server = http.createServer(common.mustCall((req, res) => {
30+
res.end();
31+
}, 1));
32+
33+
function send(next) {
34+
const client = net.connect(server.address().port, 'localhost');
35+
client.setEncoding('utf8');
36+
client.on('error', common.mustNotCall());
37+
client.on('end', next);
38+
client.write(msg);
39+
client.resume();
40+
}
41+
42+
server.listen(0, common.mustCall((err) => {
43+
assert.ifError(err);
44+
send(common.mustCall(() => {
45+
server.close();
46+
}));
47+
}));

0 commit comments

Comments
 (0)
Please sign in to comment.