📈 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
Yevhenii K8b3b5e444c3b
diff --git a/src/common/constants.ts b/src/common/constants.tsindex ddaa7ac23..ec1234d79 100644--- a/src/common/constants.ts+++ b/src/common/constants.ts@@ -108,7 +108,7 @@ const TWO_FACTOR_AUTHENTICATION_APP_NAME = process.env.TWO_FACTOR_AUTHENTICATION/*** Calculates in percent, the change between 2 numbers.* e.g from 1000 to 500 = 50%- *+ ** @param oldVal The initial value* @param newVal The value that changed*/@@ -131,6 +131,9 @@ const HISTORY_LIFE_TIME_DAYS = 30const PID_REGEX = /^(?!.*--)[a-zA-Z0-9-]{12}$/const isValidPID = (pid: string) => PID_REGEX.test(pid)+const IP_REGEX = /^(((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(((\/([4-9]|[12][0-9]|3[0-2]))?)|\s?-\s?((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))))(,\s?|$))+/+const isValidIP = (ip: string) => IP_REGEX.test(ip)+// redis keysconst getRedisProjectKey = (pid: string) => `pid_${pid}`const getRedisUserCountKey = (uid: string) => `user_c_${uid}`@@ -163,7 +166,7 @@ const SEND_WARNING_AT_PERC = 85const PROJECT_INVITE_EXPIRE = 48export {- clickhouse, JWT_LIFE_TIME, HISTORY_LIFE_TIME_DAYS, redis, isValidPID, getRedisProjectKey,+ clickhouse, JWT_LIFE_TIME, HISTORY_LIFE_TIME_DAYS, redis, isValidPID, isValidIP, getRedisProjectKey,redisProjectCacheTimeout, getPercentageChange, UNIQUE_SESSION_LIFE_TIME, REDIS_LOG_DATA_CACHE_KEY,GDPR_EXPORT_TIMEFRAME, getRedisUserCountKey, redisProjectCountCacheTimeout, REDIS_LOG_CUSTOM_CACHE_KEY,REDIS_SESSION_SALT_KEY, HEARTBEAT_SID_LIFE_TIME, isSelfhosted, UUIDV5_NAMESPACE, SELFHOSTED_EMAIL,diff --git a/src/project/project.service.ts b/src/project/project.service.tsindex 11e5d6a13..25f6fb8fd 100644--- a/src/project/project.service.ts+++ b/src/project/project.service.ts@@ -1,4 +1,4 @@-import { ForbiddenException, Injectable, BadRequestException, UnprocessableEntityException, InternalServerErrorException } from '@nestjs/common'+import { ForbiddenException, Injectable, BadRequestException, UnprocessableEntityException, InternalServerErrorException, ConflictException } from '@nestjs/common'import { InjectRepository } from '@nestjs/typeorm'import { Repository } from 'typeorm'import * as _isEmpty from 'lodash/isEmpty'@@ -21,7 +21,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,+ isValidPID, isValidIP, redisProjectCountCacheTimeout, getRedisUserCountKey, redis, clickhouse, isSelfhosted,} from '../common/constants'dayjs.extend(utc)@@ -220,6 +220,10 @@ export class ProjectService {if (!_isArray(projectDTO.origins)) throw new UnprocessableEntityException('The list of allowed origins has to be an array of strings')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.')++ projectDTO.ipBlacklist.map((ip) => {+ if (!isValidIP(ip)) throw new ConflictException(`IP address ${ip} is not correct`)+ })}// Returns amount of existing events starting from month