Skip to content

Commit

Permalink
http: add regression test for chunked smuggling
Browse files Browse the repository at this point in the history
PR-URL: nodejs-private/node-private#284
Reviewed-By: Akshay K <iit.akshay@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
  • Loading branch information
mcollina authored and BethGriggs committed Oct 11, 2021
1 parent af488f8 commit 45d419a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/parallel/test-http-chunked-smuggling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const common = require('../common');
const http = require('http');
const net = require('net');
const assert = require('assert');

// Verify that a request with a space before the content length will result
// in a 400 Bad Request.

const server = http.createServer(common.mustCall((request, response) => {
assert.notStrictEqual(request.url, '/admin');
response.end('hello world');
}), 1);

server.listen(0, common.mustCall(start));

function start() {
const sock = net.connect(server.address().port);

sock.write('' +
'GET / HTTP/1.1\r\n' +
'Host: localhost:8080\r\n' +
'Transfer-Encoding: chunked\r\n' +
'\r\n' +
'2 \n' +
'xx\r\n' +
'4c\r\n' +
'0\r\n' +
'\r\n' +
'GET /admin HTTP/1.1\r\n' +
'Host: localhost:8080\r\n' +
'Transfer-Encoding: chunked\r\n' +
'\r\n' +
'0\r\n' +
'\r\n'
);

sock.resume();
sock.on('end', common.mustCall(function() {
server.close();
}));
}

0 comments on commit 45d419a

Please sign in to comment.