mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Two items of docs/Compliance/README.md's P3 list ([GDPR] Art. 5(1)(c) data minimisation and 5(1)(e) storage limitation): - LOGIN_ADDRESS_RECORDED=false: WeKan writes down no sign-in address at all - not on the account, not in Login locations or Offices; a sign-in with a short password is still listed, without where from. The lockout still counts failed sign-ins per address, to stop guessing. - USERS_ANONYMIZE_INACTIVE_AFTER_DAYS: an account disabled for inactivity (USERS_DISABLE_INACTIVE_AFTER_DAYS) is anonymised that many days later, as Member Settings / Anonymize does - its data elsewhere erased first - in the same nightly run. Disabling now records loginDisabledAt, enabling clears it, and accounts disabled before it existed start their clock now. Never an administrator, an account disabled by hand or by LDAP, or one enabled again; off unless set. Both on every platform, the snap and the Helm chart. Thanks to xet7 !
124 lines
5.0 KiB
JavaScript
124 lines
5.0 KiB
JavaScript
'use strict';
|
|
|
|
// Disable accounts nobody has used for a while (USERS_DISABLE_INACTIVE_AFTER_DAYS).
|
|
// Pure decisions only, so they are testable without a server or a database -
|
|
// see tests/inactiveUsers.test.cjs. The nightly job is server/disableInactiveUsers.js.
|
|
//
|
|
// "Last used" is the newest of:
|
|
// lastConnectionDate every login, refreshed by the open-session heartbeat
|
|
// (server/lastActiveOnLogin.js, client/lastActiveHeartbeat.js)
|
|
// inactivityClockStart when the clock (re)started: stamped by the job for an
|
|
// account it has never seen used, and on every re-enable
|
|
// (server/models/users.js), so an admin who re-enables a
|
|
// user does not see them disabled again the next night.
|
|
//
|
|
// createdAt is deliberately NOT a fallback. lastConnectionDate has only been
|
|
// recorded since the presence feature; every account older than that has none,
|
|
// and measuring those from createdAt would disable almost the whole instance on
|
|
// the first run. Instead the first run starts their clock, and they are judged
|
|
// N days later like everybody else.
|
|
|
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
|
// Why an account is disabled, so that one mechanism does not undo another:
|
|
// LDAP background sync re-enables users it finds in the directory, but not
|
|
// one disabled for inactivity (packages/wekan-ldap/server/presenceSync.js).
|
|
const REASON_INACTIVE = 'inactive';
|
|
const REASON_LDAP = 'ldap';
|
|
|
|
// Accepts a number or a string of digits; anything else, 0 or negative is off.
|
|
function normalizeInactiveDays(value) {
|
|
if (value === undefined || value === null) return 0;
|
|
const text = String(value).trim().replace(/^(['"])(.*)\1$/, '$2').trim();
|
|
if (!/^\d+$/.test(text)) return 0;
|
|
const days = Number(text);
|
|
return Number.isSafeInteger(days) && days > 0 ? days : 0;
|
|
}
|
|
|
|
function toTime(value) {
|
|
if (!value) return NaN;
|
|
const date = value instanceof Date ? value : new Date(value);
|
|
return date.getTime();
|
|
}
|
|
|
|
function lastUsedTime(user) {
|
|
const times = [toTime(user.lastConnectionDate), toTime(user.inactivityClockStart)]
|
|
.filter(t => !Number.isNaN(t));
|
|
return times.length ? Math.max(...times) : NaN;
|
|
}
|
|
|
|
/**
|
|
* What the nightly job should do with one account:
|
|
* 'disable' unused for at least `days` days
|
|
* 'start-clock' never seen used: start counting from `now`
|
|
* null leave it alone
|
|
*/
|
|
function inactivityAction(user, days, now = new Date()) {
|
|
if (!user || !days) return null;
|
|
if (user.loginDisabled === true) return null;
|
|
// Never lock the instance out: administrators are not disabled automatically.
|
|
if (user.isAdmin === true) return null;
|
|
// Anonymised accounts are already disabled; this is belt and braces. Import
|
|
// placeholders (server/lib/importPlaceholderUsers.js) are created disabled.
|
|
if (user.anonymized === true) return null;
|
|
const last = lastUsedTime(user);
|
|
if (Number.isNaN(last)) return 'start-clock';
|
|
const nowTime = toTime(now);
|
|
if (Number.isNaN(nowTime)) return null;
|
|
return nowTime - last >= days * DAY_MS ? 'disable' : null;
|
|
}
|
|
|
|
// Selector for the candidates, so the job reads only accounts that could
|
|
// possibly be disabled. inactivityAction() still decides per account.
|
|
function inactiveCandidateSelector(days, now = new Date()) {
|
|
const cutoff = new Date(toTime(now) - days * DAY_MS);
|
|
return {
|
|
loginDisabled: { $ne: true },
|
|
isAdmin: { $ne: true },
|
|
$and: [
|
|
{ $or: [{ lastConnectionDate: { $exists: false } }, { lastConnectionDate: null }, { lastConnectionDate: { $lte: cutoff } }] },
|
|
{ $or: [{ inactivityClockStart: { $exists: false } }, { inactivityClockStart: null }, { inactivityClockStart: { $lte: cutoff } }] },
|
|
],
|
|
};
|
|
}
|
|
|
|
// USERS_ANONYMIZE_INACTIVE_AFTER_DAYS (docs/Compliance/README.md P3; [GDPR]
|
|
// Art. 5(1)(e) storage limitation): an account disabled for inactivity is
|
|
// anonymised that many days after it was disabled - the same erasure as
|
|
// Member Settings / Anonymize (models/lib/userErasure.js). Off unless set; an
|
|
// administrator, an account disabled for another reason or by hand, and one
|
|
// enabled again (which clears loginDisabledAt) are never touched.
|
|
function anonymizeDueSelector(days, now = new Date()) {
|
|
const cutoff = new Date(toTime(now) - days * DAY_MS);
|
|
return {
|
|
loginDisabled: true,
|
|
loginDisabledReason: REASON_INACTIVE,
|
|
loginDisabledAt: { $lte: cutoff },
|
|
isAdmin: { $ne: true },
|
|
anonymized: { $ne: true },
|
|
};
|
|
}
|
|
|
|
// Accounts disabled for inactivity before loginDisabledAt existed: their
|
|
// clock starts now, so none is anonymised without the full number of days.
|
|
function undatedInactiveSelector() {
|
|
return {
|
|
loginDisabled: true,
|
|
loginDisabledReason: REASON_INACTIVE,
|
|
$or: [{ loginDisabledAt: { $exists: false } }, { loginDisabledAt: null }],
|
|
anonymized: { $ne: true },
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
anonymizeDueSelector,
|
|
undatedInactiveSelector,
|
|
DAY_MS,
|
|
REASON_INACTIVE,
|
|
REASON_LDAP,
|
|
normalizeInactiveDays,
|
|
lastUsedTime,
|
|
inactivityAction,
|
|
inactiveCandidateSelector,
|
|
};
|