Shreya 2 days ago
committed by GitHub
parent
commit
e8a147b4ee
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 30
      apps/api/src/app/auth/oidc-state.store.ts

30
apps/api/src/app/auth/oidc-state.store.ts

@ -1,5 +1,6 @@
import type { Request } from 'express'; import type { Request } from 'express';
import ms from 'ms'; import ms from 'ms';
import { randomBytes } from 'node:crypto'; // ADD THIS LINE
import type { import type {
SessionStore, SessionStore,
SessionStoreCallback, SessionStoreCallback,
@ -66,14 +67,21 @@ export class OidcStateStore implements SessionStore {
const data = this.stateMap.get(handle); const data = this.stateMap.get(handle);
if (!data) { if (!data) {
return callback(null, undefined, undefined); return callback(
} new Error('Invalid OIDC state parameter'),
undefined,
undefined
);
}
if (Date.now() - data.timestamp > this.STATE_EXPIRY_MS) { if (Date.now() - data.timestamp > this.STATE_EXPIRY_MS) {
// State has expired this.stateMap.delete(handle);
this.stateMap.delete(handle); return callback(
return callback(null, undefined, undefined); new Error('OIDC state has expired, please try again'),
} undefined,
undefined
);
}
// Remove state after verification (one-time use) // Remove state after verification (one-time use)
this.stateMap.delete(handle); this.stateMap.delete(handle);
@ -106,10 +114,6 @@ export class OidcStateStore implements SessionStore {
* Generate a cryptographically secure random handle * Generate a cryptographically secure random handle
*/ */
private generateHandle() { private generateHandle() {
return ( return randomBytes(32).toString('hex');
Math.random().toString(36).substring(2, 15) + }
Math.random().toString(36).substring(2, 15) +
Date.now().toString(36)
);
}
} }

Loading…
Cancel
Save