nodejs / nodejs/node

spkac exportPublicKey cannot distinguish between internal failure vs invalid input

Aperta
#63,264 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stale
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da src/crypto/crypto_spkac.cc intorno alle righe 43-44 e confronta la gestione degli errori con quella di src/crypto/crypto_keys.cc intorno alle righe 141-143. Traccia Certificate.exportPublicKey e determina in che modo un input SPKAC non valido differisce da un errore interno di OpenSSL. Il lavoro è completato quando questi risultati sono distinguibili e il comportamento è coperto da test crypto appropriati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, javascript, node.js
Ambito
backend-api-design, security
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
58/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.