Files
wekan/server/methods/sessions.js
T
Lauri Ojansivu a242275be8 Where I am signed in, with Sign out per session; and BACKUP_PASSPHRASE encrypts the Admin Panel backups.
The last of docs/Compliance/README.md's P3 list:

- Member Settings / Privacy and my data lists every session of the
  account - this browser first, when each signed in, and when last active
  where idle logout records it - each with Sign out, which ends just that
  one. A session is named by an opaque id, never its token or hash.
  Admin Panel / People's user popup has Log out everywhere for an account
  (adminLogoutUser, in the Audit log) (models/lib/sessionList.js,
  server/methods/sessions.js).
- BACKUP_PASSPHRASE encrypts every Admin Panel backup as it is written, to
  disk or to cloud storage: AES-256-GCM, the key stretched with scrypt, the
  salt and IV in the file's own header. A restore recognises the header,
  decrypts beside the file and removes the copy whatever happens; a wrong
  passphrase or a changed file is refused, and an older plain backup still
  restores (server/lib/backupEncryption.js). On every platform, the snap and
  the Helm chart (from a Secret).

App-level encryption of attachments on disk is left to a maintainer
decision (TODO.md): disk encryption covers it without changing every read
path.

Tested against a live server: tests/playwright/specs/backup-passphrase.e2e.js
writes an encrypted backup and restores it, and compliance-p3.e2e.js ends one
session of two. Four new strings, translated in every language. Low
confidence: ace, ak, ay, bi, bm, bua, chr, csb, cv, dz, ee, ff, fj, gn, gv,
haw, iu, kl, kok, ks, kw, lg, lld, nah, nd, nso, bo, fur, mai, bho, ary,
tig, ti, wal, ve-PP, ve-CC, ve, vo, tlh, zgh, wa, wa-RR, rup, sah, se, scn,
sc, sm, to, tpi, ts, ss, st, tn, rn, rw, ny, om, pap, qu, rm, szl, uz-AR,
ug, tt, yi, yue_CN, wuu-Hans, wo, xh.

Thanks to xet7 !
2026-11-24 05:56:38 +02:00

55 lines
2.6 KiB
JavaScript

// Where an account is signed in, and ending one session (models/lib/sessionList.js).
//
// getMySessions() the caller's own sessions
// endMySession(id) ends one of the caller's own sessions
// adminLogoutUser(userId) a site administrator ends every session of an
// account; in the Audit log
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { check } from 'meteor/check';
import crypto from 'crypto';
const { sessionRows, tokenFor } = require('/models/lib/sessionList');
const { isSiteAdmin } = require('/models/lib/tenantAdmin');
const idOf = hashed => crypto.createHash('sha256').update(`session:${hashed}`).digest('hex').slice(0, 16);
async function tokensOf(userId) {
const user = await Meteor.users.findOneAsync(userId, { fields: { 'services.resume.loginTokens': 1 } });
return (user && user.services && user.services.resume && user.services.resume.loginTokens) || [];
}
Meteor.methods({
async getMySessions() {
if (!this.userId) throw new Meteor.Error('not-authorized');
const tokens = await tokensOf(this.userId);
const lastActive = {};
try {
const { IdleSessions } = require('/server/idleLogout');
for (const s of await IdleSessions.find({ userId: this.userId }, { fields: { lastActiveAt: 1 } }).fetchAsync()) {
lastActive[s._id] = s.lastActiveAt;
}
} catch (e) { /* last activity is only known while idle logout is on */ }
const currentHashed = this.connection ? Accounts._getLoginToken(this.connection.id) : null;
return sessionRows(tokens, { currentHashed, lastActive, idOf });
},
async endMySession(id) {
check(id, String);
if (!this.userId) throw new Meteor.Error('not-authorized');
const hashed = tokenFor(await tokensOf(this.userId), id, idOf);
if (!hashed) throw new Meteor.Error('session-not-found');
// Only the caller's own account, only that token. Meteor closes the
// session whose token is gone.
await Meteor.users.updateAsync(this.userId, { $pull: { 'services.resume.loginTokens': { hashedToken: hashed } } });
return true;
},
async adminLogoutUser(userId) {
check(userId, String);
const admin = this.userId ? await Meteor.users.findOneAsync(this.userId, { fields: { isAdmin: 1, loginDisabled: 1, orgs: 1, teams: 1 } }) : null;
if (!admin || admin.loginDisabled || !isSiteAdmin(admin)) throw new Meteor.Error('not-authorized');
const n = await Meteor.users.updateAsync(userId, { $set: { 'services.resume.loginTokens': [] } });
if (!n) throw new Meteor.Error('user-not-found');
return true;
},
});