mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -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 !
63 lines
3.5 KiB
JavaScript
63 lines
3.5 KiB
JavaScript
'use strict';
|
|
// Meteor's HttpOnly login cookie refresh is limited to 30 per 10 seconds per
|
|
// client address. ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT raises it; the browser
|
|
// test server sets it, because every spec comes from localhost and a quick run
|
|
// signed its own users out (the 18-rtl-layout "list pages" flake).
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const vm = require('node:vm');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const source = fs.readFileSync(path.join(root, 'server/accounts-common.js'), 'utf8');
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
const fnSource = source.match(/export function cookieRefreshRateLimit\(value\) \{[\s\S]*?\n\}/)[0]
|
|
.replace('export function', 'function');
|
|
const cookieRefreshRateLimit = vm.runInNewContext(`${fnSource}; cookieRefreshRateLimit`);
|
|
|
|
test('a positive whole number raises the per-10-seconds allowance', () => {
|
|
assert.deepEqual(JSON.parse(JSON.stringify(cookieRefreshRateLimit('100000'))),
|
|
{ httpOnlyCookieRateLimit: { max: 100000, windowMs: 10000 } });
|
|
assert.deepEqual(JSON.parse(JSON.stringify(cookieRefreshRateLimit('31'))).httpOnlyCookieRateLimit.max, 31);
|
|
});
|
|
|
|
test('negative: anything else leaves Meteor\'s default rather than disabling the limit', () => {
|
|
for (const value of [undefined, '', '0', '-5', '1.5', 'abc', 'false', 'Infinity']) {
|
|
assert.deepEqual(JSON.parse(JSON.stringify(cookieRefreshRateLimit(value))), {}, String(value));
|
|
}
|
|
});
|
|
|
|
// Admin Panel / People / Login overrides it now, like
|
|
// ACCOUNTS_COMMON_LOGIN_EXPIRATION_IN_DAYS beside it: a site administrator
|
|
// already sets the login settings, and a reverse proxy that shares one address
|
|
// for every user is exactly what an administrator, not only the host, fixes.
|
|
// Still read once, after the Admin Panel values have loaded, as Accounts.config
|
|
// accepts it once.
|
|
test('Accounts.config receives it, Admin Panel first, then the environment', () => {
|
|
assert.match(source, /\.\.\.cookieRefreshRateLimit\(authEnv\('ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT'\)\),/);
|
|
assert.ok(source.indexOf('await authConfigReady;') < source.indexOf("cookieRefreshRateLimit(authEnv("), 'after the Admin Panel values load');
|
|
const { authConfigField } = require(path.join(root, 'models/lib/authConfigCatalog.js'));
|
|
const field = authConfigField('ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT');
|
|
assert.equal(field && field.section, 'login');
|
|
assert.equal(field.restart, true, 'the form says a restart applies it');
|
|
// false would switch Meteor's limiter off entirely; never pass it.
|
|
assert.doesNotMatch(source, /httpOnlyCookieRateLimit:\s*false/);
|
|
});
|
|
|
|
test('the browser test server raises it, and documentation names it', () => {
|
|
const build = fs.readFileSync(path.join(root, 'build.sh'), 'utf8');
|
|
assert.match(build, /export ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT="\$\{ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT:-100000\}"/);
|
|
const docs = fs.readFileSync(path.join(root, 'docs/Features/Admin-Panel/People/Login.md'), 'utf8');
|
|
assert.match(docs, /ACCOUNTS_COOKIE_REFRESH_RATE_LIMIT/);
|
|
});
|
|
|
|
test('loginWithToken waits out a 429 on the cookie refresh, and only that', () => {
|
|
const auth = fs.readFileSync(path.join(root, 'tests/playwright/helpers/auth.js'), 'utf8');
|
|
assert.match(auth, /response\.status\(\) === 429 && response\.url\(\)\.includes\('\/_accounts\/cookie\/refresh'\)/);
|
|
assert.match(auth, /if \(!throttled\) throw error;/);
|
|
});
|
|
|
|
console.log(`\ncookieRefreshRateLimit: all ${passed} tests passed`);
|