feat: Enhance OpenID flow with state parameter handling

This commit is contained in:
Danny Avila 2025-05-25 16:33:34 -04:00
parent 45e4e70986
commit ac2e1b1586
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
2 changed files with 14 additions and 0 deletions

View file

@ -1,6 +1,7 @@
// file deepcode ignore NoRateLimitingForLogin: Rate limiting is handled by the `loginLimiter` middleware
const express = require('express');
const passport = require('passport');
const client = require('openid-client');
const {
checkBan,
logHeaders,
@ -107,6 +108,7 @@ router.get(
'/openid',
passport.authenticate('openid', {
session: false,
state: client.randomState(),
}),
);
@ -115,6 +117,7 @@ router.get(
passport.authenticate('openid', {
failureRedirect: `${domains.client}/oauth/error`,
failureMessage: true,
state: client.randomState(),
session: false,
}),
setBalanceConfig,

View file

@ -28,6 +28,17 @@ class CustomOpenIDStrategy extends OpenIDStrategy {
const hostAndProtocol = process.env.DOMAIN_SERVER;
return new URL(`${hostAndProtocol}${req.originalUrl ?? req.url}`);
}
/**
* Override to ensure proper authorization request parameters
*/
authorizationRequestParams(req, options) {
const params = super.authorizationRequestParams?.(req, options) || {};
if (options?.state != null && options.state && !params.has('state')) {
params.set('state', options.state);
}
return params;
}
}
/**