mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
New passwords: PASSWORD_MIN_LENGTH (default 8) and PASSWORD_CHECK_PWNED (off by default), in Admin Panel / People / Login and on every platform. The browser sends a password to Meteor hashed, so the server checks every password that reaches it as text - Admin Panel Set password and Add user, POST /users/register - and the sign-up, Change Password, reset and enrolment forms check in the browser. Signing in is never checked, so an existing shorter password keeps working until it is changed. A breached password is found with Have I Been Pwned's k-anonymity range API: only 5 hex digits of the SHA-1 leave WeKan, and an unreachable service never refuses a password. REQUIRE_2FA: off (default), admins or all. It covers accounts that sign in with a WeKan password; LDAP, OAuth2, SAML, CAS and Sandstorm accounts sign in through an identity provider and are not asked. Such an account can still sign in, sees only the 2FA set-up until it has 2FA, and until then the server refuses every method and publication but signing in and enrolling, HTTP routes do not accept its login and the REST API gives it no token. Once required, 2FA cannot be switched off. The new interface strings are pending translation. Thanks to xet7 !
77 lines
3.1 KiB
JavaScript
77 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
// REQUIRE_2FA (Admin Panel / People / Login): make two-factor authentication
|
|
// compulsory - 'off' (the default), 'admins' or 'all'.
|
|
//
|
|
// WHO IT APPLIES TO. accounts-2fa asks for the code on a PASSWORD login only, so
|
|
// the requirement covers the accounts that sign in with a WeKan password:
|
|
// authenticationMethod 'password' and a stored password. An LDAP, OAuth2,
|
|
// SAML, CAS or Sandstorm account signs in through its identity provider, whose
|
|
// own second factor is where that belongs; making it enrol here would protect
|
|
// nothing, because its login never asks.
|
|
//
|
|
// HOW IT IS ENFORCED (server/requireTwoFactor.js). Signing in is still allowed
|
|
// - the account has to sign in to enrol - but until it has 2FA:
|
|
// - every Meteor method but signing in and out and the 2FA methods is refused,
|
|
// and every publication but the login page's is empty;
|
|
// - HTTP routes do not accept its login (server/lib/activeUser.js), and the
|
|
// REST API does not give it a token;
|
|
// - the browser shows only the 2FA set-up, over everything else.
|
|
// Once required, it cannot switch 2FA off again.
|
|
//
|
|
// Pure: no Meteor. Shared by the server, the client and plain-Node tests.
|
|
|
|
const MODES = ['off', 'admins', 'all'];
|
|
|
|
function requireTwoFactorMode(get) {
|
|
const value = String(get('REQUIRE_2FA') || '').trim().toLowerCase();
|
|
return MODES.includes(value) ? value : 'off';
|
|
}
|
|
|
|
function signsInWithPassword(user) {
|
|
return !!(user && (user.authenticationMethod || 'password') === 'password'
|
|
&& user.services && user.services.password);
|
|
}
|
|
|
|
// Does the requirement cover this account?
|
|
function twoFactorApplies(user, mode) {
|
|
if (!user || mode === 'off' || !MODES.includes(mode)) return false;
|
|
if (!signsInWithPassword(user)) return false;
|
|
return mode === 'all' || (mode === 'admins' && user.isAdmin === true);
|
|
}
|
|
|
|
// The same test accounts-2fa makes (Accounts._check2faEnabled).
|
|
function hasTwoFactor(user) {
|
|
const tfa = user && user.services && user.services.twoFactorAuthentication;
|
|
return !!(tfa && tfa.secret && tfa.type === 'otp');
|
|
}
|
|
|
|
function missingTwoFactor(user, mode) {
|
|
return twoFactorApplies(user, mode) && !hasTwoFactor(user);
|
|
}
|
|
|
|
// Methods an account without its required 2FA may still call: signing in and
|
|
// out, enrolling, and what the sign-in page asks before anybody is signed in.
|
|
const ALLOWED_METHODS = new Set([
|
|
'login', 'logout', 'logoutOtherClients', 'getNewToken', 'removeOtherTokens',
|
|
'generate2faActivationQrCode', 'enableUser2fa', 'has2faEnabled',
|
|
'getTwoFactorRequirement', 'getPasswordPolicy', 'passwordPwnedRange',
|
|
'isPasswordLoginEnabled', 'isDisableRegistration', 'isDisableForgotPassword',
|
|
'isOidcRedirectionEnabled', 'getOauthLogoutUrl', 'getOauthServerUrl', 'getOauthDashboardUrl',
|
|
'getDefaultAuthenticationMethod', 'getAuthenticationsEnabled',
|
|
]);
|
|
|
|
// Publications the sign-in page already shows to nobody in particular.
|
|
const ALLOWED_PUBLICATIONS = new Set(['setting', 'user-authenticationMethod']);
|
|
|
|
module.exports = {
|
|
MODES,
|
|
requireTwoFactorMode,
|
|
twoFactorApplies,
|
|
hasTwoFactor,
|
|
missingTwoFactor,
|
|
signsInWithPassword,
|
|
ALLOWED_METHODS,
|
|
ALLOWED_PUBLICATIONS,
|
|
};
|