Audit log: the Admin Panel's own collection writes and user anonymisation are recorded.

Settings / Appearance, Features and the other switches the Admin Panel saves
straight from the browser go through Meteor's /<collection>/insert, /update
and /remove methods, which the audit log did not wrap, so most site changes
left no trace; anonymizeUser was not audited either. The admin-only
collections - settings, announcements, translation, accessibilitySettings,
lockoutSettings, inviteToBoardRolesSettings and attachmentStorageSettings -
and anonymizeUser are now in the trail, with the arguments redacted as every
other entry's. Work package 1 of docs/Compliance/README.md (GDPR Art. 5(2),
NIS2 Art. 21(2), ISO/IEC 27001 A.8.15). tests/adminAudit.test.cjs pins it.

Thanks to xet7 !
This commit is contained in:
Lauri Ojansivu committed 2026-11-22 19:14:20 +02:00
1 parent 0e8d3e5683
commit 377a7b3abc
3 files changed
+38 -3

No files matched your search

+20 -1
View File
@@ -46,8 +46,26 @@ const AUDITED_METHODS = [
'compactMongoGridFs', 'saveBackupSchedule', 'restoreBackup', 'runBackup',
'migrateTextDatabase', 'repairBrokenCards', 'repairDataHealth', 'permanentlyDeleteArchivedBoards',
'cleanupUnusedTemplateContainers', 'sandstormDeleteRawMongo', 'setRecoveryMaintenance',
// Personal data (docs/Compliance/README.md WP-1)
'anonymizeUser',
];
// 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 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',
];
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],
@@ -98,9 +116,10 @@ function auditArgs(method, args) {
}
function isAudited(method) {
return AUDITED_METHODS.includes(method);
return AUDITED_METHODS.includes(method) || auditedMutationMethods().includes(method);
}
module.exports = {
AUDITED_COLLECTIONS, auditedMutationMethods,
AUDITED_METHODS, SECRET_POSITIONS, AUDIT_KEEP_DAYS, auditArgs, isAudited, maskUrlCredentials,
};
+3 -2
View File
@@ -8,7 +8,7 @@ import { deferArgumentAudit, applyAudited } from '/server/lib/argumentChecks';
// a site administrator, one document each. Which methods, and what of their
// arguments is kept (never a password or a secret), is in
// models/lib/adminAudit.js.
const { AUDITED_METHODS, AUDIT_KEEP_DAYS, auditArgs } = require('/models/lib/adminAudit');
const { AUDITED_METHODS, auditedMutationMethods, AUDIT_KEEP_DAYS, auditArgs } = require('/models/lib/adminAudit');
const { resolveClientKey } = require('/server/lib/loginAttemptThrottle');
export const AdminAuditLog = new Mongo.Collection('adminAuditLog');
@@ -52,7 +52,8 @@ async function record(invocation, actor, method, args, error) {
// after every startup hook, for methods a later file defines in one.
export function wrapAuditedMethods() {
const methods = Meteor.server.method_handlers;
for (const name of AUDITED_METHODS) {
// The named methods, and the Admin Panel's own collection writes.
for (const name of [...AUDITED_METHODS, ...auditedMutationMethods()]) {
const original = methods[name];
if (!original || original[WRAPPED]) continue;
methods[name] = function auditedMethod(...args) {
+15
View File
@@ -148,6 +148,21 @@ test('every audited name is a Meteor method that exists', () => {
}
});
test('the Admin Panel\'s own collection writes are audited: every one is a site-admin-only collection', () => {
// WP-1 of docs/Compliance/README.md: Settings / Appearance, Features and the
// rest are saved from the browser through /<collection>/update, and were not
// in the trail.
assert.ok(audit.isAudited('/settings/update') && audit.isAudited('/announcements/insert') && audit.isAudited('anonymizeUser'));
assert.ok(!audit.isAudited('/cards/update'), 'negative: a member editing a card is not an admin action');
const files = execFileSync('git', ['ls-files', 'server', 'models'], { cwd: repoRoot, encoding: 'utf8' })
.split('\n').filter(f => f.endsWith('.js') && !/test/i.test(f));
const source = files.map(f => read(f)).join('\n');
for (const collection of audit.AUDITED_COLLECTIONS) {
assert.match(source, new RegExp(`new Mongo\\.Collection\\('${collection}'`), `${collection} is a collection`);
}
assert.match(read('server/adminAudit.js'), /\[\.\.\.AUDITED_METHODS, \.\.\.auditedMutationMethods\(\)\]/, 'and they are wrapped');
});
test('the trail is for site administrators, and the Admin Panel shows it', () => {
const server = read('server/adminAudit.js');
assert.match(server, /user\.isAdmin !== true \|\| user\.loginDisabled === true\) throw new Meteor\.Error\('error-notAuthorized'\)/);