spkac exportPublicKey cannot distinguish between internal failure vs invalid input
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
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:
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.:
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/crypto/crypto_spkac.cc around lines 43-44 and compare its failure handling with src/crypto/crypto_keys.cc around lines 141-143. Trace Certificate.exportPublicKey and determine how invalid SPKAC input differs from an internal OpenSSL failure. Done means those outcomes are distinguishable and the behavior is covered by appropriate crypto tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript, node.js
- Domain
- backend-api-design, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100