-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stepper: Implement signup sessions #98501
base: trunk
Are you sure you want to change the base?
Conversation
… into fix/use-steps-hook
… into fix/use-steps-hook
… into fix/use-steps-hook
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
…hooks/use-launchpad-decider/index.tsx
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~1261 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~3484 bytes removed 📉 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~1197 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
|
||
if ( ! flowName ) { | ||
// Stop the boot process if we can't determine the flow, reducing the number of edge cases | ||
return ( window.location.href = `/setup/${ DEFAULT_FLOW }${ window.location.search }` ); | ||
} | ||
|
||
if ( ! sessionId ) { | ||
sessionId = createSessionId(); |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 21 days ago
To fix the problem, we need to replace the use of Math.random()
with a cryptographically secure random number generator. In a browser environment, we can use crypto.getRandomValues
to generate secure random numbers. This will ensure that the session IDs are not easily predictable.
We will modify the createSessionId
function in client/landing/stepper/declarative-flow/internals/state-manager/create-session-id.ts
to use crypto.getRandomValues
instead of Math.random()
. This change will ensure that the generated session IDs are cryptographically secure.
-
Copy modified lines R27-R29
@@ -26,4 +26,5 @@ | ||
const maxNumberForTwoLettersBase62 = 3844; | ||
const seed = | ||
minNumberForTwoLettersBase62 + Math.floor( Math.random() * maxNumberForTwoLettersBase62 ); | ||
const randomArray = new Uint32Array(1); | ||
window.crypto.getRandomValues(randomArray); | ||
const seed = minNumberForTwoLettersBase62 + (randomArray[0] % (maxNumberForTwoLettersBase62 - minNumberForTwoLettersBase62 + 1)); | ||
|
Related to #
Proposed Changes
Why are these changes being made?
Testing Instructions
Pre-merge Checklist