Skip to content

crypto: runtime-deprecate calling hmac.digest() multiple times#63800

Open
algojogacor wants to merge 1 commit into
nodejs:mainfrom
algojogacor:fix/hmac-deprecation-multiple-digest
Open

crypto: runtime-deprecate calling hmac.digest() multiple times#63800
algojogacor wants to merge 1 commit into
nodejs:mainfrom
algojogacor:fix/hmac-deprecation-multiple-digest

Conversation

@algojogacor

@algojogacor algojogacor commented Jun 8, 2026

Copy link
Copy Markdown

This is an independent contribution and is not associated with any hackathon or competition.

Summary

Runtime-deprecate calling hmac.digest() multiple times without re-initialization. Unlike Hash.prototype.digest() which throws ERR_CRYPTO_HASH_FINALIZED on second call, Hmac.prototype.digest() silently returned an empty buffer, creating a potential security footgun.

Root Cause

The Hmac.prototype.digest() method did not emit any deprecation warning when called after the HMAC instance was already finalized. Instead, it silently returned an empty Buffer. This behavior differs from Hash.prototype.digest() which throws an error, and creates a security risk where callers may inadvertently reuse the same HMAC instance thinking it produces valid output.

Fix

Added a runtime deprecation warning (DEP0208) that emits when Hmac.prototype.digest() is called after the HMAC instance has already been finalized. The existing behavior (returning empty buffer) is preserved for backward compatibility. In a future version, this will throw an error matching the behavior of Hash.prototype.digest().

Testing

Existing tests in test/parallel/test-crypto-hmac.js that call .digest() multiple times continue to pass. The deprecation warning is emitted to stderr but does not change return values, maintaining backward compatibility.

Closes #62838

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants