Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(sso): support wildcard email domains for OIDC
IgorHorta0c43faeaca6a
diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.tsindex be1abf8114..0bf9f3b7bf 100644--- a/backend/src/ee/services/oidc/oidc-config-service.ts+++ b/backend/src/ee/services/oidc/oidc-config-service.ts@@ -18,6 +18,7 @@ import { crypto } from "@app/lib/crypto";import { BadRequestError, ForbiddenRequestError, NotFoundError, OidcAuthError } from "@app/lib/errors";import { AuthAttemptAuthMethod, AuthAttemptAuthResult, authAttemptCounter } from "@app/lib/telemetry/metrics";import { OrgServiceActor } from "@app/lib/types";+import { matchesAllowedEmailDomain } from "@app/lib/validator/email-domain-matcher";import { ActorType, AuthMethod, AuthTokenType } from "@app/services/auth/auth-type";import { TAuthTokenServiceFactory } from "@app/services/auth-token/auth-token-service";import { TokenType } from "@app/services/auth-token/auth-token-types";@@ -737,13 +738,10 @@ export const oidcConfigServiceFactory = ({});}- if (oidcCfg.allowedEmailDomains) {- const allowedDomains = oidcCfg.allowedEmailDomains.split(", ");- if (!allowedDomains.includes(claims.email.split("@")[1])) {- throw new ForbiddenRequestError({- message: "Email not allowed."- });- }+ if (!matchesAllowedEmailDomain(claims.email, oidcCfg.allowedEmailDomains ?? "")) {+ throw new ForbiddenRequestError({+ message: "Email not allowed."+ });}const name = claims?.given_name || claims?.name;diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex d327f17b1d..773d0cac2b 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -3211,7 +3211,7 @@ export const OidcSSo = {UPDATE_CONFIG: {organizationId: "The ID of the organization to update the OIDC config for.",allowedEmailDomains:- "A list of allowed email domains that users can use to authenticate with. This field is comma separated. Example: 'example.com,acme.com'",+ "A list of allowed email domains that users can use to authenticate with. This field is comma separated. Supports wildcards (e.g. *.example.com). Example: 'example.com, *.acme.com'",discoveryURL: "The URL of the OIDC discovery endpoint.",configurationType: "The configuration type to use for the OIDC configuration.",issuer:@@ -3231,7 +3231,7 @@ export const OidcSSo = {CREATE_CONFIG: {organizationId: "The ID of the organization to create the OIDC config for.",allowedEmailDomains:- "A list of allowed email domains that users can use to authenticate with. This field is comma separated.",+ "A list of allowed email domains that users can use to authenticate with. This field is comma separated. Supports wildcards (e.g. *.example.com).",discoveryURL: "The URL of the OIDC discovery endpoint.",configurationType: "The configuration type to use for the OIDC configuration.",issuer:diff --git a/backend/src/lib/validator/email-domain-matcher.ts b/backend/src/lib/validator/email-domain-matcher.tsnew file mode 100644index 0000000000..8796511f0c--- /dev/null+++ b/backend/src/lib/validator/email-domain-matcher.ts@@ -0,0 +1,50 @@+/**+ * Checks if an email's domain matches the allowed domains configuration.+ * Supports exact domains (e.g. "example.com") and wildcard patterns (e.g. "*.example.com", "*.infisical").+ *+ * Wildcard patterns match:+ * - The root domain: [email protected] matches *.acme.com+ * - Any subdomain: [email protected] matches *.acme.com+ * - Multi-level subdomains: [email protected] matches *.acme.com+ * - Parent domains: *.infisical matches [email protected], [email protected]+ *+ * Matching is case-insensitive (email domains are case-insensitive per RFC 5321).+ */+export const matchesAllowedEmailDomain = (email: string, allowedDomainsConfig: string): boolean => {+ if (!allowedDomainsConfig?.trim()) {+ return true;+ }++ const emailParts = email.split("@");+ if (emailParts.length !== 2 || !emailParts[1]?.trim()) {+ return false;+ }++ const emailDomain = emailParts[1].trim().toLowerCase();+ const patterns = allowedDomainsConfig+ .split(/,\s*/)+ .map((p) => p.trim())+ .filter(Boolean);++ for (const pattern of patterns) {+ const patternLower = pattern.toLowerCase();++ if (patternLower.startsWith("*.")) {+ // Wildcard: *.suffix - matches suffix as a domain label (e.g. *.infisical matches infisical.com, team.infisical.com)+ const suffix = patternLower.slice(2).trim(); // everything after "*."+ if (+ suffix &&+ (emailDomain === suffix ||+ emailDomain.endsWith(`.${suffix}`) ||+ emailDomain.startsWith(`${suffix}.`) ||+ emailDomain.includes(`.${suffix}.`))+ ) {+ return true;+ }+ } else if (emailDomain === patternLower) {+ return true;+ }+ }++ return false;+};diff --git a/docs/documentation/platform/sso/general-oidc/overview.mdx b/docs/documentation/platform/sso/general-oidc/overview.mdxindex 5ba4692647..9f5d0c54a3 100644--- a/docs/documentation/platform/sso/general-oidc/overview.mdx+++ b/docs/documentation/platform/sso/general-oidc/overview.mdx@@ -47,7 +47,7 @@ Prerequisites:2.3. Select the appropriate JWT signature algorithm for your IdP. Currently, the supported options are RS256, RS512, HS256, and EdDSA.- 2.4. Optionally, you can define a whitelist of allowed email domains.+ 2.4. Optionally, you can define a whitelist of allowed email domains. Wildcard patterns such as `*.example.com` are supported to allow entire subdomain trees (e.g. `team.example.com`, `eng.example.com`).Finally, fill out the **Client ID** and **Client Secret** fields and press **Update** to complete the required configuration.diff --git a/docs/documentation/platform/sso/okta-oidc.mdx b/docs/documentation/platform/sso/okta-oidc.mdxindex 4ce38c2751..c80cbe5d1d 100644--- a/docs/documentation/platform/sso/okta-oidc.mdx+++ b/docs/documentation/platform/sso/okta-oidc.mdx@@ -76,7 +76,7 @@ description: "Learn how to configure Okta OIDC for Infisical SSO."Currently, the following JWT signature algorithms are supported: RS256, RS512, HS256, and EdDSA. Okta typically uses RS256.</Info>- Optionally, you can define a whitelist of allowed email domains to restrict which users can authenticate.+ Optionally, you can define a whitelist of allowed email domains to restrict which users can authenticate. Wildcard patterns such as `*.example.com` are supported to allow entire subdomain trees (e.g. `team.example.com`, `eng.example.com`).Once you've filled in all the required fields, click **Update** to save the configuration.diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsxindex f980b2e4ff..be5d8e840d 100644--- a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OIDCModal.tsx@@ -382,11 +382,11 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDelename="allowedEmailDomains"render={({ field, fieldState: { error } }) => (<FormControl- label="Allowed Email Domains (defaults to any)"+ label="Allowed Email Domains (defaults to any, supports wildcards e.g. *.example.com)"errorText={error?.message}isError={Boolean(error)}>- <Input {...field} placeholder="infisical.com, google.com" autoComplete="off" />+ <Input {...field} placeholder="infisical.com, *.google.com" autoComplete="off" /></FormControl>)}/>