Skip to content

Commit 18f6b7d

Browse files
committed
fix: use crypto.randomBytes for session ID generation
generateSecureSessionId() used Math.random() which is cryptographically predictable. Replace with crypto.randomBytes() so session IDs cannot be guessed by observing previous values.
1 parent 707ae28 commit 18f6b7d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

api/sessions/create.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* /api/sessions/create
44
*/
55

6+
const crypto = require('crypto');
67
const admin = require('firebase-admin');
78
const jwt = require('jsonwebtoken');
89

@@ -28,9 +29,10 @@ if (!JWT_SECRET || !process.env.FIREBASE_PROJECT_ID) {
2829
// Generate secure session ID
2930
function generateSecureSessionId() {
3031
const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
32+
const bytes = crypto.randomBytes(8);
3133
let code = '';
3234
for (let i = 0; i < 8; i++) {
33-
code += chars.charAt(Math.floor(Math.random() * chars.length));
35+
code += chars.charAt(bytes[i] % chars.length);
3436
}
3537
return code;
3638
}

0 commit comments

Comments
 (0)