Skip to content

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

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

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

Conversation

@yynss21
Copy link
Owner

@yynss21 yynss21 commented Dec 12, 2025

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

To fix the problem, we need to ensure that the randomness used in session ID generation is cryptographically secure. In Node.js, this is accomplished with the crypto module, specifically crypto.randomBytes or crypto.randomUUID (Node.js v14.17+ for randomUUID). In browsers, window.crypto.getRandomValues should be used.

Because the code does not reveal the runtime environment explicitly (Node.js vs browser), but typically session tracking like this is used both client and server side, it's safest to support both environments. The most robust fix is to update createId to use crypto.randomUUID() where possible (Node.js 14.17+/browsers that support it), falling back to crypto.getRandomValues or crypto.randomBytes for randomness and construct an ID similar to original, or use a UUID polyfill otherwise. The fix should be in packages/core/src/shared/utils.ts for the createId function. Also, you'll need to import crypto for Node.js.

No other files need to be edited since all uses of createId will transparently become cryptographically strong.


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>
@github-actions github-actions bot added the core label Dec 12, 2025
@yynss21 yynss21 marked this pull request as ready for review December 12, 2025 22:21
@yynss21 yynss21 merged commit 8ae4f21 into main Dec 12, 2025
6 checks passed
@yynss21 yynss21 deleted the alert-autofix-2 branch December 12, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant