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 performance validator

Blue Mousee3f63f2a2d08
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.ts
index 6926f5566..ca86acdc9 100644
--- a/src/analytics/analytics.controller.ts
+++ b/src/analytics/analytics.controller.ts
@@ -184,6 +184,22 @@ const getElValue = el => {
return mysql.escape(el)
}
+
+// Performance object validator: none of the values cannot be bigger than 1000 * 60 * 5 (5 minutes)
+const MAX_PERFORMANCE_VALUE = 1000 * 60 * 5
+const isPerformanceValid = (perf: any) => {
+ return (
+ perf.dns <= MAX_PERFORMANCE_VALUE &&
+ perf.tls <= MAX_PERFORMANCE_VALUE &&
+ perf.conn <= MAX_PERFORMANCE_VALUE &&
+ perf.response <= MAX_PERFORMANCE_VALUE &&
+ perf.render <= MAX_PERFORMANCE_VALUE &&
+ perf.dom_load <= MAX_PERFORMANCE_VALUE &&
+ perf.page_load <= MAX_PERFORMANCE_VALUE &&
+ perf.ttfb <= MAX_PERFORMANCE_VALUE
+ )
+}
+
export const getPIDsArray = (pids, pid) => {
const pidsEmpty = _isEmpty(pids)
const pidEmpty = _isEmpty(pid)
@@ -392,7 +408,7 @@ export class AnalyticsController {
if (filters) {
try {
appliedFilters = JSON.parse(filters)
- } catch {}
+ } catch { }
}
return {
@@ -542,7 +558,7 @@ export class AnalyticsController {
if (filters) {
try {
appliedFilters = JSON.parse(filters)
- } catch {}
+ } catch { }
}
return {
@@ -815,13 +831,15 @@ export class AnalyticsController {
)
}
- if (!_isEmpty(logDTO.perf)) {
+ if (!_isEmpty(logDTO.perf) && isPerformanceValid(logDTO.perf)) {
if (!ua) {
ua = UAParser(userAgent)
}
+
if (!cc) {
cc = ct.getCountryForTimezone(logDTO.tz)?.id || (headers['cf-ipcountry'] === 'XX' ? 'NULL' : headers['cf-ipcountry'])
}
+
const dv = ua.device.type || 'desktop'
const br = ua.browser.name