mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-19 14:33:38 +00:00
* 🔒 fix: Enforce ALLOW_EMAIL_LOGIN on Backend Login Route
ALLOW_EMAIL_LOGIN=false previously only hid the login form; POST
/api/auth/login stayed mounted and accepted valid credentials. Add a
validateEmailLogin middleware (mirroring validateRegistration /
validatePasswordReset) that rejects login with 403 when the flag is
disabled, with an ALLOW_EMAIL_LOGIN_OVERRIDE escape hatch for
intentional direct API login (each use logged with request IP).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix: Gate admin local login by email login flag
* fix: Move email login gate into api package
* test: Avoid mutating readonly request ip
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Danny Avila <danny@librechat.ai>
27 lines
852 B
TypeScript
27 lines
852 B
TypeScript
import { logger } from '@librechat/data-schemas';
|
|
import type { NextFunction, Request, Response } from 'express';
|
|
import { isEnabled } from '~/utils';
|
|
|
|
export function validateEmailLogin(
|
|
req: Request,
|
|
res: Response,
|
|
next: NextFunction,
|
|
): Response | void {
|
|
const emailLoginEnabled =
|
|
process.env.ALLOW_EMAIL_LOGIN === undefined || isEnabled(process.env.ALLOW_EMAIL_LOGIN);
|
|
if (emailLoginEnabled) {
|
|
next();
|
|
return;
|
|
}
|
|
|
|
if (isEnabled(process.env.ALLOW_EMAIL_LOGIN_OVERRIDE)) {
|
|
logger.warn(
|
|
`[validateEmailLogin] Email login is disabled; allowing login attempt via ALLOW_EMAIL_LOGIN_OVERRIDE. IP: ${req.ip}`,
|
|
);
|
|
next();
|
|
return;
|
|
}
|
|
|
|
logger.warn(`[validateEmailLogin] Login attempt while email login is disabled. IP: ${req.ip}`);
|
|
return res.status(403).json({ message: 'Email login is not allowed.' });
|
|
}
|