mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
https: handle invalid TLS options in proxied requests
tls.connect() can throw while validating TLS options. For proxied HTTPS requests, it is called after the CONNECT response has been received, so the throw happens asynchronously from the original https.request() call and ends the process as an uncaught exception. Catch the error, close the tunnel socket, and propagate it to the request. Signed-off-by: Christian Aurich <christian.aurichzm@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66096 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
1 parent
70c269aadc
commit
33e4ba358b
2 files changed
+89
-5
No files matched your search
+14
-5
@@ -292,11 +292,20 @@ function establishTunnel(agent, socket, options, tunnelConfig, afterSocket) {
|
||||
debug('Propagate error event from tunneled socket to tunnel socket');
|
||||
afterSocket(err, tunneldSocket);
|
||||
};
|
||||
tunneldSocket = tls.connect(requestOptions, () => {
|
||||
debug('TLS handshake over tunnel succeeded');
|
||||
tunneldSocket.removeListener('error', onTLSHandshakeError);
|
||||
afterSocket(null, tunneldSocket);
|
||||
});
|
||||
// tls.connect() validates options synchronously, and here it runs after
|
||||
// https.request() has returned, so a throw would be uncaught.
|
||||
try {
|
||||
tunneldSocket = tls.connect(requestOptions, () => {
|
||||
debug('TLS handshake over tunnel succeeded');
|
||||
tunneldSocket.removeListener('error', onTLSHandshakeError);
|
||||
afterSocket(null, tunneldSocket);
|
||||
});
|
||||
} catch (err) {
|
||||
debug('tls.connect() over tunnel threw', err);
|
||||
socket.destroy();
|
||||
afterSocket(err, socket);
|
||||
return true;
|
||||
}
|
||||
if (requestOptions[kPerRequestCheckServerIdentity])
|
||||
tunneldSocket[kPerRequestCheckServerIdentity] = true;
|
||||
tunneldSocket.on('free', () => {
|
||||
|
||||
Reference in new issue
Block a user