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 !
71 lines
3.1 KiB
JavaScript
71 lines
3.1 KiB
JavaScript
// A logged-in account that attempts a vulnerability is blocked from logging in.
|
|
//
|
|
// THE ACCOUNT, NEVER THE ADDRESS. Blocking the address is the obvious reflex and
|
|
// it is wrong: an address that several accounts use is an office, a VPN, a
|
|
// university or a carrier's NAT, and blocking it takes everyone behind it off
|
|
// WeKan at once - including, if HTTP_FORWARDED_COUNT is misconfigured, the
|
|
// reverse proxy, which is every user there is. models/loginAddresses.js exists
|
|
// so an admin can see that shape; this module is why it matters.
|
|
//
|
|
// An account is the right unit anyway. A security event that names a userId is
|
|
// somebody ALREADY AUTHENTICATED reaching for something the guards refuse -
|
|
// a far stronger signal than a failed password, and one that belongs to a person
|
|
// rather than to a place. Whoever it is keeps their address; what they lose is
|
|
// that account.
|
|
//
|
|
// WHAT IS NOT BLOCKED: an event with no userId. An unauthenticated attempt has
|
|
// nobody to block, and guessing from the address is exactly the mistake above.
|
|
// Those are counted in Admin Panel -> Problems and left to the lockout.
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
const { categoryFor } = require('/models/lib/securityCategories');
|
|
|
|
// Only a refusal that names a person. `action` tells a block from a mere
|
|
// detection: a sanitised input is not an attempt to be punished for.
|
|
const BLOCKING_ACTIONS = ['blocked'];
|
|
|
|
// A block is a serious step, so only a serious finding causes one. `info` and
|
|
// `low` are noise by definition, and `medium` covers guards that fire on
|
|
// borderline-but-legitimate use.
|
|
const BLOCKING_SEVERITIES = ['high', 'critical'];
|
|
|
|
export function shouldBlockAccount(evt = {}) {
|
|
if (!evt.userId) return false;
|
|
if (!BLOCKING_ACTIONS.includes(evt.action)) return false;
|
|
const severity = evt.severity || (evt.key ? categoryFor(evt.key).severity : '');
|
|
return BLOCKING_SEVERITIES.includes(severity);
|
|
}
|
|
|
|
// Why it was blocked, in one line an admin reads in Admin Panel / People.
|
|
export function blockReason(evt = {}) {
|
|
const cat = evt.key ? categoryFor(evt.key) : {};
|
|
const name = evt.bleed || cat.bleed || evt.category || cat.category || 'a security guard';
|
|
const where = evt.source ? ` at ${evt.source}` : '';
|
|
return `Attempted ${name}${where} while logged in`;
|
|
}
|
|
|
|
// Block the account. Uses the SAME field the Admin Panel already toggles -
|
|
// loginDisabled - so an admin unblocks from the People table they already know,
|
|
// and no second notion of "blocked" appears beside the one that exists.
|
|
export async function blockAccountForSecurityEvent(evt = {}) {
|
|
if (!shouldBlockAccount(evt)) return false;
|
|
const reason = blockReason(evt);
|
|
await Meteor.users.updateAsync({ _id: evt.userId }, {
|
|
$set: {
|
|
loginDisabled: true,
|
|
// WHY, and when. Admin Panel / People shows this beside the account, so
|
|
// "why was this blocked" is answerable without reading a log.
|
|
'services.securityBlock': {
|
|
at: new Date(),
|
|
reason,
|
|
bleed: evt.bleed || '',
|
|
source: evt.source || '',
|
|
// The address it came from is RECORDED, not acted on.
|
|
ip: evt.ip || '',
|
|
},
|
|
},
|
|
});
|
|
return true;
|
|
}
|