Skip to content

Runtime-deprecate calling digest() on HMAC more than once #62838

Description

@ChALkeR

(Upd: detected by the scanner behind @deepview-autofix)

Hash behavior is reasonable:

>hash=require('crypto').createHash('sha256').update('data')>hash.digest()<Buffer3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7>>hash.digest()UncaughtError[ERR_CRYPTO_HASH_FINALIZED]: DigestalreadycalledatHash.digest(node:internal/crypto/hash:155:11){code: 'ERR_CRYPTO_HASH_FINALIZED'}

But HMAC, on the other hand, returns empty buffers on further .digest() calls, likely for compat reasons:

>hmac=require('crypto').createHmac('sha256','key').update('data')>hmac.digest()<Buffer5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0>>hmac.digest()<Buffer>

This is a footgun with potential security risks, and should be first runtime-deprecated, then removed if no breakage is detected.


Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    cryptoIssues and PRs related to the crypto subsystem.securityIssues and PRs related to security.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions