mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
OAuth2/OIDC logins could be limited to email domains with OAUTH2_ALLOWED_EMAIL_DOMAINS, but the Meteor login providers (Google, GitHub, Facebook, X, Meteor Developer, Weibo, Meetup) let anyone with an account there sign in. OAUTH_PROVIDERS_ALLOWED_EMAIL_DOMAINS, or the new field under Admin Panel / People / OAuth login providers, restricts them with the same rule and the same policy code. It is checked before an account is created or merged, and on every later login, so narrowing the list also applies to existing accounts. A provider that sends no email is refused while a restriction is set, and a list that is not domain names is refused when saved instead of locking everyone out. Listed on every platform. New text is in English, pending Transifex. Thanks to jakubgs and xet7 ! Fixes #1904.
24 lines
1.3 KiB
JavaScript
24 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
// The app's copy of packages/wekan-oidc/emailDomainPolicy.js, which a Meteor
|
|
// package cannot share with the app. tests/oauthProviderEmailDomains.test.cjs
|
|
// keeps the two identical below this comment.
|
|
|
|
// Match the email supplied by the configured identity provider, never a local
|
|
// profile field. No DNS lookup is necessary, including for intranet domains.
|
|
function isEmailDomainAllowed(email, configuration) {
|
|
if (configuration === undefined || configuration === null || configuration === '') return true;
|
|
if (typeof configuration !== 'string') return false;
|
|
const domains = configuration.split(',').map(value => value.trim().toLowerCase());
|
|
const validDomain = value => /^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/.test(value)
|
|
&& value.split('.').every(label => label && !label.startsWith('-') && !label.endsWith('-'));
|
|
// A malformed configured restriction must never silently disable the policy.
|
|
if (!domains.length || domains.some(domain => !validDomain(domain))) return false;
|
|
if (typeof email !== 'string' || /\s/.test(email)) return false;
|
|
const parts = email.split('@');
|
|
if (parts.length !== 2 || !parts[0] || !validDomain(parts[1].toLowerCase())) return false;
|
|
return domains.includes(parts[1].toLowerCase());
|
|
}
|
|
|
|
module.exports = { isEmailDomainAllowed };
|