Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

added wildcard origin support

Blue Mouse842e1147408d
diff --git a/apps/selfhosted/src/analytics/analytics.service.ts b/apps/selfhosted/src/analytics/analytics.service.ts
index a2d367aed..5a77c9e90 100644
--- a/apps/selfhosted/src/analytics/analytics.service.ts
+++ b/apps/selfhosted/src/analytics/analytics.service.ts
@@ -204,6 +204,30 @@ export enum DataType {
CAPTCHA = 'captcha',
}
+const isValidOrigin = (origins: string[], origin: string) => {
+ for (let i = 0; i < _size(origins); ++i) {
+ const allowedOrigin = origins[i]
+
+ // Check if the allowedOrigin is an exact match
+ if (allowedOrigin === origin) {
+ return true
+ }
+
+ // Check if the allowedOrigin contains a wildcard
+ if (_includes(allowedOrigin, '*')) {
+ // Escape the wildcard character for use in a regular expression
+ const wildcardRegex = new RegExp(allowedOrigin.replace(/\*/g, '.*'))
+
+ // Check if the origin matches the wildcard pattern
+ if (wildcardRegex.test(origin)) {
+ return true
+ }
+ }
+ }
+
+ return false
+}
+
@Injectable()
export class AnalyticsService {
constructor(private readonly projectService: ProjectService) {}
@@ -227,7 +251,7 @@ export class AnalyticsService {
}
} else {
const { hostname } = new URL(origin)
- if (!_includes(origins, hostname)) {
+ if (!isValidOrigin(origins, hostname)) {
throw new BadRequestException(
"This origin is prohibited by the project's origins policy",
)