nodejs / nodejs/node

spkac exportPublicKey cannot distinguish between internal failure vs invalid input

オープン
#63,264 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stale
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

v25.9.0

Platform
Linux 749dbb0e74fd 6.8.0-106-generic #106-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar  6 07:58:08 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Subsystem

crypto

What steps will reproduce the bug?

The following code will serve as an example to sketch the scenario:

const { Certificate } = require('crypto');
const spkacString = '...';
console.log(Certificate.exportPublicKey(spkacString));

This will hit the following code path, causing an empty string to be returned:

https://github.com/nodejs/node/blob/349d22625713f94a5cc667592bbf34cd63af36e6/src/crypto/crypto_spkac.cc#L43-L44

Note that in the case of a valid spkac but with an internal OpenSSL failure (e.g. allocation failure), it behaves the same as an invalid spkac string. This makes distinguishing between an invalid spkac and an internal failure conditions not possible at the call site.
Furthermore, returning an empty string seems inconsistent with how other similar APIs work, e.g.:

https://github.com/nodejs/node/blob/349d22625713f94a5cc667592bbf34cd63af36e6/src/crypto/crypto_keys.cc#L141-L143

How often does it reproduce? Is there a required condition?

When an allocation failure happens or unspecified other type of failure happens inside OpenSSL, it will reproduce.

What is the expected behavior? Why is that the expected behavior?

I would expect an exception at least in the case of an internal OpenSSL failure. Besides that, it's unexpected that there's an inconsistency in the API design between different export functions. I'd expect the failure handling to be done in a consistent manner.

What do you see instead?

An empty string is returned. At least something to distinguish invalid spkac vs internal failure would be welcome.

Additional information

Found by an experimental static-hybrid analyzer I'm working on.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

src/crypto/crypto_spkac.cc の 43〜44 行付近から始め、src/crypto/crypto_keys.cc の 141〜143 行付近とエラー処理を比較してください。Certificate.exportPublicKey を追跡し、不正な SPKAC 入力と内部 OpenSSL エラーがどのように異なるかを確認してください。これらの結果を区別でき、その挙動が適切な crypto テストでカバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, javascript, node.js
領域
backend-api-design, security
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
58/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。