-
Notifications
You must be signed in to change notification settings - Fork 797
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
Forms: hidden fields #40329
base: trunk
Are you sure you want to change the base?
Forms: hidden fields #40329
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
useEffect( () => { | ||
if ( ! hiddenFields.length ) { | ||
setAttributes( { | ||
hiddenFields: [ { uuid: Math.random() * 1000000, name: '', value: '', edit: 'both' } ], |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 1 day ago
To fix the problem, we should replace the use of Math.random()
with a cryptographically secure random number generator. In a browser environment, we can use window.crypto.getRandomValues
to generate secure random values. This will ensure that the uuid
values are not predictable and thus more secure.
We need to modify the code on line 166 to use window.crypto.getRandomValues
instead of Math.random()
. This involves generating a random value using Uint32Array
and then scaling it appropriately.
-
Copy modified line R166
@@ -165,3 +165,3 @@ | ||
setAttributes( { | ||
hiddenFields: [ { uuid: Math.random() * 1000000, name: '', value: '', edit: 'both' } ], | ||
hiddenFields: [ { uuid: window.crypto.getRandomValues(new Uint32Array(1))[0], name: '', value: '', edit: 'both' } ], | ||
} ); |
// if all hidden fields have some value, add an empty one at the end | ||
every( newHiddenFields, 'value' ) && | ||
newHiddenFields.push( { | ||
uuid: Math.random() * 1000000, |
Check failure
Code scanning / CodeQL
Insecure randomness High
Math.random()
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 1 day ago
To fix the problem, we should replace the use of Math.random()
with a cryptographically secure random number generator. In a browser environment, we can use window.crypto.getRandomValues
to generate secure random values. This ensures that the generated uuid
is not easily predictable.
We will modify the code on line 305 to use window.crypto.getRandomValues
to generate a secure random value. This change will involve importing the necessary cryptographic functions and updating the code to generate a secure random number.
-
Copy modified line R305
@@ -304,3 +304,3 @@ | ||
newHiddenFields.push( { | ||
uuid: Math.random() * 1000000, | ||
uuid: window.crypto.getRandomValues(new Uint32Array(1))[0], | ||
name: '', |
111d780
to
d073ee9
Compare
WIP: this is a draft test
Proposed changes:
Add hidden fields on JP forms
TBD
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
No
Testing instructions:
TBD