crypto: fix aes crash when tag length too small#38914
Closed
XadillaX wants to merge 4 commits intonodejs:masterfrom
Closed
crypto: fix aes crash when tag length too small#38914XadillaX wants to merge 4 commits intonodejs:masterfrom
XadillaX wants to merge 4 commits intonodejs:masterfrom
Conversation
tniessen
reviewed
Jun 3, 2021
| false, | ||
| [ 'encrypt', 'decrypt' ]) | ||
| .then((k) => { | ||
| assert.rejects(async () => { |
Member
There was a problem hiding this comment.
This function does not need the async keyword, and using it hides whether the exception is thrown synchronously or the Promise is actually rejected.
Contributor
Author
There was a problem hiding this comment.
Hmmmmm, Chrome rejects this situation in Promise. So shall we do reject or throw?
Contributor
Author
There was a problem hiding this comment.
window.crypto.subtle.decrypt({name: 'AES-GCM', iv: new Uint8Array(12)}, k, new Uint8Array(0));
> Promise {<pending>}
Uncaught (in promise) DOMException: The provided data is too small
Member
There was a problem hiding this comment.
I believe that the behavior is correct, and the test works, but it isn't as strict as it could be. assert.rejects is fine, but the async weakens the test:
function fnThatThrows() { throw new Error(); }
async function fnThatRejects() { throw new Error(); }
// With 'async':
assert.rejects(async () => fnThatRejects()); // passes
assert.rejects(async () => fnThatThrows()); // passes, but should not!
// Now remove the 'async' keyword:
assert.rejects(() => fnThatRejects()); // passes
assert.rejects(() => fnThatThrows()); // fails as it shouldSo I'd simply remove the async keyword from the function declaration :)
tniessen
approved these changes
Jun 10, 2021
Collaborator
Collaborator
Collaborator
jasnell
approved these changes
Jun 11, 2021
Contributor
Author
|
Landed in 7a9635b |
Member
|
This doesn't land cleanly on v14.x-staging. |
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.
Refs: #38883