Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

feature(api): support better wildcard

Carl-Gerhard Lindesvärdf2fb6379c616
diff --git a/apps/api/src/utils/auth.ts b/apps/api/src/utils/auth.ts
index 7f5c3b90a..0dfb55a84 100644
--- a/apps/api/src/utils/auth.ts
+++ b/apps/api/src/utils/auth.ts
@@ -75,7 +75,17 @@ export async function validateSdkRequest(
if (client.cors) {
const domainAllowed = client.cors.split(',').find((domain) => {
- if (cleanDomain(domain) === cleanDomain(origin || '')) {
+ const cleanedDomain = cleanDomain(domain);
+ // support wildcard domains `*.foo.com`
+ if (cleanedDomain.includes('*')) {
+ const regex = new RegExp(
+ `${cleanedDomain.replaceAll('.', '\\.').replaceAll('*', '.+?')}`,
+ );
+
+ return regex.test(origin || '');
+ }
+
+ if (cleanedDomain === cleanDomain(origin || '')) {
return true;
}
});