nodejs / nodejs/node

spkac exportPublicKey cannot distinguish between internal failure vs invalid input

未关闭
#63,264 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stale
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 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 摘要。