diff options
Diffstat (limited to 'test/parallel/test-http-header-overflow.js')
-rw-r--r-- | test/parallel/test-http-header-overflow.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/parallel/test-http-header-overflow.js b/test/parallel/test-http-header-overflow.js new file mode 100644 index 0000000000..a9bf5cbfa0 --- /dev/null +++ b/test/parallel/test-http-header-overflow.js @@ -0,0 +1,47 @@ +'use strict'; +const assert = require('assert'); +const { createServer, maxHeaderSize } = require('http'); +const { createConnection } = require('net'); +const { expectsError, mustCall } = require('../common'); + +const CRLF = '\r\n'; +const DUMMY_HEADER_NAME = 'Cookie: '; +const DUMMY_HEADER_VALUE = 'a'.repeat( + // plus one is to make it 1 byte too big + maxHeaderSize - DUMMY_HEADER_NAME.length - (2 * CRLF.length) + 1 +); +const PAYLOAD_GET = 'GET /blah HTTP/1.1'; +const PAYLOAD = PAYLOAD_GET + CRLF + + DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE + CRLF.repeat(2); + +const server = createServer(); + +server.on('connection', mustCall((socket) => { + socket.on('error', expectsError({ + type: Error, + message: 'Parse Error', + code: 'HPE_HEADER_OVERFLOW', + bytesParsed: maxHeaderSize + PAYLOAD_GET.length, + rawPacket: Buffer.from(PAYLOAD) + })); +})); + +server.listen(0, mustCall(() => { + const c = createConnection(server.address().port); + let received = ''; + + c.on('connect', mustCall(() => { + c.write(PAYLOAD); + })); + c.on('data', mustCall((data) => { + received += data.toString(); + })); + c.on('end', mustCall(() => { + assert.strictEqual( + received, + 'HTTP/1.1 431 Request Header Fields Too Large\r\n\r\n' + ); + c.end(); + })); + c.on('close', mustCall(() => server.close())); +})); |