Commit 97d5d90135e for nodejs
commit 97d5d90135e0263acf3ca8b902befa803587556a
Author: Paolo Insogna <paolo@cowtech.it>
Date: Sun Nov 22 20:10:52 2026 +0100
https: encode all TLS fields in agent names
`https.Agent#getName()` joined several TLS options with `:` without
encoding them, so a value containing `:` could shift into the next field
and produce the same name as a different set of options. A `DataView`
passed as `dhparam` was also reduced to its type name.
Encode the remaining string, boolean, number, buffer and array valued
options, including `sigalgs`, with `getTlsOptionKey()`, which prefixes
the type and the length, like the options that were already encoded.
Assisted-By: OpenAI GPT-5.6 Sol <openai/gpt-5.6-sol>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
PR-URL: https://github.com/nodejs/node/pull/67641
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
diff --git a/lib/https.js b/lib/https.js
index cd75c30a0f2..7481439bf1b 100644
--- a/lib/https.js
+++ b/lib/https.js
@@ -30,7 +30,6 @@ const {
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
FunctionPrototypeCall,
- JSONStringify,
NumberParseInt,
ObjectAssign,
ObjectSetPrototypeOf,
@@ -606,7 +605,7 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
name += ':';
if (options.ciphers)
- name += options.ciphers;
+ name += getTlsOptionKey(options.ciphers);
name += ':';
if (options.key) {
@@ -622,23 +621,23 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
name += ':';
if (options.rejectUnauthorized !== undefined)
- name += options.rejectUnauthorized;
+ name += getTlsOptionKey(options.rejectUnauthorized);
name += ':';
if (options.servername && options.servername !== options.host)
- name += options.servername;
+ name += getTlsOptionKey(options.servername);
name += ':';
if (options.minVersion)
- name += options.minVersion;
+ name += getTlsOptionKey(options.minVersion);
name += ':';
if (options.maxVersion)
- name += options.maxVersion;
+ name += getTlsOptionKey(options.maxVersion);
name += ':';
if (options.secureProtocol)
- name += options.secureProtocol;
+ name += getTlsOptionKey(options.secureProtocol);
name += ':';
if (options.crl)
@@ -646,27 +645,27 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
name += ':';
if (options.honorCipherOrder !== undefined)
- name += options.honorCipherOrder;
+ name += getTlsOptionKey(options.honorCipherOrder);
name += ':';
if (options.ecdhCurve)
- name += options.ecdhCurve;
+ name += getTlsOptionKey(options.ecdhCurve);
name += ':';
if (options.dhparam)
- name += options.dhparam;
+ name += getTlsOptionKey(options.dhparam);
name += ':';
if (options.secureOptions !== undefined)
- name += options.secureOptions;
+ name += getTlsOptionKey(options.secureOptions);
name += ':';
if (options.sessionIdContext)
- name += options.sessionIdContext;
+ name += getTlsOptionKey(options.sessionIdContext);
name += ':';
if (options.sigalgs)
- name += JSONStringify(options.sigalgs);
+ name += getTlsOptionKey(options.sigalgs);
name += ':';
if (options.secureContext)
diff --git a/test/parallel/test-https-agent-additional-options.js b/test/parallel/test-https-agent-additional-options.js
index eca5f147a41..84cb6a40f4b 100644
--- a/test/parallel/test-https-agent-additional-options.js
+++ b/test/parallel/test-https-agent-additional-options.js
@@ -56,30 +56,29 @@ const updatedValues = new Map([
['sessionIdContext', 'sessionIdContext'],
]);
-let value;
+// Every variation must be pooled under its own name, and repeating a
+// variation must reuse the name it had.
+const requested = new Set();
+let expectedNames = 1;
function variations(iter, port, cb) {
return common.mustCall((res) => {
res.resume();
https.globalAgent.once('free', common.mustCall(() => {
- // Verify that the most recent connection is in the freeSockets pool.
+ // Verify that the connections are in the freeSockets pool, one name for
+ // each distinct set of options.
const keys = Object.keys(https.globalAgent.freeSockets);
- if (value) {
- assert.ok(
- keys.some((val) => val.startsWith(value.toString() + ':') ||
- val.endsWith(':' + value.toString()) ||
- val.includes(':' + value.toString() + ':')),
- `missing value: ${value.toString()} in ${keys}`
- );
- }
+ assert.strictEqual(keys.length, expectedNames, `unexpected ${keys}`);
const next = iter.next();
if (next.done) {
https.globalAgent.destroy();
server.close();
} else {
- // Save `value` for check the next time.
const [key, val] = next.value;
- value = val;
+ if (!requested.has(key)) {
+ requested.add(key);
+ expectedNames++;
+ }
https.get({ ...getBaseOptions(port), [key]: val },
variations(iter, port, cb));
}
@@ -90,5 +89,7 @@ function variations(iter, port, cb) {
server.listen(0, common.mustCall(() => {
const port = server.address().port;
https.globalAgent.keepAlive = true;
- https.get(getBaseOptions(port), variations(updatedValues.entries(), port));
+ const all = [...updatedValues.entries()];
+ const entries = [...all, all[0]];
+ https.get(getBaseOptions(port), variations(entries.values(), port));
}));
diff --git a/test/parallel/test-https-agent-getname.js b/test/parallel/test-https-agent-getname.js
index 7ae5b8479d1..2a15f5e6d61 100644
--- a/test/parallel/test-https-agent-getname.js
+++ b/test/parallel/test-https-agent-getname.js
@@ -47,10 +47,10 @@ const options = {
assert.strictEqual(
agent.getName(options),
- '0.0.0.0:443:192.168.1.1:s2:ca:s4:cert:ciphers:s3:key::' +
- 's3:pfx::false:localhost:::secureProtocol:' +
- 'a3:7:v1:Yw==:7:v1:cg==:7:v1:bA==:false:ecdhCurve:dhparam:0:' +
- 'sessionIdContext:"sigalgs":::::::::'
+ '0.0.0.0:443:192.168.1.1:s2:ca:s4:cert:s7:ciphers:s3:key::' +
+ 's3:pfx::b5:false:s9:localhost:::s14:secureProtocol:' +
+ 'a3:7:v1:Yw==:7:v1:cg==:7:v1:bA==:b5:false:s9:ecdhCurve:s7:dhparam:' +
+ 'n1:0:s16:sessionIdContext:s7:sigalgs:::::::::'
);
{
@@ -156,4 +156,43 @@ assert.strictEqual(
agent.getName({ ...baseOptions, session: Buffer.from('one') }),
agent.getName({ ...baseOptions, session: Buffer.from('two') })
);
+
+ // Values containing the field delimiter must not shift across fields.
+ const collisions = [
+ [{ servername: 'a:b' }, { servername: 'a', minVersion: 'b:' }],
+ [{ minVersion: 'a:b' }, { minVersion: 'a', maxVersion: 'b:' }],
+ [{ maxVersion: 'a:b' }, { maxVersion: 'a', secureProtocol: 'b:' }],
+ [{ rejectUnauthorized: 'false:a' },
+ { rejectUnauthorized: 'false', servername: 'a:' }],
+ [{ honorCipherOrder: 'a:b' }, { honorCipherOrder: 'a', ecdhCurve: 'b:' }],
+ [{ ecdhCurve: 'a:b' }, { ecdhCurve: 'a', dhparam: 'b:' }],
+ [{ dhparam: 'a:b' }, { dhparam: 'a', secureOptions: 'b:' }],
+ [{ secureOptions: '1:a' }, { secureOptions: 1, sessionIdContext: 'a:' }],
+ [{ sessionIdContext: 'a:b' }, { sessionIdContext: 'a', sigalgs: 'b:' }],
+ [{ sigalgs: ['a:b'] }, { sigalgs: ['a', 'b'] }],
+ [{ servername: 'a', rejectUnauthorized: false, ecdhCurve: 'P-256:P-384' },
+ { rejectUnauthorized: 'false:a', honorCipherOrder: 'P-256',
+ ecdhCurve: 'P-384' }],
+ ];
+ for (const [first, second] of collisions) {
+ assert.notStrictEqual(
+ agent.getName({ ...baseOptions, ...first }),
+ agent.getName({ ...baseOptions, ...second }),
+ `${JSON.stringify(first)} collides with ${JSON.stringify(second)}`
+ );
+ }
+
+ // The type of a value is part of its key.
+ assert.notStrictEqual(
+ agent.getName({ ...baseOptions, rejectUnauthorized: false }),
+ agent.getName({ ...baseOptions, rejectUnauthorized: 'false' })
+ );
+
+ assert.notStrictEqual(
+ agent.getName({ ...baseOptions, dhparam: new DataView(new ArrayBuffer(2)) }),
+ agent.getName({
+ ...baseOptions,
+ dhparam: new DataView(new Uint8Array([1, 2]).buffer),
+ })
+ );
}