Skip to content

crypto: adjust types for getRandomValues - #41481

Closed
LiviaMedeiros wants to merge 6 commits into
nodejs:masterfrom
LiviaMedeiros:adjust-getRandomValues
Closed

crypto: adjust types for getRandomValues#41481
LiviaMedeiros wants to merge 6 commits into
nodejs:masterfrom
LiviaMedeiros:adjust-getRandomValues

Conversation

@LiviaMedeiros

Copy link
Copy Markdown
Member

Fixes: #41480

Prevents Web Crypto API's getRandomValues from accepting DataView

WIP/draft at this moment.

I'm not sure if new DataView(buf.buffer) in this test was intentional:

{
constbuf=newUint16Array(10);
constbefore=Buffer.from(buf).toString('hex');
getRandomValues(newDataView(buf.buffer));
constafter=Buffer.from(buf).toString('hex');
assert.notStrictEqual(before,after);
}

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-botnodejs-github-bot added crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Jan 11, 2022
@tniessen
tniessen requested a review from jasnellJanuary 11, 2022 17:58
@lpinca

lpinca commented Jan 11, 2022

Copy link
Copy Markdown
Member

@LiviaMedeiros If this is ready (it seems so) please remove the draft status, otherwise CI does not run. Thank you.

@LiviaMedeiros
LiviaMedeiros marked this pull request as ready for review January 11, 2022 23:05
@LiviaMedeiros

Copy link
Copy Markdown
MemberAuthor

Sure, now it's ready.

Also I should explicitly mention that this is a potentially breaking change, if someone actually uses this method with DataView.
Such usage is unlikely; but it's a part of public API and current documentation allows that.

@lpinca

Copy link
Copy Markdown
Member

The Web Crypto API is experimental so I do not think we should label this as "semver-major". Can you please also update the doc to remove the no longer supported types?

@LiviaMedeiros

Copy link
Copy Markdown
MemberAuthor

That's great.
Updated the doc.

Raw ArrayBuffer from previous version wasn't acceptable and didn't work:

crypto.getRandomValues(newArrayBuffer(8));// DOMException [TypeMismatchError]

@LiviaMedeiros
LiviaMedeirosforce-pushed the adjust-getRandomValues branch 2 times, most recently from 6b067ef to c108ea1CompareJanuary 12, 2022 22:41
@LiviaMedeiros

Copy link
Copy Markdown
MemberAuthor

Rebased to make linter happy, updated list of jsGlobalTypes to make type parser happy.
If the union type looks too pedantic and ugly, it may be reduced to just {Buffer|TypedArray}.
But technically even Buffer is redundant, since its prototype is Uint8Array; and it would require an explicit warning about Float32Array and Float64Array anyway.

@DerekNonGenericDerekNonGeneric left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@LiviaMedeiros, thank you so much for this PR!

Did a light review, so pre-approving for now, but hope that we can get a more thorough review on this by other collaborators more involved in these parts — would like to see if further improvements can be made here. :)

Comment threadtest/fixtures/wpt/WebCryptoAPI/getRandomValues.any.js Outdated
Comment threaddoc/api/webcrypto.md Outdated
Comment threaddoc/api/webcrypto.md Outdated
Comment threadtools/doc/type-parser.mjs Outdated
@tniessen

Copy link
Copy Markdown
Member

Thanks @LiviaMedeiros :)

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva

Copy link
Copy Markdown
Member

Landed in b8de7aa

panva pushed a commit that referenced this pull request Jan 22, 2022
prevents Web Crypto API's getRandomValues from accepting DataView
Fixes: #41480
Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
PR-URL: #41481
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@panvapanva closed this Jan 22, 2022
BethGriggs pushed a commit that referenced this pull request Jan 25, 2022
prevents Web Crypto API's getRandomValues from accepting DataView
Fixes: #41480
Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
PR-URL: #41481
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@ruyadornoruyadorno mentioned this pull request Feb 8, 2022
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Feb 25, 2022
This was previously a `DataView`, not an integer-type TypedArray,
throwing in Node 17.5.0: nodejs/node#41481
danielleadams pushed a commit that referenced this pull request Feb 28, 2022
prevents Web Crypto API's getRandomValues from accepting DataView
Fixes: #41480
Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
PR-URL: #41481
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Mar 2, 2022
prevents Web Crypto API's getRandomValues from accepting DataView
Fixes: #41480
Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
PR-URL: #41481
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Mar 3, 2022
prevents Web Crypto API's getRandomValues from accepting DataView
Fixes: #41480
Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
PR-URL: #41481
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Mar 14, 2022
prevents Web Crypto API's getRandomValues from accepting DataView
Fixes: #41480
Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
PR-URL: #41481
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cryptoIssues and PRs related to the crypto subsystem.experimentalIssues and PRs related to experimental features.needs-ciPRs that need a full CI run.typingswebcrypto

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webcrypto getRandomValues accepts DataView

8 participants

@LiviaMedeiros@nodejs-github-bot@lpinca@tniessen@panva@jasnell@himself65@DerekNonGeneric