GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: fix rawHeaders exceeding maxHeadersCount limit · nodejs/node@24033ee

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • _http_common.js
  • test/parallel
    • test-http-rawheaders-limit.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/_http_common.js‎

Copy file name to clipboardExpand all lines: lib/_http_common.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ const MAX_HEADER_PAIRS = 2000;
5959
// called to process trailing HTTP headers.
6060
function parserOnHeaders(headers, url) {
6161
// Once we exceeded headers limit - stop collecting them
62-
if (this.maxHeaderPairs <= 0 ||
63-
this._headers.length < this.maxHeaderPairs) {
62+
const capacity = this.maxHeaderPairs - this._headers.length;
63+
if (this.maxHeaderPairs <= 0 || capacity >= headers.length) {
6464
this._headers.push(...headers);
65+
} else if (capacity > 0) {
66+
this._headers.push(...headers.slice(0, capacity));
6567
}
6668
this._url += url;
6769
}
Collapse file

‎test/parallel/test-http-rawheaders-limit.js‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
const net = require('net');
6+
7+
const server = http.createServer(common.mustCall((req, res) => {
8+
const limit = server.maxHeadersCount * 2;
9+
assert.ok(req.rawHeaders.length <= limit,
10+
`rawHeaders.length (${req.rawHeaders.length}) exceeds limit (${limit})`);
11+
res.end();
12+
server.close();
13+
}));
14+
15+
server.maxHeadersCount = 50;
16+
17+
server.listen(0, common.mustCall(() => {
18+
const port = server.address().port;
19+
const headers = Array.from({ length: 65 }, (_, i) => `X-${i}:v`).join('\r\n');
20+
const req = `GET / HTTP/1.1\r\nHost: localhost\r\n${headers}\r\n\r\n`;
21+
22+
net.createConnection(port, 'localhost', function() {
23+
this.write(req);
24+
this.once('data', () => this.end());
25+
});
26+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.