Skip to content

Commit e43ca72

Browse files
fix: use randomBytes() instead of Math.random() for OAuth state generation (#145)
1 parent c11b701 commit e43ca72

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

apps/backend/src/routes/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
2-
2+
import { randomBytes } from 'crypto';
33
const GITHUB_AUTH_URL = 'https://github.com/login/oauth/authorize';
44
const GITHUB_TOKEN_URL = 'https://github.com/login/oauth/access_token';
55
const GITHUB_USER_URL = 'https://api.github.com/user';
@@ -287,5 +287,5 @@ export async function authRoutes(app: FastifyInstance) {
287287
}
288288

289289
function generateState(): string {
290-
return Math.random().toString(36).substring(2, 15);
290+
return randomBytes(32).toString('hex');
291291
}

apps/backend/src/routes/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,5 @@ function parseGoogleState(state: string): ParsedOAuthState | null {
170170
}
171171

172172
function generateState(): string {
173-
return Math.random().toString(36).substring(2, 15);
173+
return randomBytes(32).toString('hex');
174174
}

0 commit comments

Comments
 (0)