Skip to content

Commit d0ece30

Browse files
takuro-satorichardlau
authored andcommittedFeb 14, 2023
crypto: clear OpenSSL error queue after calling X509_verify()
Prior to this commit, functions accessing the OpenSSL error queue did not work properly after x509.verify() returned false. Backport-PR-URL: nodejs-private/node-private#375 CVE-ID: CVE-2023-23919 PR-URL: #45377 Refs: https://hackerone.com/bugs?subject=nodejs&report_id=1808596 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 7fef050 commit d0ece30

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
 

‎src/crypto/crypto_x509.cc

+2
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ void X509Certificate::Verify(const FunctionCallbackInfo<Value>& args) {
468468
ASSIGN_OR_RETURN_UNWRAP(&key, args[0]);
469469
CHECK_EQ(key->Data()->GetKeyType(), kKeyTypePublic);
470470

471+
ClearErrorOnReturn clear_error_on_return;
472+
471473
args.GetReturnValue().Set(
472474
X509_verify(
473475
cert->get(),

‎test/parallel/test-crypto-x509.js

+5
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ const der = Buffer.from(
187187
code: 'ERR_INVALID_ARG_VALUE'
188188
});
189189

190+
// Confirm failure of X509Certificate:verify() doesn't affect other functions that use OpenSSL.
191+
assert(!x509.verify(x509.publicKey));
192+
// This call should not throw.
193+
createPrivateKey(key);
194+
190195
// X509Certificate can be cloned via MessageChannel/MessagePort
191196
const mc = new MessageChannel();
192197
mc.port1.onmessage = common.mustCall(({ data }) => {

0 commit comments

Comments
 (0)
Please sign in to comment.