📈 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
added validation origins
kruzhambusc61543acaf9a
diff --git a/src/common/constants.ts b/src/common/constants.tsindex 4ce0b554f..3a62ddd34 100644--- a/src/common/constants.ts+++ b/src/common/constants.ts@@ -129,7 +129,8 @@ function getPercentageChange(oldVal: number, newVal: number, round: number = 2)const JWT_LIFE_TIME = 7 * 24 * 60 * 60const HISTORY_LIFE_TIME_DAYS = 30-const IP_REGEX = /^(([12]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])(\.|\/)){4}([1-2]?[0-9]|3[0-2])$/;+const ORIGINS_REGEX = /^(?=.{1,255}$)[0-9A-Za-z\:](?:(?:[0-9A-Za-z\:]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z\:](?:(?:[0-9A-Za-z\:]|-){0,61}[0-9A-Za-z\:])?)*\.?$/+const IP_REGEX = /^(([12]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])(\.|\/)){4}([1-2]?[0-9]|3[0-2])$/const PID_REGEX = /^(?!.*--)[a-zA-Z0-9-]{12}$/const isValidPID = (pid: string) => PID_REGEX.test(pid)@@ -171,5 +172,5 @@ export {REDIS_SESSION_SALT_KEY, HEARTBEAT_SID_LIFE_TIME, isSelfhosted, UUIDV5_NAMESPACE, SELFHOSTED_EMAIL,SELFHOSTED_PASSWORD, SELFHOSTED_UUID, CLICKHOUSE_INIT_QUERIES, REDIS_USERS_COUNT_KEY, REDIS_PROJECTS_COUNT_KEY,REDIS_PAGEVIEWS_COUNT_KEY, SEND_WARNING_AT_PERC, PROJECT_INVITE_EXPIRE, TWO_FACTOR_AUTHENTICATION_APP_NAME,- IP_REGEX, isNewRelicEnabled,+ IP_REGEX, isNewRelicEnabled, ORIGINS_REGEX,}diff --git a/src/project/project.service.ts b/src/project/project.service.tsindex 718690b68..104326231 100644--- a/src/project/project.service.ts+++ b/src/project/project.service.ts@@ -24,7 +24,7 @@ import { ProjectDTO } from './dto/project.dto'import { UserType } from '../user/entities/user.entity'import { Role } from '../project/entity/project-share.entity'import {- isValidPID, redisProjectCountCacheTimeout, getRedisUserCountKey, redis, clickhouse, isSelfhosted, IP_REGEX,+ isValidPID, redisProjectCountCacheTimeout, getRedisUserCountKey, redis, clickhouse, isSelfhosted, IP_REGEX, ORIGINS_REGEX,} from '../common/constants'dayjs.extend(utc)@@ -224,13 +224,20 @@ export class ProjectService {if (_size(_join(projectDTO.origins, ',')) > 300) throw new UnprocessableEntityException('The list of allowed origins has to be smaller than 300 symbols')if (_size(_join(projectDTO.ipBlacklist, ',')) > 300) throw new UnprocessableEntityException('The list of allowed blacklisted IP addresses must be less than 300 characters.')++ _map(projectDTO.origins, host => {+ if (!ORIGINS_REGEX.test(_trim(host))) {+ throw new ConflictException(`Host ${host} is not correct`)+ }+ })+_map(projectDTO.ipBlacklist, ip => {if (!validateIP(_trim(ip))) {if (!IP_REGEX.test(_trim(ip))) {throw new ConflictException(`IP address ${ip} is not correct`)}}- });+ })}// Returns amount of exirsting events starting from month