The generateState() function in both auth.ts and connect.ts uses Math.random():
function generateState(): string {
return Math.random().toString(36).substring(2, 15);
}
Math.random() is not cryptographically secure. The OAuth state parameter exists specifically to prevent CSRF attacks. Using a predictable value defeats this protection entirely.
Expected behaviour
The state parameter should be generated using crypto.randomBytes() to ensure it is cryptographically unpredictable.
Proposed fix
import crypto from 'crypto';
function generateState(): string {
return crypto.randomBytes(32).toString('hex');
}
Files to touch
apps/backend/src/routes/auth.ts
apps/backend/src/routes/connect.ts
GSSoC 2026 — Assignment Request
I would like to work on this issue as part of GirlScript Summer of Code 2026. I have reviewed the codebase and understand the root cause and the fix required.
Could you please assign this issue to me?
GitHub: @MehtabSandhu11
Thank you!
The
generateState()function in bothauth.tsandconnect.tsusesMath.random():Math.random()is not cryptographically secure. The OAuthstateparameter exists specifically to prevent CSRF attacks. Using a predictable value defeats this protection entirely.Expected behaviour
The state parameter should be generated using
crypto.randomBytes()to ensure it is cryptographically unpredictable.Proposed fix
Files to touch
apps/backend/src/routes/auth.tsapps/backend/src/routes/connect.tsGSSoC 2026 — Assignment Request
I would like to work on this issue as part of GirlScript Summer of Code 2026. I have reviewed the codebase and understand the root cause and the fix required.
Could you please assign this issue to me?
GitHub: @MehtabSandhu11
Thank you!