Skip to content

crypto: make DEP0206 end-of-life - #65141

Closed
mcollina wants to merge 2 commits into
nodejs:mainfrom
mcollina:dep0206-eol
Closed

crypto: make DEP0206 end-of-life#65141
mcollina wants to merge 2 commits into
nodejs:mainfrom
mcollina:dep0206-eol

Conversation

@mcollina

@mcollina mcollina commented Aug 8, 2026

Copy link
Copy Markdown
Member

Make DEP0206 (calling Hmac.digest() more than once) end-of-life.

Currently a repeat digest() on a finalized Hmac returns an empty buffer with a deprecation warning, which is inconsistent with hash.digest() and can mask misuse. This makes it end-of-life by throwing ERR_CRYPTO_HASH_FINALIZED on a finalized Hmac instance, matching the behavior of Hash.digest().

This also closes the stream path: with the kFinalized flag now set by Hmac.prototype._flush (see the related fix for uninitialized memory after stream use), digest() after the Hmac has been used as a stream throws instead of reaching the native side and returning uninitialized stack memory.

Removes the now-unused DEP0206 warning emitter and the empty-buffer return path, updates the tests to verify the throw on both the direct and stream paths, and renames test-crypto-dep0206.js to test-crypto-hmac-finalized.js since the deprecation no longer exists.

Hmac.prototype._flush was aliased to Hash.prototype._flush, which
finalizes the native HMAC context but never sets the JavaScript-side
kFinalized flag. After an Hmac has been used as a stream, a subsequent
Hmac.prototype.digest() call therefore still believes the object has not
been finalized and calls into C++ a second time. On that second call the
native context has already been reset, so the digest buffer is never
written and Digest::MAX_SIZE bytes of uninitialized stack memory are
returned to JavaScript.

Hash is not affected because Hash::HashDigest caches its digest
(refs nodejs#28245); Hmac never received the equivalent protection.

Give Hmac its own _flush that sets kFinalized so repeat digest() calls
after stream use are handled by the existing DEP0206 guard. As defense
in depth, also set buf.len = 0 on the native side when the context has
already been reset so unwritten bytes can never be emitted.
DEP0206 (calling Hmac.digest() more than once) is a runtime deprecation
that returns an empty buffer instead of throwing, which is inconsistent
with hash.digest() and can mask misuse. Make it end-of-life by throwing
ERR_CRYPTO_HASH_FINALIZED on a finalized Hmac instance, matching the
behavior of Hash.digest().

This also closes the stream path: with the kFinalized flag now set by
Hmac.prototype._flush, digest() after the Hmac has been used as a stream
throws instead of reaching the native side and returning uninitialized
stack memory.

Remove the now-unused DEP0206 warning emitter and the empty-buffer
return path, and update the tests to verify the throw on both the direct
and stream paths.
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Aug 8, 2026
@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 8, 2026

@panva panva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEP0206 is planned to go to runtime-deprecation in 27.x (#63624)

node/doc/api/deprecations.md

Lines 4625 to 4631 in c59cd6b

### DEP0206: Calling `digest()` on an already-finalized `Hmac` instance
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/63624
description: Runtime deprecation.

An EOL needs to wait for 28.x

@mcollina

mcollina commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

oh no :(

@mcollina mcollina closed this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants