mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
The last item of docs/Compliance/README.md's P3 list, on the maintainer's decision: while ATTACHMENTS_PASSPHRASE is set (at least 16 characters), a site administrator gets Admin Panel / Attachments / Encrypt, which encrypts or decrypts every attachment on this server's disk in the background with progress, and turns on encryption of new attachments. - AES-256-CTR (server/lib/attachmentEncryption.js), so a download can start anywhere: the counter for any byte is the IV plus its block. The key is stretched from the passphrase with scrypt once per salt and kept in memory. Each file starts with WKATT1, the salt and its own IV; a file without the header is plain and read as before. - Every read goes through FileStoreStrategyFilesystem.getReadStream, which decrypts - byte ranges included - so every address, preview, export and storage move is unchanged; the board export and the WebDAV move, which read the file directly, use the same decrypting read. - New uploads are encrypted after their validation and indexing, which need the plain file; imports, e-mail to card and the REST API by an hourly sweep. Each changed attachment's meta.updatedAt is set, so the filesystem integrity scan sees the change explained. The runs and the switch are in the Audit log. - On every platform, the snap and the Helm chart (from a Secret). Tested against a live server (tests/playwright/specs/attachment-encryption.e2e.js): an attachment encrypted on disk downloads at the same address, whole and as a byte range, and decrypts back to the same bytes. Seven new strings, translated in every language. Low confidence: ace, ak, ay, bi, bm, bo, bua, chr, csb, dz, ee, ff, fj, gn, gv, haw, iu, kl, kok, ks, kw, lg, lld, nah, nap, nd, nso, fur, mg, tlh, tig, ti, wal, om, ve-PP, ve-CC, rup, zgh, uz-AR, sah, vo, wuu-Hans, se, qu, to, sm, ss, ts, ve, ny, rn, tn, st, wa, sc, scn. Thanks to xet7 !
130 lines
6.0 KiB
JavaScript
130 lines
6.0 KiB
JavaScript
'use strict';
|
|
|
|
// Admin Panel / People / Audit log: who, among the site administrators, did
|
|
// what and when - set a password, made somebody an admin, changed a login
|
|
// setting, restored a backup. Admin Panel / Problems answers a different
|
|
// question (what attacks were refused) and folds its events into summaries;
|
|
// an audit trail has to keep every event, so it is a collection of its own
|
|
// (server/adminAudit.js), one document per action, kept AUDIT_KEEP_DAYS.
|
|
//
|
|
// WHAT IS RECORDED: a call, by a site administrator, of one of the methods
|
|
// below - the ones that change who can do what or how the site is configured.
|
|
// An administrator editing cards is a member editing cards and is not here.
|
|
// A call that fails is recorded too, with its error: an attempt is part of
|
|
// the trail.
|
|
//
|
|
// WHAT IS NEVER RECORDED: a password or a secret. The arguments are kept as a
|
|
// short summary, and on the way in:
|
|
// - every value under a key that names a credential (password, secret,
|
|
// token, key, credential, ...) is replaced by [redacted], at any depth;
|
|
// - the arguments that are a password by POSITION (setPassword's first,
|
|
// setCreateUser's fourth) are replaced too;
|
|
// - a password inside a URL (ldap://user:pass@host) is masked.
|
|
//
|
|
// Pure: no Meteor. Shared by the server and plain-Node tests.
|
|
|
|
const AUDIT_KEEP_DAYS = 365;
|
|
|
|
const AUDITED_METHODS = [
|
|
// People
|
|
'setCreateUser', 'setPassword', 'setUsername', 'setEmail', 'setUsernameAndEmail',
|
|
'setEmailVerified', 'setInitials', 'editUser', 'removeUser', 'impersonate', 'adminLogoutUser', 'setEncryptNewAttachments', 'encryptAllAttachments', 'decryptAllAttachments',
|
|
'adminSetAvatarUrl', 'unlockUser', 'unlockAllUsers', 'mergeImportedUser',
|
|
'sendInvitation', 'setUserOrgsTeamsFromLdap', 'ldap_sync_now',
|
|
// Organizations and teams
|
|
'setCreateOrg', 'setOrgAllFields', 'setOrgIsActive', 'setOrgTenantFields',
|
|
'setAutoAddUsersWithDomainName', 'setCreateTeam', 'setTeamAllFields', 'setTeamIsActive',
|
|
// Login and site settings
|
|
'saveAuthConfigSettings', 'saveSamlSettings', 'saveOauthProviderSettings',
|
|
'savePasswordlessSettings', 'saveAdminMailSettings', 'setPermanentDeleteEnabled',
|
|
'saveSqrlEnabled', 'saveInstanceFeatures', 'saveOptionalApis', 'saveRulesReadOnlyForMembers',
|
|
'saveWebhookInternalHosts', 'saveAccountWebhook', 'saveWebhooksDisabled', 'saveActivityPubEnabled',
|
|
'saveEmailBounceSettings', 'saveInboundMailSettings', 'setAdminNotifyDefault', 'uploadSiteLogo',
|
|
'reloadAccountsLockout', 'saveAdminPanelAllowedAddresses',
|
|
// Attachments, backups and data
|
|
'updateAttachmentStorageSettings', 'setDefaultAttachmentStorage', 'startBulkAttachmentMove',
|
|
'compactMongoGridFs', 'saveBackupSchedule', 'restoreBackup', 'runBackup',
|
|
'migrateTextDatabase', 'repairBrokenCards', 'repairDataHealth', 'permanentlyDeleteArchivedBoards',
|
|
'cleanupUnusedTemplateContainers', 'sandstormDeleteRawMongo', 'setRecoveryMaintenance',
|
|
// Personal data (docs/Compliance/README.md WP-1)
|
|
'anonymizeUser',
|
|
// Legal pages and privacy contacts (WP-6)
|
|
'saveLegalPage', 'saveLegalContacts',
|
|
];
|
|
|
|
// The collections the Admin Panel writes straight from the browser - Settings
|
|
// / Appearance and Features, Announcement, Accessibility, Translation, Locked
|
|
// users, the invite roles and the attachment storage settings - through
|
|
// Meteor's own /<collection>/insert, /update and /remove methods, which only a
|
|
// site administrator may call (their allow rules). Without these, most Admin
|
|
// Panel switches (also People / Account settings and the table visibility
|
|
// modes) changed the site with no trace in the audit log
|
|
// (GDPR Art. 5(2), NIS2 Art. 21(2), ISO/IEC 27001 A.8.15).
|
|
const AUDITED_COLLECTIONS = [
|
|
'settings', 'announcements', 'translation', 'accessibilitySettings',
|
|
'lockoutSettings', 'inviteToBoardRolesSettings', 'attachmentStorageSettings',
|
|
'accountSettings', 'tableVisibilityModeSettings',
|
|
];
|
|
const MUTATIONS = ['insert', 'update', 'remove'];
|
|
function auditedMutationMethods() {
|
|
return AUDITED_COLLECTIONS.flatMap(c => MUTATIONS.map(m => `/${c}/${m}`));
|
|
}
|
|
|
|
// Arguments that are a password by position, for methods that take one.
|
|
const SECRET_POSITIONS = {
|
|
setPassword: [0],
|
|
setCreateUser: [3],
|
|
};
|
|
|
|
const SECRET_KEY = /pass(word)?|secret|token|credential|private|api[-_]?key|access[-_]?key|account[-_]?key|connection[-_]?string|^key$/i;
|
|
const MAX_STRING = 200;
|
|
const MAX_SUMMARY = 2000;
|
|
const MAX_DEPTH = 4;
|
|
const MAX_ITEMS = 20;
|
|
|
|
function maskUrlCredentials(text) {
|
|
return text.replace(/([a-z][a-z0-9+.-]*:\/\/)([^/@\s:]+):([^/@\s]+)@/gi, '$1$2:[redacted]@');
|
|
}
|
|
|
|
function clean(value, depth) {
|
|
if (value === null || value === undefined) return value;
|
|
if (typeof value === 'string') {
|
|
const s = maskUrlCredentials(value);
|
|
return s.length > MAX_STRING ? `${s.slice(0, MAX_STRING)}…` : s;
|
|
}
|
|
if (typeof value === 'number' || typeof value === 'boolean') return value;
|
|
if (value instanceof Date) return value.toISOString();
|
|
if (depth >= MAX_DEPTH) return '[…]';
|
|
if (Array.isArray(value)) {
|
|
const items = value.slice(0, MAX_ITEMS).map(v => clean(v, depth + 1));
|
|
if (value.length > MAX_ITEMS) items.push(`[+${value.length - MAX_ITEMS}]`);
|
|
return items;
|
|
}
|
|
if (typeof value === 'object') {
|
|
const out = {};
|
|
for (const key of Object.keys(value).slice(0, MAX_ITEMS)) {
|
|
out[key] = SECRET_KEY.test(key) ? '[redacted]' : clean(value[key], depth + 1);
|
|
}
|
|
return out;
|
|
}
|
|
return `[${typeof value}]`;
|
|
}
|
|
|
|
// The arguments as they are stored: secrets out, short, JSON.
|
|
function auditArgs(method, args) {
|
|
const secret = new Set(SECRET_POSITIONS[method] || []);
|
|
const list = (Array.isArray(args) ? args : []).map((arg, i) => (secret.has(i) ? '[redacted]' : clean(arg, 0)));
|
|
let text = JSON.stringify(list);
|
|
if (text.length > MAX_SUMMARY) text = `${text.slice(0, MAX_SUMMARY)}…`;
|
|
return text;
|
|
}
|
|
|
|
function isAudited(method) {
|
|
return AUDITED_METHODS.includes(method) || auditedMutationMethods().includes(method);
|
|
}
|
|
|
|
module.exports = {
|
|
AUDITED_COLLECTIONS, auditedMutationMethods,
|
|
AUDITED_METHODS, SECRET_POSITIONS, AUDIT_KEEP_DAYS, auditArgs, isAudited, maskUrlCredentials,
|
|
};
|