mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
WHAT WAS ALREADY THERE, checked first: server/lib/loginAttemptThrottle.js resolves a client address for the REST throttle, the lockout resolves one for DDP, models/users.js has getInitials() and profile.avatarUrl, the board sidebar and cards show members through +userAvatar / +userAvatarInitials, cardDetails.js builds "open in map" links for a dozen providers, and Admin Panel tables already had a js-table-page-edit-user handler and a `userId` column option. All of it is reused rather than rewritten; only geolocation from CDN headers is new. THE TALLY, both directions from one successful login. On the user: which addresses this account uses - `100.100.100.100 25, 122.122.122.122 50`. On a new loginAddresses collection: which accounts use each address. Capped both ways with an overflow count, as the Problems summaries are. WHY THE SECOND DIRECTION EXISTS: an address several accounts log in from is an office, a VPN, a university, a carrier's NAT. Blocking it takes everyone behind it off WeKan at once - including the reverse proxy itself if HTTP_FORWARDED_COUNT is wrong, which is every user there is. So WeKan blocks the ACCOUNT that attempted the vulnerability and never the address, and this record is what lets an admin see that shape before drawing any conclusion from an address. Blocking uses loginDisabled, the field Admin Panel / People already toggles, so an admin unblocks from the table they know and no second notion of "blocked" appears beside the one that exists. `services.securityBlock` records why, from what and when. Only a 'blocked' action at high or critical severity, and only with a userId: an unauthenticated attempt has nobody to block, and guessing from the address is the mistake above. LOCATION, when something in front of WeKan already knows it: Cloudflare, Fastly, CloudFront, Vercel, Google Cloud or a hand-configured proxy. WeKan does no geolocation of its own - no database to ship, no third-party lookup of a user's address. An office in London is labelled London. DISPLAY ONLY, and the file says so twice: anything a client can send it can forge, and X-Forwarded-For at least has HTTP_FORWARDED_COUNT to say how much to believe, where a city name has nothing. USERS AS INITIALS OR AVATAR, in every Admin Panel / Problems table at once - it is one line of the shared table page, so Security, Speed, Tests, CPU, Database, Integrity and Impersonation all change together. The name is the title, so hovering still says who it is, and clicking opens the existing "Edit user" popup. Not +userAvatar: it renders its own anchor for the board's member popup, and an anchor inside the cell's anchor is invalid and would swallow the click. mapLinkFor and its Chinese datum conversions move to models/lib/mapLink.js so the card and the Admin Panel build map links the same way, with the user's own profile.mapProvider choice applying in both. Thanks to xet7 !
86 lines
4.3 KiB
JavaScript
86 lines
4.3 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';
|
|
import { blockAccountForSecurityEvent } from '/server/lib/blockOnSecurityEvent';
|
|
|
|
// 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');
|
|
// A logged-in account that attempted a vulnerability loses that account - see
|
|
// server/lib/blockOnSecurityEvent.js for why the ACCOUNT and never the
|
|
// address. Fire-and-forget like the fold: the guard already refused the
|
|
// operation, and the consequence must not be able to break the refusal.
|
|
try {
|
|
const p = blockAccountForSecurityEvent(doc);
|
|
if (p && typeof p.catch === 'function') p.catch(() => {});
|
|
} catch (e) { /* blocking must never break the guard */ }
|
|
}
|
|
|
|
// 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 };
|