mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
WHAT WAS ALREADY THERE, checked before writing any of this: the DDP login has
wekan-accounts-lockout (per user, now per user+address), the REST login has
server/lib/loginAttemptThrottle.js (per address, in memory), and
server/lib/loginTimingDefense.js equalises timing so a missing user cannot be
told from a wrong password. Nothing anywhere does increasing delays, and nothing
at all blocks an address. So this extends the lockout decision rather than
adding a second mechanism beside it.
THE LOCKOUT ON ITS OWN IS A STEP FUNCTION: two failures cost nothing, the third
costs sixty seconds. A guesser spends the free attempts of every window and
waits; somebody who mistyped gets no sign they are about to be locked out. A
delay that GROWS - 1s, 2s, 4s, 8s, capped - costs a guesser far more than it
costs a person, and it degrades instead of slamming shut: the account is never
unavailable, only slower to try again.
Per (user, source address), like the counter, and for the same reason: an
attacker must not be able to slow down the account's owner. A correct password
ignores the delay entirely and clears it. An attempt refused for being too soon
is NOT counted - otherwise trying faster would reach the lockout faster, and
impatience would become a weapon against the address.
Two settings, beside the three the lockout already has: known-loginDelayBase
(1s) and known-loginDelayMax (30s). Base 0 switches delays off and leaves the
lockout behaving exactly as before, so an instance that does not want this is
not forced into it.
AND A BUG OF MINE, found by looking for existing code: knownUser.js had grown a
`require('/models/lib/accountLockout')`. A Meteor package is compiled separately
from the app and cannot import app modules - no other package here reaches
across that boundary. The check is inlined and a test fails if the import comes
back.
Thanks to xet7 !
92 lines
2.9 KiB
JavaScript
92 lines
2.9 KiB
JavaScript
import { Mongo } from 'meteor/mongo';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
const { SimpleSchema } = require('/imports/simpleSchema');
|
|
|
|
const LockoutSettings = new Mongo.Collection('lockoutSettings');
|
|
|
|
LockoutSettings.attachSchema(
|
|
new SimpleSchema({
|
|
_id: {
|
|
type: String,
|
|
},
|
|
value: {
|
|
type: Number,
|
|
},
|
|
category: {
|
|
type: String,
|
|
},
|
|
sort: {
|
|
type: Number,
|
|
},
|
|
createdAt: {
|
|
type: Date,
|
|
optional: true,
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
if (this.isInsert) {
|
|
return new Date();
|
|
} else if (this.isUpsert) {
|
|
return { $setOnInsert: new Date() };
|
|
} else {
|
|
this.unset();
|
|
}
|
|
},
|
|
},
|
|
modifiedAt: {
|
|
type: Date,
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
if (this.isInsert || this.isUpsert || this.isUpdate) {
|
|
return new Date();
|
|
} else {
|
|
this.unset();
|
|
}
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
|
|
LockoutSettings.helpers({
|
|
getKnownConfig() {
|
|
// Fetch all settings in one query instead of 3 separate queries
|
|
const settings = LockoutSettings.find({
|
|
_id: { $in: ['known-failuresBeforeLockout', 'known-lockoutPeriod', 'known-failureWindow',
|
|
'known-loginDelayBase', 'known-loginDelayMax'] }
|
|
}, { fields: { _id: 1, value: 1 } }).fetch();
|
|
|
|
const settingsMap = {};
|
|
settings.forEach(s => { settingsMap[s._id] = s.value; });
|
|
|
|
return {
|
|
failuresBeforeLockout: settingsMap['known-failuresBeforeLockout'] || 3,
|
|
lockoutPeriod: settingsMap['known-lockoutPeriod'] || 60,
|
|
failureWindow: settingsMap['known-failureWindow'] || 15,
|
|
// The increasing delay after a wrong password (lockoutDecision.js), in
|
|
// seconds: the first failure costs `loginDelayBase`, and each one after
|
|
// doubles it up to `loginDelayMax`. 0 for the base switches delays off
|
|
// entirely and leaves the lockout behaving as it did before.
|
|
loginDelayBase: settingsMap['known-loginDelayBase'] === undefined
|
|
? 1 : settingsMap['known-loginDelayBase'],
|
|
loginDelayMax: settingsMap['known-loginDelayMax'] === undefined
|
|
? 30 : settingsMap['known-loginDelayMax']
|
|
};
|
|
},
|
|
getUnknownConfig() {
|
|
// Fetch all settings in one query instead of 3 separate queries
|
|
const settings = LockoutSettings.find({
|
|
_id: { $in: ['unknown-failuresBeforeLockout', 'unknown-lockoutPeriod', 'unknown-failureWindow'] }
|
|
}, { fields: { _id: 1, value: 1 } }).fetch();
|
|
|
|
const settingsMap = {};
|
|
settings.forEach(s => { settingsMap[s._id] = s.value; });
|
|
|
|
return {
|
|
failuresBeforeLockout: settingsMap['unknown-failuresBeforeLockout'] || 3,
|
|
lockoutPeriod: settingsMap['unknown-lockoutPeriod'] || 60,
|
|
failureWindow: settingsMap['unknown-failureWindow'] || 15
|
|
};
|
|
}
|
|
});
|
|
|
|
export default LockoutSettings;
|