WeSearch

Math.random() Is Not Random Enough. I Found It Building API Keys in a 44K-Star Repo.

·4 min read · 0 reactions · 0 comments · 10 views
#security#javascript#crypto
Math.random() Is Not Random Enough. I Found It Building API Keys in a 44K-Star Repo.
⚡ TL;DR · AI summary

A recent analysis highlights the security risks associated with using Math.random() for generating API keys. The article explains that Math.random() is a pseudo-random number generator that can be exploited by attackers to predict future outputs. It recommends using more secure alternatives like crypto.randomBytes() to ensure better randomness and security for sensitive tokens.

Key facts
Original article
DEV.to (Top)
Read full at DEV.to (Top) →
Opening excerpt (first ~120 words) tap to expand

try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 3669992) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } Ofri Peretz Posted on May 30 • Originally published at ofriperetz.dev Math.random() Is Not Random Enough. I Found It Building API Keys in a 44K-Star Repo. #security #javascript #node #devsecops I found this in our benchmark corpus, extracted verbatim from Cal.com's Make integration setup (~44K GitHub stars): const apiKey = `cal_live_${Math.random().toString(36).substring(2)}`; Enter fullscreen mode Exit fullscreen mode An attacker who observes a handful of these keys can predict the…

Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from DEV.to (Top)