mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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 Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> Co-authored-by: Filip Skokan <panva.ip@gmail.com> Signed-off-by: Matteo Collina <hello@matteocollina.com> Backport-PR-URL: https://github.com/nodejs-private/node-private/pull/1041 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs-private/node-private/pull/1036 CVE-ID: CVE-2026-123877
158 lines
4.0 KiB
JavaScript
158 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const https = require('https');
|
|
const tls = require('tls');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const agent = new https.Agent();
|
|
|
|
// empty argument
|
|
assert.strictEqual(
|
|
agent.getName(),
|
|
'localhost::::::::::::::::::::::::::::::'
|
|
);
|
|
|
|
// empty options
|
|
assert.strictEqual(
|
|
agent.getName({}),
|
|
'localhost::::::::::::::::::::::::::::::'
|
|
);
|
|
|
|
// Pass all options arguments
|
|
const options = {
|
|
host: '0.0.0.0',
|
|
port: 443,
|
|
localAddress: '192.168.1.1',
|
|
ca: 'ca',
|
|
cert: 'cert',
|
|
clientCertEngine: 'dynamic',
|
|
ciphers: 'ciphers',
|
|
crl: [Buffer.from('c'), Buffer.from('r'), Buffer.from('l')],
|
|
dhparam: 'dhparam',
|
|
ecdhCurve: 'ecdhCurve',
|
|
honorCipherOrder: false,
|
|
key: 'key',
|
|
pfx: 'pfx',
|
|
rejectUnauthorized: false,
|
|
secureOptions: 0,
|
|
secureProtocol: 'secureProtocol',
|
|
servername: 'localhost',
|
|
sessionIdContext: 'sessionIdContext',
|
|
sigalgs: 'sigalgs',
|
|
privateKeyIdentifier: 'privateKeyIdentifier',
|
|
privateKeyEngine: 'privateKeyEngine',
|
|
};
|
|
|
|
assert.strictEqual(
|
|
agent.getName(options),
|
|
'0.0.0.0:443:192.168.1.1:s2:ca:s4:cert:dynamic:ciphers:s3:key::' +
|
|
's3:pfx::false:localhost:::secureProtocol:' +
|
|
'a3:7:v1:Yw==:7:v1:cg==:7:v1:bA==:false:ecdhCurve:dhparam:0:' +
|
|
'sessionIdContext:"sigalgs":privateKeyIdentifier:privateKeyEngine::::::::'
|
|
);
|
|
|
|
{
|
|
const baseOptions = {
|
|
host: '0.0.0.0',
|
|
port: 443,
|
|
};
|
|
|
|
const agent1 = fixtures.readKey('agent1.pfx');
|
|
const agent6 = fixtures.readKey('agent6.pfx');
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({
|
|
...baseOptions,
|
|
pfx: [{ buf: agent1, passphrase: 'sample' }],
|
|
}),
|
|
agent.getName({
|
|
...baseOptions,
|
|
pfx: [{ buf: agent6, passphrase: 'sample' }],
|
|
})
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({
|
|
...baseOptions,
|
|
pfx: [{ buf: agent1, passphrase: 'sample' }],
|
|
}),
|
|
agent.getName({
|
|
...baseOptions,
|
|
pfx: [{ buf: agent1, passphrase: 'different' }],
|
|
})
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({
|
|
...baseOptions,
|
|
pfx: [{ __proto__: { buf: agent1, passphrase: 'sample' } }],
|
|
}),
|
|
agent.getName({
|
|
...baseOptions,
|
|
pfx: [{ __proto__: { buf: agent6, passphrase: 'sample' } }],
|
|
})
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName(baseOptions),
|
|
agent.getName({ ...baseOptions, ca: [] })
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({ ...baseOptions, allowPartialTrustChain: true }),
|
|
agent.getName({ ...baseOptions, allowPartialTrustChain: false })
|
|
);
|
|
|
|
const secureContext1 = tls.createSecureContext({ ca: agent1 });
|
|
const secureContext2 = tls.createSecureContext({ ca: agent6 });
|
|
assert.strictEqual(
|
|
agent.getName({ ...baseOptions, secureContext: secureContext1 }),
|
|
agent.getName({ ...baseOptions, secureContext: secureContext1 })
|
|
);
|
|
assert.notStrictEqual(
|
|
agent.getName({ ...baseOptions, secureContext: secureContext1 }),
|
|
agent.getName({ ...baseOptions, secureContext: secureContext2 })
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({
|
|
...baseOptions,
|
|
key: [{ pem: agent1, passphrase: 'sample' }],
|
|
}),
|
|
agent.getName({
|
|
...baseOptions,
|
|
key: [{ pem: agent6, passphrase: 'sample' }],
|
|
})
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({ ...baseOptions, ciphers: 'A:B' }),
|
|
agent.getName({ ...baseOptions, ciphers: 'A', key: 'B' })
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({ ...baseOptions, ALPNProtocols: ['h2'] }),
|
|
agent.getName({ ...baseOptions, ALPNProtocols: ['http/1.1'] })
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({ ...baseOptions, minDHSize: 1024 }),
|
|
agent.getName({ ...baseOptions, minDHSize: 2048 })
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({ ...baseOptions, pskCallback() {} }),
|
|
agent.getName({ ...baseOptions, pskCallback() {} })
|
|
);
|
|
|
|
assert.notStrictEqual(
|
|
agent.getName({ ...baseOptions, session: Buffer.from('one') }),
|
|
agent.getName({ ...baseOptions, session: Buffer.from('two') })
|
|
);
|
|
}
|