mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
A guard on a path an attacker controls fires as fast as they can send. One
document per event meant the database grew with the attack, the Problems page
became a scroll of near-identical lines, and the one event that mattered was
buried under ten thousand that did not. The admin's question is never "list
every attempt" - it is what is happening, how much, since when, and who.
So each problem is ONE row that accumulates:
count how many times this problem has happened
firstAt … at the window it happened in
actors who, each with their own count:
username1 25, 100.100.100.100 30
username/ip the most recent occurrence
WHAT MAKES TWO EVENTS THE SAME PROBLEM is the whole design. Identity is the KIND
of thing that happened - stream, bleed, category, action, source, severity, CWE,
and the database stream's own type/db/kind. The actor is NOT part of it: a
username or an address in the key gives a row per attacker per attempt, which is
the cost being removed.
A USERNAME AND AN ADDRESS ARE TALLIED SEPARATELY, not as a pair. They answer
different questions - which account, and where from - and an unauthenticated
attempt has an address and no name. Pairing them would split one attacker across
a line per address and answer neither.
THE TALLY IS CAPPED at 50 actors, with the rest counted in actorsOverflow.
Otherwise an attacker rotating addresses grows the row with the attack and
reintroduces the same bug one level down - and "and 9,412 others" is itself the
signal that the source is spread rather than single. The cap needs to know
whether an actor is new to the row, so the row's actor keys are cached per
process: reading it on every attempt would double the database work of the thing
being made cheap, and under attack the same few actors repeat.
All three loggers share the fold (server/lib/eventLogFold.js) - a slow query in
a loop and a test failing on every run repeat just as a guard under attack does.
Still fire-and-forget and still unable to throw into the caller.
EXISTING PER-EVENT ROWS ARE FOLDED IN PLACE at startup, in batches, in JS so it
behaves the same on FerretDB as on MongoDB, and idempotently - a row with firstAt
is already a summary. Nothing is lost that the summary does not carry: counts are
summed, the earliest becomes firstAt, the latest becomes at, and the latest
occurrence's actor and detail are what the row keeps.
AND A COVERAGE CHECK, as asked: tests/hallOfFameProblemsCoverage.test.cjs
requires every hall-of-fame vulnerability to be keyed, deliberate (with the
reason, as HashBleed is), or pending. 30 of 66 are keyed; the other 35 predate
the rule and are listed as pending rather than judged here, because deciding
whether a given fix has anything to detect means reading that fix and claiming
otherwise would be worse than the gap. The pending list may shrink and may never
grow, so a NEW vulnerability without a key fails.
It found one real fault immediately: the catalog said OidcBleed and the site says
OIDCBleed, so attempts were grouping under a name nobody could look up.
Thanks to xet7 !
77 lines
3.7 KiB
JavaScript
77 lines
3.7 KiB
JavaScript
// ============================================================================
|
|
// WeKan security event logger (design: docs/Security/Remediation/WeKan.md)
|
|
// ----------------------------------------------------------------------------
|
|
// Single choke point every runtime security guard funnels through when it
|
|
// BLOCKS, SANITIZES or REMEDIATES a request (SSRF rejection, XSS scheme drop,
|
|
// forged-XFF ignore, export-authz denial, invite rate-limit, attachment/avatar
|
|
// upload rejection or sanitization, …).
|
|
//
|
|
// Records one document into the EXISTING WeKan database via a normal Meteor
|
|
// JavaScript query (models/eventLog.js, stream:'security'). No new files/DBs, so
|
|
// it works the same on FerretDB and MongoDB. BEST-EFFORT and NEVER throws into the
|
|
// caller: the insert is fire-and-forget and any error is swallowed. Server-only.
|
|
// ============================================================================
|
|
|
|
import EventLog from '/models/eventLog';
|
|
const { categoryFor } = require('/models/lib/securityCategories');
|
|
const { sanitizeDetail } = require('/models/lib/securityLogFormat');
|
|
import { foldEventFireAndForget } from '/server/lib/eventLogFold';
|
|
|
|
// ONE ROW PER PROBLEM, not per event (models/lib/eventLogSummary.js).
|
|
//
|
|
// A guard on a path an attacker controls fires as fast as they can send, so a
|
|
// row per event grows the database with the attack and buries the one line that
|
|
// mattered under ten thousand identical ones. The row carries `count` and the
|
|
// window `firstAt` … `at` instead, and the actor fields describe the most recent
|
|
// occurrence.
|
|
//
|
|
// Still fire-and-forget and still never throws into the caller: recording that a
|
|
// guard fired must never be able to stop it firing.
|
|
// ONE ROW PER PROBLEM, not per event: server/lib/eventLogFold.js does the
|
|
// folding, shared with the speed and test loggers. A guard on a path an attacker
|
|
// controls fires as fast as they can send, so a row per event grows the database
|
|
// with the attack and buries the one line that mattered under ten thousand
|
|
// identical ones. The row carries `count`, the window `firstAt` … `at`, and a
|
|
// per-actor tally read out as `username1 25, 100.100.100.100 30`.
|
|
function insert(doc) {
|
|
foldEventFireAndForget(doc, 'securityLog');
|
|
}
|
|
|
|
// Record one security event. Never throws. Pass a catalog `key` (see
|
|
// models/lib/securityCategories) and/or explicit fields; explicit wins.
|
|
export function record(evt = {}) {
|
|
try {
|
|
const base = evt.key ? categoryFor(evt.key) : {};
|
|
const m = { ...base, ...evt };
|
|
const doc = {
|
|
stream: 'security',
|
|
at: new Date(),
|
|
severity: m.severity || 'info',
|
|
category: m.category || 'unknown',
|
|
bleed: m.bleed || 'Generic',
|
|
action: m.action || 'detected',
|
|
source: m.source || '',
|
|
cwe: m.cwe || '',
|
|
detail: sanitizeDetail(m.detail),
|
|
};
|
|
if (m.userId || m.userid) doc.userId = String(m.userId || m.userid);
|
|
// WHO and FROM WHERE (docs/Security/Remediation/WeKan.md §12). Both are
|
|
// optional: a guard that fires on an unauthenticated request has no
|
|
// username, and one that fires outside a request context has no address.
|
|
// Truncated here as well as sanitized, because both are attacker-influenced
|
|
// strings - a username can be chosen at registration and an XFF header is
|
|
// whatever was sent.
|
|
if (m.username) doc.username = String(m.username).slice(0, 100);
|
|
if (m.ip) doc.ip = String(m.ip).slice(0, 64);
|
|
// How many attempts this row stands for; 1 unless a canary is flushing a
|
|
// window's summary.
|
|
const count = Number(m.count);
|
|
doc.count = Number.isFinite(count) && count > 0 ? Math.floor(count) : 1;
|
|
insert(doc);
|
|
} catch (e) {
|
|
if (process.env.DEBUG === 'true') console.warn('securityLog.record failed:', e && e.message);
|
|
}
|
|
}
|
|
|
|
export default { record };
|