Skip to content

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

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

Potential fix for code scanning alert no. 4: Insecure randomness#3
yynss21 merged 1 commit intomainfrom
alert-autofix-4

Conversation

@yynss21
Copy link
Owner

@yynss21 yynss21 commented Dec 12, 2025

Potential fix for https://github.com/byRespect/tracker-hub/security/code-scanning/4

To fix the problem, the insecure call to Math.random() must be replaced with a cryptographically secure random number source. For browser-based code, window.crypto.getRandomValues (or crypto.getRandomValues) should be used. We'll generate a random string of sufficient length and in base-36 format to replace the current usage of Math.random().toString(36).substring(2, 11). We need to define a helper function, e.g., generateSecureId, which uses crypto.getRandomValues to produce a random string in the correct format. This helper should be added above createSession. We'll also consider whether to fix the user id generation. If user.id is security-sensitive, a similar change applies.

We'll:

  • Add a function (e.g., generateSecureId(length)) to generate a random string using crypto.getRandomValues.
  • Use this function to generate both the session id and user id (the latter, if warranted).
  • Make sure the import of window.crypto is not needed (accessible globally in browsers), so no import is required.
  • Change only the shown snippet, avoiding edits outside.

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>
@yynss21 yynss21 marked this pull request as ready for review December 12, 2025 22:25
@yynss21 yynss21 merged commit 20601db into main Dec 12, 2025
6 checks passed
@yynss21 yynss21 deleted the alert-autofix-4 branch December 12, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant