mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
Two rules in CLAUDE.md, both learned from fixes in this repository rather than
proposed in the abstract.
A TEST AND A NEGATIVE TEST, written so the fault cannot exist ANYWHERE in the
codebase rather than only where it was reported. A test that pins one call site
leaves the same mistake free to live in the other five, and that is how most of
these arrive: SignupBleed's guard read an option nothing sets and the same shape
sat in a second endpoint; the source-map trim was safe on the client and fatal
on the server. So the test proves the fix does what it claims - driving the
decision itself where it can, as arithmetic, reproducing the reporter's attack
exactly - and the negative test proves the fault is GONE rather than moved, by
searching the tree for the shape of it and asserting nothing matches. A test
that parses a source file is a real test here: it is what makes "and nowhere
else" checkable at all.
AND AN ATTEMPT HAS TO BE VISIBLE in Admin Panel -> Problems, wherever the fix
denies an operation and the denial can be attributed. That is the difference
between a hole that is closed and one that is closed and watched. The catalog
key, the wrapped record() call on the refusal path, and the rule that only an
ATTEMPT is logged and never ordinary use - a log that fills with normal traffic
hides the one line that mattered, which is why HashBleed deliberately has no
key.
JamBleed did not meet the second rule when it was committed: the catalog entry
was there and nothing ever wrote to it. It does now. A Meteor package cannot
import app code, so the reporter is injected - AccountsLockout takes an
onLockout callback, KnownUser calls it when a lock FIRES, and the app passes one
that writes a security-log event. On the lock only, not on every refused attempt
during it, or an attacker could fill Problems by holding down a key.
There are TWO construction sites - startup and the Admin Panel settings reload -
and a reload that dropped the reporter would stop recording attempts on a
running server while the guard kept working, which is the worst version of this:
nobody can see it working. So the negative test walks server/ and fails on any
`new AccountsLockout({...})` without onLockout, present or future.
Thanks to daniais and xet7 !
66 lines
2.5 KiB
JavaScript
66 lines
2.5 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { AccountsLockout } from 'meteor/wekan-accounts-lockout';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import LockoutSettings from '/models/lockoutSettings';
|
|
|
|
// GHSA-rf3w-rj48-jxcc: a lockout firing is an ATTEMPT that the fix refused, so
|
|
// it belongs in Admin Panel -> Problems. A Meteor package cannot import app
|
|
// code, so the reporter is injected here. Wrapped, because the record of the
|
|
// defence must never be able to break the defence.
|
|
function reportLockout({ userId, failedAttempts, lockoutSeconds }) {
|
|
try {
|
|
require('/server/lib/securityLog').record({
|
|
key: 'brute.lockout',
|
|
action: 'blocked',
|
|
source: 'DDP login',
|
|
detail: `locked one address out of account ${userId} after ${failedAttempts} `
|
|
+ `wrong passwords, for ${lockoutSeconds}s`,
|
|
});
|
|
} catch (e) { /* logging must never break the guard */ }
|
|
}
|
|
|
|
|
|
Meteor.methods({
|
|
async reloadAccountsLockout() {
|
|
// Check if user has admin rights
|
|
const userId = this.userId;
|
|
if (!userId) {
|
|
throw new Meteor.Error('error-invalid-user', 'Invalid user');
|
|
}
|
|
const user = await ReactiveCache.getUser(userId);
|
|
if (!user || !user.isAdmin) {
|
|
throw new Meteor.Error('error-not-allowed', 'Not allowed');
|
|
}
|
|
|
|
try {
|
|
// Get configurations from database
|
|
const knownUsersConfig = {
|
|
failuresBeforeLockout: (await LockoutSettings.findOneAsync('known-failuresBeforeLockout'))?.value || 3,
|
|
lockoutPeriod: (await LockoutSettings.findOneAsync('known-lockoutPeriod'))?.value || 60,
|
|
failureWindow: (await LockoutSettings.findOneAsync('known-failureWindow'))?.value || 15
|
|
};
|
|
|
|
const unknownUsersConfig = {
|
|
failuresBeforeLockout: (await LockoutSettings.findOneAsync('unknown-failuresBeforeLockout'))?.value || 3,
|
|
lockoutPeriod: (await LockoutSettings.findOneAsync('unknown-lockoutPeriod'))?.value || 60,
|
|
failureWindow: (await LockoutSettings.findOneAsync('unknown-failureWindow'))?.value || 15
|
|
};
|
|
|
|
// Initialize the AccountsLockout with configuration
|
|
const accountsLockout = new AccountsLockout({
|
|
knownUsers: knownUsersConfig,
|
|
unknownUsers: unknownUsersConfig,
|
|
onLockout: reportLockout,
|
|
});
|
|
|
|
// Start the accounts lockout mechanism
|
|
accountsLockout.startup();
|
|
|
|
return true;
|
|
} catch (error) {
|
|
console.error('Failed to reload accounts lockout:', error);
|
|
throw new Meteor.Error('error-reloading-settings', 'Error reloading settings');
|
|
}
|
|
}
|
|
});
|