https: isolate Agent TLS policy keys

Encode TLS option types and values in HTTPS Agent keys so distinct trust
and identity policies cannot share sockets or cached sessions. Assign
stable identities to opaque SecureContext and callback objects.

Refs: https://hackerone.com/reports/3946081

Assisted-by: codex:gpt-5.6-sol
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs-private/node-private/pull/1036
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
CVE-ID: CVE-2026-123877
This commit is contained in:
Matteo Collina authored and Antoine du Hamel committed 2026-11-11 17:33:39 +01:00
1 parent 519c65ec6a
commit 20fd568f00
3 files changed
+383 -21

No files matched your search

+106 -16
View File
@@ -22,6 +22,7 @@
'use strict';
const {
ArrayBufferIsView,
ArrayIsArray,
ArrayPrototypeIndexOf,
ArrayPrototypePush,
@@ -35,6 +36,8 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
ReflectConstruct,
SafeWeakMap,
String,
Symbol,
SymbolAsyncDispose,
} = primordials;
@@ -54,6 +57,8 @@ const {
} = require('internal/tls/secure-context');
const kPerRequestCheckServerIdentity = Symbol('per-request checkServerIdentity');
let perRequestCheckServerIdentityIndex = 0;
const tlsPolicyObjectIds = new SafeWeakMap();
let tlsPolicyObjectId = 0;
const {
kProxyConfig,
checkShouldUseProxy,
@@ -514,16 +519,65 @@ Agent.prototype.keepSocketAlive = function keepSocketAlive(socket) {
return FunctionPrototypeCall(HttpAgent.prototype.keepSocketAlive, this, socket);
};
function getPfxAgentKey(pfx, passphrase) {
if (!ArrayIsArray(pfx))
return pfx;
// Encode values with their type and length so distinct TLS policies cannot
// collapse to the same Agent key. Use stable identities for opaque objects.
function getTlsOptionKey(value) {
if (value === undefined)
return '';
if (value === null)
return 'n';
let key = '';
for (let i = 0; i < pfx.length; i++) {
const value = pfx[i];
const raw = value?.buf || value;
const pass = value?.passphrase || passphrase;
key += `:${raw}:${pass}`;
if (ArrayIsArray(value)) {
let key = `a${value.length}`;
for (let i = 0; i < value.length; i++) {
const itemKey = getTlsOptionKey(value[i]);
key += `:${itemKey.length}:${itemKey}`;
}
return key;
}
if (ArrayBufferIsView(value)) {
const bytes = Buffer.from(value.buffer, value.byteOffset, value.byteLength);
return `v${bytes.byteLength}:${bytes.toString('base64')}`;
}
const type = typeof value;
if (type === 'object' || type === 'function') {
let id = tlsPolicyObjectIds.get(value);
if (id === undefined) {
id = ++tlsPolicyObjectId;
tlsPolicyObjectIds.set(value, id);
}
return `o${id}`;
}
const string = String(value);
return `${type[0]}${string.length}:${string}`;
}
function getKeyMaterialAgentKey(value, passphrase, property,
useTruthyProperties) {
if (!ArrayIsArray(value)) {
return `${getTlsOptionKey(value)}:${getTlsOptionKey(passphrase)}`;
}
let key = `a${value.length}`;
for (let i = 0; i < value.length; i++) {
const item = value[i];
let raw = item;
let pass = passphrase;
if (item !== null && typeof item === 'object' &&
!ArrayBufferIsView(item)) {
if (useTruthyProperties) {
raw = item[property] || item;
pass = item.passphrase || passphrase;
} else {
raw = item[property] !== undefined ? item[property] : item;
pass = item.passphrase !== undefined ? item.passphrase : passphrase;
}
}
const itemKey = `${getTlsOptionKey(raw)}:${getTlsOptionKey(pass)}`;
key += `:${itemKey.length}:${itemKey}`;
}
return key;
}
@@ -544,23 +598,27 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
name += ':';
if (options.ca)
name += options.ca;
name += getTlsOptionKey(options.ca);
name += ':';
if (options.cert)
name += options.cert;
name += getTlsOptionKey(options.cert);
name += ':';
if (options.ciphers)
name += options.ciphers;
name += ':';
if (options.key)
name += options.key;
if (options.key) {
name += getKeyMaterialAgentKey(
options.key, options.passphrase, 'pem', false);
}
name += ':';
if (options.pfx)
name += getPfxAgentKey(options.pfx, options.passphrase);
if (options.pfx) {
name += getKeyMaterialAgentKey(
options.pfx, options.passphrase, 'buf', true);
}
name += ':';
if (options.rejectUnauthorized !== undefined)
@@ -584,7 +642,7 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
name += ':';
if (options.crl)
name += options.crl;
name += getTlsOptionKey(options.crl);
name += ':';
if (options.honorCipherOrder !== undefined)
@@ -610,6 +668,38 @@ Agent.prototype.getName = function getName(options = kEmptyObject) {
if (options.sigalgs)
name += JSONStringify(options.sigalgs);
name += ':';
if (options.secureContext)
name += getTlsOptionKey(options.secureContext);
name += ':';
if (options.allowPartialTrustChain !== undefined)
name += getTlsOptionKey(options.allowPartialTrustChain);
name += ':';
if (options.ALPNProtocols)
name += getTlsOptionKey(options.ALPNProtocols);
name += ':';
if (options.certificateCompression)
name += getTlsOptionKey(options.certificateCompression);
name += ':';
if (options.minDHSize !== undefined)
name += getTlsOptionKey(options.minDHSize);
name += ':';
if (options.pskCallback)
name += getTlsOptionKey(options.pskCallback);
name += ':';
if (options.requestOCSP !== undefined)
name += getTlsOptionKey(options.requestOCSP);
name += ':';
if (options.session)
name += getTlsOptionKey(options.session);
if (options[kPerRequestCheckServerIdentity])
name += `:${options[kPerRequestCheckServerIdentity]}`;