Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: type errors

IgorHortad8ea2a9a5c82
diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.ts
index 0bf9f3b7bf..3e8b0117e5 100644
--- a/backend/src/ee/services/oidc/oidc-config-service.ts
+++ b/backend/src/ee/services/oidc/oidc-config-service.ts
@@ -18,7 +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 { matchesAllowedEmailDomain } from "@app/lib/validator";
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";
diff --git a/backend/src/lib/validator/email-domain-matcher.ts b/backend/src/lib/validator/email-domain-matcher.ts
new file mode 100644
index 0000000000..3b17848720
--- /dev/null
+++ b/backend/src/lib/validator/email-domain-matcher.ts
@@ -0,0 +1,45 @@
+/**
+ * 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").
+ *
+ * Wildcard patterns match only the exact suffix or subdomains of it:
+ * - The root domain: [email protected] matches *.acme.com
+ * - Any subdomain: [email protected] matches *.acme.com
+ * - Multi-level subdomains: [email protected] matches *.acme.com
+ *
+ * Does NOT match prefix-style abuse (e.g. *.example.com must not allow [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 exact suffix or subdomains only (domain === suffix or domain ends with .suffix)
+ // Avoids prefix abuse: *.example.com must not allow example.com.evil
+ const suffix = patternLower.slice(2).trim(); // everything after "*."
+ if (suffix && (emailDomain === suffix || emailDomain.endsWith(`.${suffix}`))) {
+ return true;
+ }
+ } else if (emailDomain === patternLower) {
+ return true;
+ }
+ }
+
+ return false;
+};
diff --git a/backend/src/lib/validator/index.ts b/backend/src/lib/validator/index.ts
index 1033c07ed7..d1e2fd9f45 100644
--- a/backend/src/lib/validator/index.ts
+++ b/backend/src/lib/validator/index.ts
@@ -1,3 +1,4 @@
+export { matchesAllowedEmailDomain } from "./email-domain-matcher";
export { isDisposableEmail } from "./validate-email";
export { isValidFolderName, isValidSecretPath } from "./validate-folder-name";
export {