Skip to content

Scheduling infrastructure for absolutely everyone.

fix: allow wildcard prefix in domain validation (#27413)

Alex van Andel5c2382d29620
diff --git a/packages/features/blocklist/components/CreateBlocklistEntryModal.tsx b/packages/features/blocklist/components/CreateBlocklistEntryModal.tsx
index 49f444bec81..327202975a4 100644
--- a/packages/features/blocklist/components/CreateBlocklistEntryModal.tsx
+++ b/packages/features/blocklist/components/CreateBlocklistEntryModal.tsx
@@ -72,7 +72,8 @@ export function CreateBlocklistEntryModal({
return t("invalid_email_address");
}
} else if (watchType === WatchlistType.DOMAIN) {
- if (!domainRegex.test(value)) {
+ const domainToValidate = value.startsWith("*.") ? value.slice(2) : value;
+ if (!domainRegex.test(domainToValidate)) {
return t("invalid_domain_format");
}
}
diff --git a/packages/features/watchlist/lib/service/WatchlistOperationsService.ts b/packages/features/watchlist/lib/service/WatchlistOperationsService.ts
index 3e8c18417c5..002e9019c91 100644
--- a/packages/features/watchlist/lib/service/WatchlistOperationsService.ts
+++ b/packages/features/watchlist/lib/service/WatchlistOperationsService.ts
@@ -56,8 +56,11 @@ export abstract class WatchlistOperationsService {
throw WatchlistErrors.invalidEmail("Invalid email address format");
}
- if (type === WatchlistType.DOMAIN && !domainRegex.test(value)) {
- throw WatchlistErrors.invalidDomain("Invalid domain format (e.g., example.com)");
+ if (type === WatchlistType.DOMAIN) {
+ const domainToValidate = value.startsWith("*.") ? value.slice(2) : value;
+ if (!domainRegex.test(domainToValidate)) {
+ throw WatchlistErrors.invalidDomain("Invalid domain format (e.g., example.com or *.example.com)");
+ }
}
}
diff --git a/packages/features/watchlist/lib/utils/normalization.test.ts b/packages/features/watchlist/lib/utils/normalization.test.ts
index 3e5ebf6bcf2..7d8343e8691 100644
--- a/packages/features/watchlist/lib/utils/normalization.test.ts
+++ b/packages/features/watchlist/lib/utils/normalization.test.ts
@@ -41,11 +41,24 @@ describe("normalization", () => {
expect(normalizeDomain("company.com.au")).toBe("company.com.au");
});
+ test("should accept and preserve wildcard prefix", () => {
+ expect(normalizeDomain("*.cal.com")).toBe("*.cal.com");
+ expect(normalizeDomain("*.EXAMPLE.COM")).toBe("*.example.com");
+ expect(normalizeDomain(" *.domain.org ")).toBe("*.domain.org");
+ expect(normalizeDomain("*.sub.domain.co.uk")).toBe("*.sub.domain.co.uk");
+ });
+
test("should throw on invalid domains", () => {
expect(() => normalizeDomain("invalid..domain")).toThrow("Invalid domain format");
expect(() => normalizeDomain(".domain.com")).toThrow("Invalid domain format");
expect(() => normalizeDomain("domain.")).toThrow("Invalid domain format");
});
+
+ test("should throw on invalid wildcard domains", () => {
+ expect(() => normalizeDomain("*.")).toThrow("Invalid domain format");
+ expect(() => normalizeDomain("*..domain.com")).toThrow("Invalid domain format");
+ expect(() => normalizeDomain("*.invalid..domain")).toThrow("Invalid domain format");
+ });
});
describe("extractDomainFromEmail", () => {
diff --git a/packages/features/watchlist/lib/utils/normalization.ts b/packages/features/watchlist/lib/utils/normalization.ts
index 75e92551cb2..4e33bd40dce 100644
--- a/packages/features/watchlist/lib/utils/normalization.ts
+++ b/packages/features/watchlist/lib/utils/normalization.ts
@@ -33,13 +33,14 @@ export function normalizeEmail(email: string): string {
* 1. Convert to lowercase
* 2. Trim whitespace
* 3. Remove @ prefix if present
+ * 4. Preserve *. prefix for wildcard domains
*
* Note: Domains are stored without @ prefix (e.g., mail.google.com, example.co.uk)
* Wildcard matching is configurable:
* - `*.cal.com` blocks all subdomains (app.cal.com, sub.app.cal.com, etc.)
* - `cal.com` only blocks exact matches
*
- * @param domain - Raw domain (with or without @ prefix)
+ * @param domain - Raw domain (with or without @ prefix, with or without *. prefix)
* @returns Normalized domain without @ prefix
*/
export function normalizeDomain(domain: string): string {
@@ -49,13 +50,22 @@ export function normalizeDomain(domain: string): string {
normalized = normalized.slice(1);
}
+ // Check for wildcard prefix and validate the domain part separately
+ let isWildcard = false;
+ let domainToValidate = normalized;
+
+ if (normalized.startsWith("*.")) {
+ isWildcard = true;
+ domainToValidate = normalized.slice(2); // Remove "*." for validation
+ }
+
const domainRegex =
/^[a-zA-Z0-9\u00a1-\uffff]([a-zA-Z0-9\u00a1-\uffff-]*[a-zA-Z0-9\u00a1-\uffff])?(\.[a-zA-Z0-9\u00a1-\uffff]([a-zA-Z0-9\u00a1-\uffff-]*[a-zA-Z0-9\u00a1-\uffff])?)*$/;
- if (!domainRegex.test(normalized)) {
+ if (!domainRegex.test(domainToValidate)) {
throw new Error(`Invalid domain format: ${domain}`);
}
- return normalized;
+ return isWildcard ? `*.${domainToValidate}` : domainToValidate;
}
/**