🔑 fix: Keep Passkey Sign-In Reachable When Email Login Is Disabled (#16254)

The passkey login routes sat behind validateEmailLogin, and the client
hid the passkey button unless email login was enabled, so a deployment
with ALLOW_PASSKEY_LOGIN=true and ALLOW_EMAIL_LOGIN=false advertised a
sign-in method it rejected. Gate the routes on the passkey limiter,
same-origin and ban checks only, and render the button on passkey
enablement alone.
This commit is contained in:
Marco Beretta 2026-09-23 23:56:53 +02:00 • committed by GitHub
parent 33f02f1148
commit 59014b53c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 10 deletions

View file

@ -76,7 +76,7 @@ jest.mock('~/server/middleware', () => {
setTwoFactorTempUser: (...args) => mockSetTwoFactorTempUser(...args),
twoFactorTempLimiter: pass,
checkBan: pass,
validateEmailLogin: pass,
validateEmailLogin: jest.requireActual('~/server/middleware/validateEmailLogin'),
requireLocalAuth: (...args) => mockRequireLocalAuth(...args),
requireLdapAuth: (...args) => mockRequireLocalAuth(...args),
registerLimiter: pass,
@ -213,4 +213,40 @@ describe('local login endpoints reject cross-site submissions', () => {
expect(mockLoginController).toHaveBeenCalledTimes(1);
});
describe('with email login disabled', () => {
beforeEach(() => {
process.env.ALLOW_EMAIL_LOGIN = 'false';
});
afterEach(() => {
delete process.env.ALLOW_EMAIL_LOGIN;
});
it('still rejects the password login', async () => {
await request(app)
.post('/api/auth/login')
.send({ email: 'user@example.com', password: 'password' })
.expect(403);
expect(mockLoginController).not.toHaveBeenCalled();
});
it('keeps passkey sign-in reachable', async () => {
const {
authenticatePasskey,
loginPasskeyOptions,
} = require('~/server/controllers/auth/PasskeyController');
await request(app).post('/api/auth/passkey/login/options').expect(204);
await request(app)
.post('/api/auth/passkey/login/verify')
.send({ sessionId: 'session', credential: { id: 'credential' } })
.expect(204);
expect(loginPasskeyOptions).toHaveBeenCalledTimes(1);
expect(authenticatePasskey).toHaveBeenCalledTimes(1);
expect(mockLoginController).toHaveBeenCalledTimes(1);
});
});
});

View file

@ -116,7 +116,6 @@ router.post(
'/passkey/login/options',
middleware.logHeaders,
middleware.passkeyLimiter,
middleware.validateEmailLogin,
middleware.checkBan,
loginPasskeyOptions,
);
@ -125,7 +124,6 @@ router.post(
middleware.logHeaders,
middleware.requireSameOrigin,
middleware.passkeyLimiter,
middleware.validateEmailLogin,
middleware.checkBan,
authenticatePasskey,
setBalanceConfig,

View file

@ -119,11 +119,7 @@ function SocialLoginRender({
),
};
/** The passkey sign-in routes sit behind the email-login gate; management does not. */
const passkeyEnabled =
showPasskey &&
startupConfig.passkeyLoginEnabled === true &&
startupConfig.emailLoginEnabled !== false;
const passkeyEnabled = showPasskey && startupConfig.passkeyLoginEnabled === true;
const socialEnabled =
startupConfig.socialLoginEnabled === true && (startupConfig.socialLogins?.length ?? 0) > 0;

View file

@ -318,7 +318,7 @@ test.describe('passkeys', () => {
await expect(page.getByRole('button', { name: 'Sign in with a passkey' })).toHaveCount(0);
});
test('with email login off, passkey sign-in is hidden but management stays @scenario:passkey-management-stays-when-email-login-off', async ({
test('with email login off, passkey sign-in and management both stay @scenario:passkey-management-stays-when-email-login-off', async ({
browser,
playwright,
baseURL,
@ -340,7 +340,7 @@ test.describe('passkeys', () => {
await expect(passkeysDialog.getByText('Office key', { exact: true })).toBeVisible();
await logOut(page);
await expect(page.getByRole('button', { name: 'Sign in with a passkey' })).toHaveCount(0);
await expect(page.getByRole('button', { name: 'Sign in with a passkey' })).toBeVisible();
});
test('a passkey sign-in on a 2FA account asks for the second factor @scenario:passkey-sign-in-hands-off-to-2fa', async ({