Skip to content

security: replace Math.random with crypto.randomUUID in structuredLogger (#443) - #544

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
davidsoniaudin2-oss:security/crypto-randomuuid
Jun 28, 2026
Merged

security: replace Math.random with crypto.randomUUID in structuredLogger (#443)#544
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
davidsoniaudin2-oss:security/crypto-randomuuid

Conversation

@davidsoniaudin2-oss

Copy link
Copy Markdown
Contributor

Description

Replaces insecure \Math.random()\ usage with \crypto.randomUUID()\ in the structured logger for session ID and error ID generation.

Changes

  • Replace \Math.random().toString(36).substring(2, 9)\ with \crypto.randomUUID()\ in sessionId generation
  • Replace \Math.random().toString(36).substring(2, 9)\ with \crypto.randomUUID()\ in error ID generation
  • Add structuredLogger tests asserting crypto.randomUUID usage and non-predictability
  • Add crypto.randomUUID polyfill to jest.setup.js for jsdom compatibility

Related Issues

Closes #443 - Math.random used for structured logger sessionId

…ger (MettaChain#443)

- Replace Math.random-based sessionId generation with crypto.randomUUID()
- Replace Math.random-based error ID generation with crypto.randomUUID()
- Add structuredLogger tests asserting crypto.randomUUID usage
- Add crypto.randomUUID polyfill to jest.setup.js for jsdom environment
- Remove unpredictable Math.random usage from security-sensitive ID generation
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@davidsoniaudin2-oss Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copy link
Copy Markdown
Contributor

LGTM on the crypto.randomUUID upgrade. Merging.

@nanaf6203-bit
nanaf6203-bit merged commit f019c1a into MettaChain:main Jun 28, 2026
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.

security: Math.random used for structured logger sessionId

3 participants