Files
wekan/models/loginAddresses.js
T
Lauri Ojansivu d8d1863dba Login offices: who logs in from where, and users shown as initials or avatar.
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 !
2026-08-16 16:17:13 +03:00

54 lines
2.7 KiB
JavaScript

import { Mongo } from 'meteor/mongo';
const { SimpleSchema } = require('/imports/simpleSchema');
// ============================================================================
// LoginAddresses — one document per address people log in FROM.
//
// The other direction of the per-account tally on the user document: this says
// who uses an address, that says which addresses an account uses. Both are
// written from the same successful login (server/lib/loginTally.js).
//
// WHAT IT IS FOR. An address several accounts log in from is an office, a VPN,
// a university or a carrier's NAT - one address in front of a lot of people.
// Admin Panel groups them so an admin can see the shape of their own users:
// which offices exist, who is at each, and how often each of them logs in.
//
// It is also why WeKan does not block addresses. A security event blocks the
// ACCOUNT that caused it; blocking the address would take everyone behind it
// off WeKan at once, and this collection is what makes that visible rather than
// theoretical - "one address blocked" reads very differently next to "and
// eighty people use it".
// ============================================================================
const LoginAddresses = new Mongo.Collection('loginAddresses');
LoginAddresses.attachSchema(
new SimpleSchema({
// The address as recorded: an IPv4-mapped IPv6 is stored as the IPv4 it is,
// so one client is one row however it reached the server.
address: { type: String },
// Split into families so a report can put each in its own column. One row
// has one or the other, never both.
ipv4: { type: String, optional: true },
ipv6: { type: String, optional: true },
// Total successful logins from here, and the window they fall in.
count: { type: Number, optional: true },
firstAt: { type: Date, optional: true },
at: { type: Date, optional: true },
// Who logs in from here: { entries: { <key>: { value, count, firstAt, at } },
// overflow: n }. Capped (models/lib/loginTally.js MAX_USERS_PER_ADDRESS) so
// a large office cannot grow one document without bound; `overflow` counts
// the logins that were not attributed to a listed account.
users: { type: Object, optional: true, blackbox: true },
// Where a CDN in front of WeKan says this address is, when one does
// (models/lib/geoHeaders.js): { city, region, country, latitude, longitude,
// via }. DISPLAY ONLY - it is a label for an office, and anything a client
// can send it can forge, so nothing decides anything on the strength of it.
location: { type: Object, optional: true, blackbox: true },
// The one line a table cell shows: "London, GB".
locationLabel: { type: String, optional: true },
}),
);
export default LoginAddresses;