Skip to content

fix for code scanning alert no. 4: Insecure randomness#396

Merged
MickLesk merged 1 commit intomainfrom
alert-autofix-4
Dec 12, 2025
Merged

fix for code scanning alert no. 4: Insecure randomness#396
MickLesk merged 1 commit intomainfrom
alert-autofix-4

Conversation

@MickLesk
Copy link
Copy Markdown
Member

Potential fix for https://github.com/community-scripts/ProxmoxVE-Local/security/code-scanning/4

To fix the issue, we need to replace the insecure use of Math.random() with a cryptographically secure random number generator. Since this code runs in the browser (it's a React component and there's no Node-only syntax), we should use the Web Crypto API's crypto.getRandomValues. This can be used to generate secure random bytes and convert them to a random string for session ID use. Specifically, we can generate random bytes (or integers), encode them in base36 or hex, and splice that into the session ID in place of the current usage of Math.random().toString(36).substr(2, 9). We should add a helper function within this file to handle secure random string generation, and update line 423 to use it. No new imports are necessary, as the global crypto object is available in modern browsers.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@MickLesk MickLesk marked this pull request as ready for review December 12, 2025 10:30
@MickLesk MickLesk requested a review from a team as a code owner December 12, 2025 10:30
@MickLesk MickLesk merged commit 47ee224 into main Dec 12, 2025
4 checks passed
@MickLesk MickLesk changed the title Potential fix for code scanning alert no. 4: Insecure randomness fix for code scanning alert no. 4: Insecure randomness Dec 12, 2025
@MickLesk MickLesk deleted the alert-autofix-4 branch April 1, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant