Skip to content

Commit efd5a6b

Browse files
sam-githubaddaleax
authored andcommitted
test: using TE to smuggle reqs is not possible
See: https://hackerone.com/reports/735748 PR-URL: nodejs-private/node-private#199 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
1 parent 4c5b8dd commit efd5a6b

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

test/parallel/test-http-client-error-rawbytes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ server.listen(0, common.mustCall(() => {
1919
const req = http.get(`http://localhost:${server.address().port}/`);
2020
req.end();
2121
req.on('error', common.mustCall((err) => {
22-
const reason = 'Content-Length can\'t be present with chunked encoding';
22+
const reason = 'Content-Length can\'t be present with Transfer-Encoding';
2323
assert.strictEqual(err.message, `Parse Error: ${reason}`);
2424
assert(err.bytesParsed < response.length);
2525
assert(err.bytesParsed >= response.indexOf('Transfer-Encoding'));

test/parallel/test-http-invalid-te.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
// Test https://hackerone.com/reports/735748 is fixed.
6+
7+
const assert = require('assert');
8+
const http = require('http');
9+
const net = require('net');
10+
11+
const REQUEST_BB = `POST / HTTP/1.1
12+
Content-Type: text/plain; charset=utf-8
13+
Host: hacker.exploit.com
14+
Connection: keep-alive
15+
Content-Length: 10
16+
Transfer-Encoding: chunked, eee
17+
18+
HELLOWORLDPOST / HTTP/1.1
19+
Content-Type: text/plain; charset=utf-8
20+
Host: hacker.exploit.com
21+
Connection: keep-alive
22+
Content-Length: 28
23+
24+
I AM A SMUGGLED REQUEST!!!
25+
`;
26+
27+
const server = http.createServer(common.mustNotCall());
28+
29+
server.on('clientError', common.mustCall((err) => {
30+
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
31+
server.close();
32+
}));
33+
34+
server.listen(0, common.mustCall(() => {
35+
const client = net.connect(
36+
server.address().port,
37+
common.mustCall(() => {
38+
client.end(REQUEST_BB.replace(/\n/g, '\r\n'));
39+
}));
40+
}));

0 commit comments

Comments
 (0)