Skip to content

Commit aa6b97f

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#235 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
1 parent fc70ce0 commit aa6b97f

File tree

1 file changed

+46
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)
Please sign in to comment.