mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
https: limit proxy CONNECT response headers
Apply the configured maximum header size while reading CONNECT responses. Rearm the readable listener only once per read pass to avoid unbounded buffer and listener growth. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/64545 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
1 parent
466f1f8e62
commit
536ccc7daf
2 files changed
+69
-11
No files matched your search
@@ -0,0 +1,45 @@
|
||||
// This tests that the proxy server cannot send unbounded incomplete headers
|
||||
// while establishing a CONNECT tunnel.
|
||||
|
||||
import * as common from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import { once } from 'events';
|
||||
import http from 'node:http';
|
||||
import { runProxiedRequest } from '../common/proxy-server.js';
|
||||
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const proxy = http.createServer();
|
||||
proxy.on('connect', common.mustCall((req, socket) => {
|
||||
socket.write('HTTP/1.1 200 Connection Established\r\n');
|
||||
|
||||
const interval = setInterval(() => {
|
||||
if (socket.destroyed) {
|
||||
clearInterval(interval);
|
||||
return;
|
||||
}
|
||||
socket.write('x'.repeat(100));
|
||||
}, 10);
|
||||
socket.on('close', () => clearInterval(interval));
|
||||
socket.on('error', () => clearInterval(interval));
|
||||
}, 1));
|
||||
proxy.listen(0);
|
||||
await once(proxy, 'listening');
|
||||
|
||||
const { code, signal, stderr, stdout } = await runProxiedRequest({
|
||||
NODE_USE_ENV_PROXY: 1,
|
||||
REQUEST_URL: 'https://localhost:1/test',
|
||||
HTTPS_PROXY: `http://localhost:${proxy.address().port}`,
|
||||
}, ['--max-http-header-size=1024']);
|
||||
|
||||
assert.match(
|
||||
stderr,
|
||||
/ERR_PROXY_TUNNEL.*Proxy response headers exceeded 1024 bytes/,
|
||||
);
|
||||
assert.doesNotMatch(stderr, /MaxListenersExceededWarning/);
|
||||
assert.strictEqual(stdout.trim(), '');
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(signal, null);
|
||||
|
||||
proxy.close();
|
||||
Reference in new issue
Block a user