Files
wekan/server/lib/shortPasswordLogins.js
T
Lauri Ojansivu 92fc9b686a LOGIN_ADDRESS_RECORDED=false records no sign-in address, and USERS_ANONYMIZE_INACTIVE_AFTER_DAYS anonymises long-disabled accounts.
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 !
2026-11-24 05:08:23 +02:00

73 lines
3.4 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import ShortPasswordLogins from '/models/shortPasswordLogins';
import { ensureIndex } from '/server/lib/mongoStartup';
// Admin Panel / Problems / Password length (models/lib/shortPasswordLogins.js
// says what a row is and what "fixed" means).
const { cleanFilter, filterSelector, shortLoginUpdate } = require('/models/lib/shortPasswordLogins');
const { addressOf } = require('/models/lib/loginTally');
// The same address resolver and location headers as every other login record
// (server/lib/loginTally.js): two answers to "where from" would not compare.
const { resolveClientKey } = require('/server/lib/loginAttemptThrottle');
const { locationFromHeaders } = require('/models/lib/geoHeaders');
const MAX_PAGE = 100;
export async function recordShortPasswordLogin(user, connection) {
if (!user || !user._id) return;
const raw = resolveClientKey({
headers: connection && connection.httpHeaders,
socketAddress: connection && connection.clientAddress,
forwardedCount: process.env.HTTP_FORWARDED_COUNT,
});
const { value, family } = addressOf(raw);
// LOGIN_ADDRESS_RECORDED=false: the sign-in is listed, without where from.
const recorded = require('/models/lib/loginAddressRetention').addressRecorded({ LOGIN_ADDRESS_RECORDED: process.env.LOGIN_ADDRESS_RECORDED });
await ShortPasswordLogins.upsertAsync({ userId: user._id }, shortLoginUpdate({
username: user.username, now: new Date(), address: recorded ? value : '', family,
location: recorded ? locationFromHeaders(connection && connection.httpHeaders) : null,
}));
}
// The account's password changed: an open row is fixed. A row already fixed
// keeps the date it was first fixed.
export async function markShortPasswordFixed(userId) {
if (!userId) return;
await ShortPasswordLogins.updateAsync({ userId, fixedAt: null }, { $set: { fixedAt: new Date() } });
}
async function requireSiteAdmin(userId) {
const user = userId && await Meteor.users.findOneAsync(userId, { fields: { isAdmin: 1, loginDisabled: 1 } });
if (!user || user.isAdmin !== true || user.loginDisabled === true) throw new Meteor.Error('not-authorized');
}
Meteor.methods({
// One page of the table, newest sign-in first. Site administrators only.
async shortPasswordLoginsPage(options = {}) {
check(options, Match.ObjectIncluding({
filter: Match.Optional(String),
search: Match.Optional(String),
limit: Match.Optional(Match.Integer),
skip: Match.Optional(Match.Integer),
}));
await requireSiteAdmin(this.userId);
const selector = filterSelector(cleanFilter(options.filter));
const search = String(options.search || '').trim().slice(0, 100);
if (search) {
const re = new RegExp(search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
selector.$or = [{ username: re }, { ipv4: re }, { ipv6: re }];
}
const limit = Math.min(Math.max(options.limit || 25, 1), MAX_PAGE);
const skip = Math.max(options.skip || 0, 0);
const total = await ShortPasswordLogins.find(selector).countAsync();
const rows = await ShortPasswordLogins.find(selector, { sort: { at: -1 }, skip, limit }).fetchAsync();
return { rows, total };
},
});
Meteor.startup(async () => {
await ensureIndex(ShortPasswordLogins, { userId: 1 }, { unique: true });
await ensureIndex(ShortPasswordLogins, { fixedAt: 1, at: -1 });
});