crypto: add cipher update/final methods encoding validation - #45990
Merged
nodejs-github-bot merged 1 commit intoJan 17, 2023
Merged
Conversation
Collaborator
|
Review requested:
|
VoltrexKeyva
previously requested changes
Dec 28, 2022
vitpavlenko
force-pushed
the
bugfix/45189-encoding-validation
branch
from
December 28, 2022 12:16
eba9755 to
9bbecff
Compare
vitpavlenko
force-pushed
the
bugfix/45189-encoding-validation
branch
from
December 28, 2022 16:34
9bbecff to
449cc81
Compare
Contributor
Author
|
Sorry, some-how missed js lint error in test. Fixed it, also updated first commit message. Please approve run @VoltrexKeyva |
Contributor
Author
|
@VoltrexKeyva any chance to approve?) |
panva
reviewed
Jan 1, 2023
vitpavlenko
force-pushed
the
bugfix/45189-encoding-validation
branch
from
January 1, 2023 17:20
449cc81 to
1853424
Compare
Collaborator
Collaborator
22 tasks
Collaborator
This was referenced Jan 3, 2023
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
This was referenced Jan 14, 2023
vitpavlenko
commented
Jan 16, 2023
| if (normalizedEncoding === undefined) { | ||
| throw new ERR_UNKNOWN_ENCODING(encoding); | ||
| } | ||
| assert(false, 'Cannot change encoding'); |
Contributor
Author
There was a problem hiding this comment.
why throw error by assert? it will be some internal error, no?
Member
There was a problem hiding this comment.
We can replace the assert with a coded error in a follow up
semver-major
Contributor
Author
There was a problem hiding this comment.
I think it is better to have a coded error, can I make the change? @panva
Member
There was a problem hiding this comment.
Sure, best wait until this change lands.
17 tasks
panva
approved these changes
Jan 17, 2023
Collaborator
|
Landed in 5a7d4a7 |
This was referenced Jan 18, 2023
Merged
Merged
nodejs-github-bot
pushed a commit
that referenced
this pull request
Sep 30, 2026
Cipher.update(string, badEncoding, ...) and Decipher.update with the same shape silently produced incorrect output: the binding skipped the unrecognized encoding and fell back to a default, giving the user wrong ciphertext or plaintext with no signal. Sub-cases 1 and 2 from issue #45189 (bad output encoding to update/final) were addressed in PR #45990. This commit completes the fix for sub-case 3 (bad input encoding) per panva's comment deferring it to a follow-up PR for CITGM testing. When `data` is a string and `inputEncoding` is non-null but does not normalize to a known encoding, throw ERR_UNKNOWN_ENCODING. Buffer / TypedArray / DataView data paths are unaffected (the binding ignores `inputEncoding` for non-string data anyway). Fixes: #45189 Refs: #45990 Signed-off-by: Maruthan G <maruthang4@gmail.com> PR-URL: #66247 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
nodejs-github-bot
pushed a commit
that referenced
this pull request
Sep 30, 2026
Move unknown encoding validation into validateEncoding so Hash, Hmac, Sign, and Verify reject invalid string input encodings alongside Cipher and Decipher. Preserve ignored encodings for buffer inputs. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66247 Fixes: #45189 Refs: #45990 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
nodejs-github-bot
pushed a commit
that referenced
this pull request
Sep 30, 2026
Reject unknown Hash and Hmac digest encodings before finalizing the operation instead of silently returning a Buffer. Preserve buffer output aliases and existing encoding coercion. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66247 Fixes: #45189 Refs: #45990 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
nodejs-github-bot
pushed a commit
that referenced
this pull request
Sep 30, 2026
Pass an encoding rather than a string length to FileHandle.write. Cover invalid encodings in fs.write, fs.writeSync, and FileHandle.write, along with valid encodings and unchanged files after rejected writes. Rejecting previously accepted invalid encodings is an intentional semver-major bug fix shared with the crypto validation changes. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66247 Fixes: #45189 Refs: #45990 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds encoding validation to update and final cipher methods.
Refs: #45189