📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
using session salts
Blue Mouse8132de1e8a17
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.tsindex 0d69ffa64..539c5b5c6 100644--- a/src/analytics/analytics.controller.ts+++ b/src/analytics/analytics.controller.ts@@ -28,7 +28,7 @@ import { AppLoggerService } from '../logger/logger.service'import { SelfhostedGuard } from '../common/guards/selfhosted.guard'import {REDIS_LOG_DATA_CACHE_KEY, redis, REDIS_LOG_CUSTOM_CACHE_KEY,- HEARTBEAT_SID_LIFE_TIME, REDIS_USERS_COUNT_KEY, REDIS_PROJECTS_COUNT_KEY, REDIS_PAGEVIEWS_COUNT_KEY, // REDIS_SESSION_SALT_KEY,+ HEARTBEAT_SID_LIFE_TIME, REDIS_USERS_COUNT_KEY, REDIS_PROJECTS_COUNT_KEY, REDIS_PAGEVIEWS_COUNT_KEY, REDIS_SESSION_SALT_KEY,} from '../common/constants'dayjs.extend(utc)@@ -221,8 +221,8 @@ export class AnalyticsController {const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''if (eventsDTO.unique) {- // const salt = await redis.get(REDIS_SESSION_SALT_KEY)- const sessionHash = getSessionKeyCustom(ip, userAgent, eventsDTO.pid, eventsDTO.ev/*, salt */)+ const salt = await redis.get(REDIS_SESSION_SALT_KEY)+ const sessionHash = getSessionKeyCustom(ip, userAgent, eventsDTO.pid, eventsDTO.ev, salt)const unique = await this.analyticsService.isUnique(sessionHash)if (!unique) {@@ -266,8 +266,8 @@ export class AnalyticsController {const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''- // const salt = await redis.get(REDIS_SESSION_SALT_KEY)- const sessionHash = getSessionKey(ip, userAgent, logDTO.pid/*, salt */)+ const salt = await redis.get(REDIS_SESSION_SALT_KEY)+ const sessionHash = getSessionKey(ip, userAgent, logDTO.pid, salt)const unique = await this.analyticsService.isUnique(sessionHash)let dto: Array<string | number>const ua = UAParser(userAgent)@@ -317,8 +317,8 @@ export class AnalyticsController {const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''- // const salt = await redis.get(REDIS_SESSION_SALT_KEY)- const sessionHash = getSessionKey(ip, userAgent, logDTO.pid/*, salt */)+ const salt = await redis.get(REDIS_SESSION_SALT_KEY)+ const sessionHash = getSessionKey(ip, userAgent, logDTO.pid, salt)const unique = await this.analyticsService.isUnique(sessionHash)const ua = UAParser(userAgent)diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.tsindex 19044ba78..790bf5b43 100644--- a/src/analytics/analytics.service.ts+++ b/src/analytics/analytics.service.ts@@ -24,7 +24,7 @@ import { ACCOUNT_PLANS } from '../user/entities/user.entity'import {redis, isValidPID, getRedisProjectKey, redisProjectCacheTimeout,UNIQUE_SESSION_LIFE_TIME, clickhouse, getPercentageChange, getRedisUserCountKey,- redisProjectCountCacheTimeout, isSelfhosted, // REDIS_SESSION_SALT_KEY,+ redisProjectCountCacheTimeout, isSelfhosted, REDIS_SESSION_SALT_KEY,} from '../common/constants'import { getProjectsClickhouse } from '../common/utils'import { PageviewsDTO } from './dto/pageviews.dto'@@ -231,8 +231,8 @@ export class AnalyticsService {const { pid } = logDTOthis.validatePID(pid)- // const salt = await redis.get(REDIS_SESSION_SALT_KEY)- const sessionHash = getSessionKey(ip, userAgent, pid/*, salt */)+ const salt = await redis.get(REDIS_SESSION_SALT_KEY)+ const sessionHash = getSessionKey(ip, userAgent, pid, salt)const sessionExists = await this.isSessionOpen(sessionHash)if (!sessionExists) throw new ForbiddenException('The Heartbeat session does not exist')diff --git a/src/task-manager/task-manager.service.ts b/src/task-manager/task-manager.service.tsindex b19ba0d09..094ea0f00 100644--- a/src/task-manager/task-manager.service.ts+++ b/src/task-manager/task-manager.service.ts@@ -1,6 +1,6 @@import { Injectable } from '@nestjs/common'import { Cron, CronExpression } from '@nestjs/schedule'-// import * as bcrypt from 'bcrypt'+import * as bcrypt from 'bcrypt'import * as dayjs from 'dayjs'import * as utc from 'dayjs/plugin/utc'import * as _isEmpty from 'lodash/isEmpty'@@ -16,7 +16,7 @@ import { LetterTemplate } from '../mailer/letter'import { AnalyticsService } from '../analytics/analytics.service'import { ReportFrequency } from '../user/entities/user.entity'import {- clickhouse, redis, REDIS_LOG_DATA_CACHE_KEY, REDIS_LOG_CUSTOM_CACHE_KEY, isSelfhosted, // REDIS_SESSION_SALT_KEY,+ clickhouse, redis, REDIS_LOG_DATA_CACHE_KEY, REDIS_LOG_CUSTOM_CACHE_KEY, isSelfhosted, REDIS_SESSION_SALT_KEY,REDIS_USERS_COUNT_KEY, REDIS_PROJECTS_COUNT_KEY, REDIS_PAGEVIEWS_COUNT_KEY,} from '../common/constants'import { getRandomTip } from '../common/utils'@@ -60,11 +60,11 @@ export class TaskManagerService {}}- // @Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)- // async generateSessionSalt(): Promise<void> {- // const salt = await bcrypt.genSalt(10)- // await redis.set(REDIS_SESSION_SALT_KEY, salt, 'EX', 87000)- // }+ @Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)+ async generateSessionSalt(): Promise<void> {+ const salt = await bcrypt.genSalt(10)+ await redis.set(REDIS_SESSION_SALT_KEY, salt, 'EX', 87000)+ }// EVERY SUNDAY AT 2:30 AM@Cron('30 02 * * 0')