mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
http: fix rawHeaders exceeding maxHeadersCount limit
Fixes: https://github.com/nodejs/node/issues/61284 PR-URL: https://github.com/nodejs/node/pull/61285 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
1 parent
c755b0113c
commit
34abee5b3b
2 files changed
+30
-2
No files matched your search
+4
-2
@@ -59,9 +59,11 @@ const MAX_HEADER_PAIRS = 2000;
|
||||
// called to process trailing HTTP headers.
|
||||
function parserOnHeaders(headers, url) {
|
||||
// Once we exceeded headers limit - stop collecting them
|
||||
if (this.maxHeaderPairs <= 0 ||
|
||||
this._headers.length < this.maxHeaderPairs) {
|
||||
const capacity = this.maxHeaderPairs - this._headers.length;
|
||||
if (this.maxHeaderPairs <= 0 || capacity >= headers.length) {
|
||||
this._headers.push(...headers);
|
||||
} else if (capacity > 0) {
|
||||
this._headers.push(...headers.slice(0, capacity));
|
||||
}
|
||||
this._url += url;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
|
||||
const server = http.createServer(common.mustCall((req, res) => {
|
||||
const limit = server.maxHeadersCount * 2;
|
||||
assert.ok(req.rawHeaders.length <= limit,
|
||||
`rawHeaders.length (${req.rawHeaders.length}) exceeds limit (${limit})`);
|
||||
res.end();
|
||||
server.close();
|
||||
}));
|
||||
|
||||
server.maxHeadersCount = 50;
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const port = server.address().port;
|
||||
const headers = Array.from({ length: 65 }, (_, i) => `X-${i}:v`).join('\r\n');
|
||||
const req = `GET / HTTP/1.1\r\nHost: localhost\r\n${headers}\r\n\r\n`;
|
||||
|
||||
net.createConnection(port, 'localhost', function() {
|
||||
this.write(req);
|
||||
this.once('data', () => this.end());
|
||||
});
|
||||
}));
|
||||
Reference in new issue
Block a user