mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
An audit of every environment variable the code reads found 30 that are new since v12.00. Eleven were already Admin Panel settings and on every platform the release workflows build. Of the rest: Now Admin Panel settings, through models/lib/authConfigCatalog.js (a value there wins, an empty field falls back to the variable): - Email to card limits, beside its own Admin Panel settings: INBOUND_IMAP_POLL_SECONDS, INBOUND_EMAIL_PER_ADDRESS_PER_HOUR, INBOUND_EMAIL_MAX_BYTES, INBOUND_EMAIL_MAX_ATTACHMENT_BYTES and EMAIL_VIEW_SENDS_PER_HOUR. They were module-level constants, read before the Admin Panel values loaded; they are read when used now. createRateLimiter takes a limit function, and a changed poll interval restarts the IMAP poller. - ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT in People / Login, like the login expiry beside it, applied from the next start. - Windows SSO (WINDOWS_SSO_ENABLED, _DOMAINS, _ACTIVE_DIRECTORY, _MERGE_EXISTING_USERS) in People / Login. It was already read through authEnv but had no form. Being Windows-only, its catalog section names start-wekan.bat as its one platform. Listed on every platform (Dockerfile, the docker-compose files, start-wekan.sh and .bat, the snap config and help), where none of these had been: the variables above, INBOUND_EMAIL_WEBHOOK_SECRET (its own Admin Panel page already has it), and the per-process switches that stay environment only - INBOUND_IMAP_DISABLED (one pod of a multi-pod deployment), WEKAN_DISK_MONITOR, WEKAN_DISK_WATCH_PATHS, WEKAN_RAM_MONITOR and WEKAN_IMPORT_RUN_STALE_MS. Left unlisted on purpose: NEXTCLOUD_EXAPP, NEXTCLOUD_URL and WEKAN_NEXTCLOUD_PROXY_KEY (set by Nextcloud's AppAPI), SANDSTORM_MAILDIR (set by Sandstorm). DEFAULT_AVATAR_URL keeps no Admin Panel UI, as decided in #824. tests/envVarCoverage.test.cjs keeps it so. It fails for a variable that is in no Admin Panel catalog, OWN_PANE or ENV_ONLY with its reason; the variables read before v12.00 are a frozen LEGACY list that can only shrink. An environment-only or own-page setting a user sets must be on every platform, and stale entries fail. tests/authConfigCatalog.test.cjs honours a section's platform list. tests/adminPanelNewSettings.test.cjs pins the reads and the forms. tests/cookieRefreshRateLimit.test.cjs's guard now expects the Admin Panel value, and says why. tests/playwright/specs/admin-new-env-settings.e2e.js opens the forms. Thanks to xet7 !
68 lines
3.0 KiB
JavaScript
68 lines
3.0 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Accounts } from 'meteor/accounts-base';
|
|
import http from 'http';
|
|
import { ensureLoginCookieExpiry } from '/server/lib/loginCookieExpiry';
|
|
|
|
import { authEnv, authConfigReady } from '/server/lib/authConfig';
|
|
|
|
// ACCOUNTS_COMMON_LOGIN_EXPIRATION_IN_DAYS, or its Admin Panel / People / Login
|
|
// override. Accounts.config() accepts it once, so it is read at startup and a
|
|
// change applies from the next start; the cookie below uses the same value.
|
|
let loginExpirationDays = 90;
|
|
|
|
// Meteor answers more than 30 refreshes of the HttpOnly login cookie per 10
|
|
// seconds from one client address with 429, and every page load is one. That
|
|
// is per ADDRESS: behind a reverse proxy that is not trusted for the client
|
|
// address (HTTP_FORWARDED_COUNT), every user shares one, and the browser tests
|
|
// all come from localhost, where a quick run signs itself out mid-test.
|
|
// ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT raises the per-10-seconds allowance; a
|
|
// value that is not a positive whole number leaves Meteor's default.
|
|
export function cookieRefreshRateLimit(value) {
|
|
const max = Number(value);
|
|
return Number.isSafeInteger(max) && max > 0
|
|
? { httpOnlyCookieRateLimit: { max, windowMs: 10000 } }
|
|
: {};
|
|
}
|
|
|
|
Meteor.startup(async () => {
|
|
await authConfigReady;
|
|
loginExpirationDays = Number(authEnv('ACCOUNTS_COMMON_LOGIN_EXPIRATION_IN_DAYS')) || 90;
|
|
Accounts.config({
|
|
loginExpirationInDays: loginExpirationDays,
|
|
clientStorage: 'none',
|
|
useHttpOnlyCookies: true,
|
|
// CodeBleed (2026-10-02): a passwordless sign-in code was 6 hex
|
|
// characters (16.7 million values) valid for an hour, and failed codes are
|
|
// not counted by the lockout - only Meteor's per-connection rate limit
|
|
// stood in the way, which many connections walk around. 10 characters is
|
|
// over a trillion values, and a code now lives 15 minutes.
|
|
tokenSequenceLength: 10,
|
|
loginTokenExpirationHours: 0.25,
|
|
// Admin Panel / People / Login first, like the expiry above; a restart applies it.
|
|
...cookieRefreshRateLimit(authEnv('ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT')),
|
|
});
|
|
});
|
|
|
|
// #6684: guarantee the HttpOnly login cookie always carries an expiry that
|
|
// matches loginExpirationDays, even on the rare request where accounts-base's
|
|
// own lookup fails to find one (see server/lib/loginCookieExpiry.js). Patched
|
|
// at the http.ServerResponse level, not as Connect middleware, because
|
|
// accounts-base's cookie handler (server_http_cookies.js) writes the header
|
|
// directly and returns without calling next().
|
|
const originalSetHeader = http.ServerResponse.prototype.setHeader;
|
|
http.ServerResponse.prototype.setHeader = function setHeaderWithLoginCookieExpiry(
|
|
name,
|
|
value,
|
|
) {
|
|
if (typeof name === 'string' && name.toLowerCase() === 'set-cookie') {
|
|
if (Array.isArray(value)) {
|
|
value = value.map(v =>
|
|
ensureLoginCookieExpiry(v, loginExpirationDays * 86400),
|
|
);
|
|
} else {
|
|
value = ensureLoginCookieExpiry(value, loginExpirationDays * 86400);
|
|
}
|
|
}
|
|
return originalSetHeader.call(this, name, value);
|
|
};
|