mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Each login method has its own section: LDAP, OAuth2 (OpenID Connect and Oracle OIM), CAS and Header login are new or complete, and the Login pane gets PASSWORD_LOGIN_ENABLED and ACCOUNTS_COMMON_LOGIN_EXPIRATION_IN_DAYS. models/lib/authConfigCatalog.js lists all 103 variables; server/lib/ authConfig.js resolves each one at run time (Admin Panel value first, then the environment variable) for the app and, through globalThis.__wekanAuthEnv, for the wekan-ldap, wekan-oidc and wekan-accounts-cas packages. OAuth2 and CAS service configurations and LDAP background sync are reapplied when their settings are saved. Passwords and client secrets (LDAP_AUTHENTIFICATION_PASSWORD, OAUTH2_SECRET) never reach the browser: the page learns only whether one is set and where it comes from. Other values have credentials written inside a URL masked on the server, and a URL field refuses them. Fixed on the way: - The Admin Panel LDAP overrides never applied. The bridge read Settings with a server-side findOne(), which Meteor 3 refuses; the error was swallowed and the environment used. The settings are now held in an observed cache. - LDAP Test connection never existed on the server (testConnection.js was not imported) and used the synchronous Meteor.user(). - PROPAGATE_OIDC_DATA=false turned the feature on. - CAS read only the misspelled CASE_VALIDATE_URL; CAS_VALIDATE_URL now works and the old name still does. - snap help named three group-filter keys snap set does not know. Every catalog variable is now listed in the Dockerfile, the docker-compose files, snap config and help, and start-wekan.sh/.bat; 14 were missing. tests/authConfigCatalog.test.cjs pins resolution, secrets, input validation, platform coverage, and - across the whole tree - that no code reads a login variable outside the catalog or straight from process.env, and that no server code calls the synchronous Settings.findOne() or Meteor.user(). tests/playwright/specs/admin-login-env-overrides.e2e.js drives the pages. Thanks to xet7 !
114 lines
5.6 KiB
JavaScript
114 lines
5.6 KiB
JavaScript
'use strict';
|
|
|
|
// #5174: an OIDC login against a provider that refused the request died with
|
|
//
|
|
// Error in OAuth Server: Cannot read property 'ocs' of null
|
|
//
|
|
// which tells the admin nothing about the refusal - the reporter's actual
|
|
// problem was a scope the provider did not allow.
|
|
//
|
|
// Where the null came from: getTokenContent() returns NULL for a token it cannot
|
|
// parse (`var content = null; if (token) {...} return content`), and the
|
|
// ADFS/B2C branch assigns its result straight into `userinfo`. The next line was
|
|
// the Nextcloud hack, `if (userinfo.ocs)`, so the first thing to touch the failed
|
|
// response was a property read on null. Every claim read after it had the same
|
|
// problem; that line just happened to be first.
|
|
//
|
|
// The fix is not one null check but the ORDER: the provider's answer is
|
|
// validated once, as a whole, before anything reads a field off it, and each
|
|
// failure says which step failed and what the provider sent. This pins that
|
|
// order, because a later edit that reads a claim earlier would restore the
|
|
// original bug without touching the checks.
|
|
//
|
|
// Run: node tests/oidcNullUserinfo.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const src = fs.readFileSync(path.join(ROOT, 'packages/wekan-oidc/oidc_server.js'), 'utf8');
|
|
|
|
// Comments quote the old broken line on purpose; assertions are about code.
|
|
const code = src.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
console.log('oidcNullUserinfo:');
|
|
|
|
test('getTokenContent can still return null - that is the premise', () => {
|
|
// Not a bug in itself: an unparseable token has no content. The bug was
|
|
// handing that null to code that assumed an object. If this ever stops
|
|
// returning null the guards below are harmless, but the comment above would be
|
|
// describing history.
|
|
const at = code.indexOf('var getTokenContent = function');
|
|
assert.notStrictEqual(at, -1, 'getTokenContent must be there');
|
|
const fn = code.slice(at, code.indexOf('\n}', at));
|
|
assert.ok(/var content = null/.test(fn) && /return content/.test(fn),
|
|
'it returns null when the token cannot be parsed');
|
|
});
|
|
|
|
test('the token response is checked before any field is read off it', () => {
|
|
const tokenCheck = code.indexOf('the token endpoint returned no usable response');
|
|
const firstRead = code.indexOf('token.access_token');
|
|
assert.notStrictEqual(tokenCheck, -1, 'a missing/!object token response must be refused');
|
|
assert.ok(tokenCheck < firstRead,
|
|
'the check has to come BEFORE the first read, or the read throws first');
|
|
});
|
|
|
|
test('a token response with no token in it fails with what the provider sent', () => {
|
|
assert.ok(/neither access_token nor/.test(code),
|
|
'a 200 carrying neither token must be refused explicitly');
|
|
assert.ok(/Object\.keys\(token\)/.test(code),
|
|
'and name the fields that DID come back - keys only, since the values are secrets');
|
|
assert.ok(!/JSON\.stringify\(token\)/.test(code),
|
|
'never dump the whole token response into an error message');
|
|
});
|
|
|
|
test('userinfo is validated before any claim is read', () => {
|
|
const check = code.indexOf('no user information came back from the provider');
|
|
assert.notStrictEqual(check, -1, 'a null/non-object userinfo must be refused');
|
|
// The claim reads: the Nextcloud hack first, then the OAUTH2_*_MAP lookups.
|
|
const ocs = code.indexOf('userinfo.ocs');
|
|
// OAUTH2_ID_MAP is read through authEnv (Admin Panel override, else the env var).
|
|
const firstClaim = code.indexOf("userinfo[authEnv('OAUTH2_ID_MAP')]");
|
|
assert.ok(check < ocs && check < firstClaim,
|
|
'the check must precede BOTH the ocs hack and the claim lookups - the ocs '
|
|
+ 'line was only first by accident of ordering');
|
|
// And it must say which branch produced it: the claims-in-access-token path
|
|
// and the userinfo-endpoint path fail for different reasons.
|
|
assert.ok(/claimsInAccessToken/.test(code.slice(check, check + 600)),
|
|
'the message distinguishes the two paths, or it just moves the mystery');
|
|
assert.ok(/OAUTH2_REQUEST_PERMISSIONS/.test(code.slice(check, check + 700)),
|
|
'and points at the scopes, which is what was actually wrong in #5174');
|
|
});
|
|
|
|
test('the ocs and metadata hacks cannot produce an undefined userinfo', () => {
|
|
// Both re-point userinfo at a nested object. `ocs` present but `ocs.data`
|
|
// missing used to set userinfo to undefined and fail on the NEXT line.
|
|
assert.ok(/if \(userinfo\.ocs && userinfo\.ocs\.data\)/.test(code),
|
|
'the Nextcloud hack must check the nested object it unwraps to');
|
|
const hacks = code.indexOf('userinfo.ocs');
|
|
const after = code.slice(hacks, hacks + 800);
|
|
assert.ok(/unwrapped to nothing usable/.test(after),
|
|
'and an unwrap that lands on nothing must be refused right after');
|
|
});
|
|
|
|
test('the B2C email claim is checked before it is indexed', () => {
|
|
const at = code.indexOf('OAUTH2_B2C_ENABLED');
|
|
const branch = code.slice(code.indexOf('OAUTH2_B2C_ENABLED', at + 10));
|
|
assert.ok(/Array\.isArray\(userinfo\.emails\)/.test(branch),
|
|
'userinfo["emails"][0] on a token without the claim is undefined[0]');
|
|
assert.ok(/no "emails" claim/.test(branch),
|
|
'and the failure must say the tenant is not releasing it');
|
|
});
|
|
|
|
test('a missing expires_in does not become NaN', () => {
|
|
assert.ok(/Number\.isFinite\(expiresIn\)/.test(code),
|
|
'parseInt(undefined) is NaN, and NaN in expiresAt propagates silently');
|
|
assert.ok(/expiresIn = 3600/.test(code), 'with the OAuth2 default hour as the fallback');
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|