mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Password login disabled: the login method refuses a password request before any lookup, so the answer is the same for a right and a wrong password.
The validateLoginAttempt hook refused every password sign-in, but a later
hook of the same chain - the lockout's "User not found" / "Incorrect
password" - overwrote its error for a wrong password and left it for a right
one, so while password login was off the answer still said whether a
password was right. Meteor's login method now refuses a { user, password }
request itself (loginRequestRefusal), synchronously before the original
method runs; the hook stays for resetPassword, verifyEmail and createUser.
Found by the new Playwright spec.
Thanks to xet7 !
This commit is contained in:
1 parent
bdaad563ac
commit
47fc873e1d
5 files changed
+76
-2
No files matched your search
@@ -125,8 +125,10 @@ tally names the account (when the call had one) and the address it came from.
|
||||
decides the login settings: `passwordLoginRefusal` for a DDP sign-in,
|
||||
`restPasswordLoginRoute` for `POST /users/login`, `forgotPasswordRefusal`
|
||||
for `forgotPassword`. [server/authentication.js](../../../server/authentication.js)
|
||||
asks it in an `Accounts.validateLoginAttempt` hook and in a wrapper around
|
||||
Meteor's `forgotPassword` method; [server/apiAuthRoutes.js](../../../server/apiAuthRoutes.js)
|
||||
asks it in a wrapper around Meteor's `login` method (`loginRequestRefusal`,
|
||||
before any account is looked up, so a right and a wrong password get the
|
||||
same answer), in an `Accounts.validateLoginAttempt` hook for the other
|
||||
password sign-ins, and in a wrapper around Meteor's `forgotPassword` method; [server/apiAuthRoutes.js](../../../server/apiAuthRoutes.js)
|
||||
asks it before the user lookup.
|
||||
- [models/lib/selfAccountRemoval.js](../../../models/lib/selfAccountRemoval.js)
|
||||
decides deleting or anonymizing your own account (`selfRemovalRefusal`),
|
||||
|
||||
@@ -55,6 +55,20 @@ function passwordLoginRefusal({ type, loginRequest, env } = {}) {
|
||||
return 'password-login-disabled';
|
||||
}
|
||||
|
||||
// Meteor's `login` method, before any account is looked up: a request in the
|
||||
// password service's own shape ({ user, password }) while password login is
|
||||
// off. Refused there rather than only in validateLoginAttempt, because a
|
||||
// later hook of that chain (the lockout's "User not found" / "Incorrect
|
||||
// password") would overwrite the refusal for a wrong password and leave it
|
||||
// for a right one - answering, while password login is off, whether a
|
||||
// password is right. An LDAP request ({ ldap: true, ldapPass }) has no
|
||||
// `password` and is never refused here.
|
||||
function loginRequestRefusal(loginRequest, env) {
|
||||
if (!loginRequest || typeof loginRequest !== 'object') return null;
|
||||
if (!('password' in loginRequest) || !('user' in loginRequest)) return null;
|
||||
return passwordLoginEnabled(env) ? null : 'password-login-disabled';
|
||||
}
|
||||
|
||||
// POST /users/login: which way a username/email + password request goes.
|
||||
// 'refuse' - password login is off and the request cannot be LDAP
|
||||
// 'ldap' - password login is off, LDAP is on and a username was given:
|
||||
@@ -82,6 +96,7 @@ module.exports = {
|
||||
passwordLoginEnabled,
|
||||
isLdapFallback,
|
||||
passwordLoginRefusal,
|
||||
loginRequestRefusal,
|
||||
restPasswordLoginRoute,
|
||||
forgotPasswordRefusal,
|
||||
REFUSAL_MESSAGES,
|
||||
|
||||
@@ -221,6 +221,31 @@ Meteor.startup(() => {
|
||||
throw new Meteor.Error(refusal, REFUSAL_MESSAGES[refusal]);
|
||||
});
|
||||
|
||||
// The `login` method itself refuses a { user, password } request first
|
||||
// (models/lib/passwordLoginPolicy.js loginRequestRefusal), so the answer is
|
||||
// the same whatever the password and the account: the hook above stays for
|
||||
// resetPassword, verifyEmail and createUser. Decided synchronously, so the
|
||||
// original method's own check() still counts for audit-argument-checks.
|
||||
const loginHandlers = Meteor.server && Meteor.server.method_handlers;
|
||||
const originalLogin = loginHandlers && loginHandlers.login;
|
||||
if (typeof originalLogin === 'function') {
|
||||
loginHandlers.login = function guardedLogin(...args) {
|
||||
const { loginRequestRefusal, REFUSAL_MESSAGES } = require('/models/lib/passwordLoginPolicy');
|
||||
const refusal = loginRequestRefusal(args[0], authEnvObject);
|
||||
if (refusal) {
|
||||
check(args, [Match.Any]);
|
||||
try {
|
||||
require('/server/lib/securityLog').record({
|
||||
key: 'authn.password-login-disabled', action: 'blocked', source: 'ddp:login',
|
||||
detail: 'Password sign-in refused while password login is disabled.',
|
||||
});
|
||||
} catch (e) { /* logging must never break the guard */ }
|
||||
throw new Meteor.Error(refusal, REFUSAL_MESSAGES[refusal]);
|
||||
}
|
||||
return originalLogin.apply(this, args);
|
||||
};
|
||||
}
|
||||
|
||||
// DISABLE_FORGOT_PASSWORD, and password login off, refuse Meteor's own
|
||||
// forgotPassword method, which e-mails a reset link whatever the page shows.
|
||||
const handlers = Meteor.server && Meteor.server.method_handlers;
|
||||
|
||||
@@ -60,6 +60,18 @@ describe('password login disabled is refused on the server', function () {
|
||||
expect(a.error && a.error.error).to.equal('password-login-disabled');
|
||||
});
|
||||
|
||||
it('refuses the login method itself the same way, for a right and a wrong password', async function () {
|
||||
if (!passwordLoginOff()) this.skip();
|
||||
for (const password of [PASSWORD, 'wrong password']) {
|
||||
let error;
|
||||
try {
|
||||
await Meteor.server.method_handlers.login.call({ connection: { id: Random.id(), clientAddress: '198.51.100.7',
|
||||
httpHeaders: {}, onClose() {} }, setUserId() {}, userId: null }, { user: { username }, password });
|
||||
} catch (e) { error = e; }
|
||||
expect(error && error.error, password).to.equal('password-login-disabled');
|
||||
}
|
||||
});
|
||||
|
||||
it('refuses the sign-in that resetPassword and verifyEmail make', async function () {
|
||||
if (!passwordLoginOff()) this.skip();
|
||||
for (const methodName of ['resetPassword', 'verifyEmail']) {
|
||||
|
||||
@@ -62,6 +62,17 @@ test('but not without LDAP, without the fallback, or without ldap:true (negative
|
||||
env: { ...OFF, LDAP_ENABLE: 'true', LDAP_LOGIN_FALLBACK: 'true' } }), 'password-login-disabled');
|
||||
});
|
||||
|
||||
test('the login method refuses a { user, password } request before any lookup, LDAP never', () => {
|
||||
assert.strictEqual(policy.loginRequestRefusal({ user: { username: 'a' }, password: 'x' }, OFF), 'password-login-disabled');
|
||||
assert.strictEqual(policy.loginRequestRefusal({ user: { email: 'a@b' }, password: { digest: 'd', algorithm: 'sha-256' }, code: '1' }, OFF),
|
||||
'password-login-disabled');
|
||||
// negative
|
||||
assert.strictEqual(policy.loginRequestRefusal({ user: { username: 'a' }, password: 'x' }, {}), null);
|
||||
assert.strictEqual(policy.loginRequestRefusal({ ldap: true, username: 'a', ldapPass: 'x', ldapOptions: {} }, OFF), null);
|
||||
assert.strictEqual(policy.loginRequestRefusal({ resume: 'token' }, OFF), null);
|
||||
for (const junk of [null, undefined, 'x', 3]) assert.strictEqual(policy.loginRequestRefusal(junk, OFF), null);
|
||||
});
|
||||
|
||||
test('REST login: refused, or sent to LDAP only, while password login is off', () => {
|
||||
assert.strictEqual(policy.restPasswordLoginRoute({ env: {}, usernameProvided: true }), null);
|
||||
assert.strictEqual(policy.restPasswordLoginRoute({ env: OFF, usernameProvided: true }), 'refuse');
|
||||
@@ -99,6 +110,15 @@ test('DDP: a validateLoginAttempt hook asks passwordLoginRefusal with the login
|
||||
assert.match(authentication, /key: 'authn\.password-login-disabled', action: 'blocked'/);
|
||||
});
|
||||
|
||||
test('DDP: the login method is wrapped, deciding synchronously before the original runs', () => {
|
||||
const wrap = authentication.slice(authentication.indexOf('loginHandlers.login = function guardedLogin(...args) {'));
|
||||
assert.ok(wrap.length > 0);
|
||||
const body = wrap.slice(0, wrap.indexOf('\n };'));
|
||||
assert.match(body, /loginRequestRefusal\(args\[0\], authEnvObject\)/);
|
||||
assert.doesNotMatch(body, /await /, 'no await before the original method, so its check() still counts');
|
||||
assert.ok(body.indexOf('throw new Meteor.Error(refusal') < body.indexOf('return originalLogin.apply(this, args);'));
|
||||
});
|
||||
|
||||
test('DDP: Meteor\'s forgotPassword method is wrapped by forgotPasswordRefusal', () => {
|
||||
assert.match(authentication, /handlers\.forgotPassword = async function guardedForgotPassword/);
|
||||
assert.match(authentication, /forgotPasswordRefusal\(\{ setting: await ReactiveCache\.getCurrentSetting\(\), env: authEnvObject \}\)/);
|
||||
|
||||
Reference in new issue
Block a user