Skip to content

Commit db65f1c

Browse files
unifiedjdclaude
andauthored
Fix OAuth strategy registration and trust proxy for reverse-proxy deploys (#1)
Register Passport strategies under their provider name so passport.authenticate('azure'|'google'|'okta'|'auth0'|'custom') resolves correctly; previously the OAuth2Strategy registered under its default name 'oauth2', causing "Unknown authentication strategy" 500s at /auth/login. Also honor the EXPRESS_TRUST_PROXY env var so Azure Container Apps (and other reverse proxies) don't trigger express-rate-limit X-Forwarded-For validation errors. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a186423 commit db65f1c

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/servers/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ if (TRANSPORT === 'stdio') {
394394
// Disable X-Powered-By header for security
395395
app.disable('x-powered-by');
396396
397+
// Trust reverse proxy (Azure Container Apps, Cloudflare, etc.) so that
398+
// req.ip and X-Forwarded-For are honored correctly by express-rate-limit.
399+
// Set EXPRESS_TRUST_PROXY to a number of hops, a CIDR, "true", or leave unset.
400+
const trustProxy = process.env.EXPRESS_TRUST_PROXY;
401+
if (trustProxy) {
402+
const numeric = Number(trustProxy);
403+
app.set('trust proxy', Number.isFinite(numeric) ? numeric : trustProxy === 'true' ? true : trustProxy);
404+
}
405+
397406
// Request/Response logging middleware
398407
app.use((req: Request, res: Response, next: NextFunction) => {
399408
const startTime = Date.now();
@@ -958,11 +967,11 @@ if (TRANSPORT === 'stdio') {
958967
// OAuth routes (if configured)
959968
if (oauthConfig) {
960969
const scopeArray = oauthConfig.scope ? oauthConfig.scope.split(',') : undefined;
961-
app.get('/auth/login', loginLimiter, passport.authenticate(oauthConfig.provider === 'custom' ? 'oauth2' : oauthConfig.provider, { scope: scopeArray }));
970+
app.get('/auth/login', loginLimiter, passport.authenticate(oauthConfig.provider, { scope: scopeArray }));
962971

963972
app.get(
964973
'/auth/callback',
965-
passport.authenticate(oauthConfig.provider === 'custom' ? 'oauth2' : oauthConfig.provider, { failureRedirect: '/' }),
974+
passport.authenticate(oauthConfig.provider, { failureRedirect: '/' }),
966975
(req: Request, res: Response) => {
967976
if (req.user && req.session) {
968977
const user = req.user as OAuthUser;

src/utils/core/oauth-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface OAuthUser {
3030
*/
3131
export function configureOAuthStrategy(config: OAuthConfig): void {
3232
const strategy = createStrategy(config);
33-
passport.use(strategy);
33+
passport.use(config.provider, strategy);
3434

3535
// Serialize user for session storage
3636
passport.serializeUser((user: any, done) => {

0 commit comments

Comments
 (0)