mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
PASSWORD_MIN_LENGTH (default 8) is now the length below which a sign-in is REPORTED, in the new Admin Panel / Problems / Password length, and PASSWORD_MIN_LENGTH_ENFORCE (off by default) is what makes it a rule: a shorter new password is refused, and an account that signs in with an older shorter one sees only "Change your password" until it has a long enough one. Signing in is never refused, enforced or not, so nobody is locked out by a minimum set after their password. LDAP, OAuth2, OIDC, SAML, CAS and Sandstorm accounts are neither reported nor asked: their password is their provider's. An administrator's Set password no longer applies WeKan's policy to such an account. Meteor sends a password hashed, so only the browser knows its length: it notes it on the sign-in form and, after a sign-in that worked, says "it was short" - never the password or its length. The page has both settings and a table, one row per account: username, first and last short-password login, the latest IPv4 and IPv6 address with the country's flag and city when a CDN says where it is, the count, and when it was fixed, with the Too short (default) / Fixed / All filter. Fixed is a changed password not seen short since; a short one seen again reopens the row. Changing one's own password - Member Settings, the forced change, a reset link - now signs EVERY session of the account out, the one that changed it too, and only the new password signs in again. The browser goes to the sign-in page as soon as it is signed out, since the server closes the connection before the answer can arrive. Documented in docs/Features/Admin-Panel/Problems/Password-length.md, the settings on every platform. The new strings are in every locale in English for now. Tests: passwordPolicy, passwordChangeRequired and shortPasswordLogins (node); password-min-length-signup-login, password-length-report and password-change-other-sessions (Playwright, Chromium and WebKit), which change each setting on the page and check what it does, and that sign-up with no mail server registers and signs the user in. Thanks to xet7 !
71 lines
3.1 KiB
JavaScript
71 lines
3.1 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { check, Match } from 'meteor/check';
|
|
import ShortPasswordLogins from '/models/shortPasswordLogins';
|
|
import { ensureIndex } from '/server/lib/mongoStartup';
|
|
|
|
// Admin Panel / Problems / Password length (models/lib/shortPasswordLogins.js
|
|
// says what a row is and what "fixed" means).
|
|
const { cleanFilter, filterSelector, shortLoginUpdate } = require('/models/lib/shortPasswordLogins');
|
|
const { addressOf } = require('/models/lib/loginTally');
|
|
// The same address resolver and location headers as every other login record
|
|
// (server/lib/loginTally.js): two answers to "where from" would not compare.
|
|
const { resolveClientKey } = require('/server/lib/loginAttemptThrottle');
|
|
const { locationFromHeaders } = require('/models/lib/geoHeaders');
|
|
|
|
const MAX_PAGE = 100;
|
|
|
|
export async function recordShortPasswordLogin(user, connection) {
|
|
if (!user || !user._id) return;
|
|
const raw = resolveClientKey({
|
|
headers: connection && connection.httpHeaders,
|
|
socketAddress: connection && connection.clientAddress,
|
|
forwardedCount: process.env.HTTP_FORWARDED_COUNT,
|
|
});
|
|
const { value, family } = addressOf(raw);
|
|
await ShortPasswordLogins.upsertAsync({ userId: user._id }, shortLoginUpdate({
|
|
username: user.username, now: new Date(), address: value, family,
|
|
location: locationFromHeaders(connection && connection.httpHeaders),
|
|
}));
|
|
}
|
|
|
|
// The account's password changed: an open row is fixed. A row already fixed
|
|
// keeps the date it was first fixed.
|
|
export async function markShortPasswordFixed(userId) {
|
|
if (!userId) return;
|
|
await ShortPasswordLogins.updateAsync({ userId, fixedAt: null }, { $set: { fixedAt: new Date() } });
|
|
}
|
|
|
|
async function requireSiteAdmin(userId) {
|
|
const user = userId && await Meteor.users.findOneAsync(userId, { fields: { isAdmin: 1, loginDisabled: 1 } });
|
|
if (!user || user.isAdmin !== true || user.loginDisabled === true) throw new Meteor.Error('not-authorized');
|
|
}
|
|
|
|
Meteor.methods({
|
|
// One page of the table, newest sign-in first. Site administrators only.
|
|
async shortPasswordLoginsPage(options = {}) {
|
|
check(options, Match.ObjectIncluding({
|
|
filter: Match.Optional(String),
|
|
search: Match.Optional(String),
|
|
limit: Match.Optional(Match.Integer),
|
|
skip: Match.Optional(Match.Integer),
|
|
}));
|
|
await requireSiteAdmin(this.userId);
|
|
const selector = filterSelector(cleanFilter(options.filter));
|
|
const search = String(options.search || '').trim().slice(0, 100);
|
|
if (search) {
|
|
const re = new RegExp(search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
|
|
selector.$or = [{ username: re }, { ipv4: re }, { ipv6: re }];
|
|
}
|
|
const limit = Math.min(Math.max(options.limit || 25, 1), MAX_PAGE);
|
|
const skip = Math.max(options.skip || 0, 0);
|
|
const total = await ShortPasswordLogins.find(selector).countAsync();
|
|
const rows = await ShortPasswordLogins.find(selector, { sort: { at: -1 }, skip, limit }).fetchAsync();
|
|
return { rows, total };
|
|
},
|
|
});
|
|
|
|
Meteor.startup(async () => {
|
|
await ensureIndex(ShortPasswordLogins, { userId: 1 }, { unique: true });
|
|
await ensureIndex(ShortPasswordLogins, { fixedAt: 1, at: -1 });
|
|
});
|