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!

Done normal validation

Yevhenii Kb4987c7da158
diff --git a/package.json b/package.json
index bbaddaece..7c2ba96fb 100644
--- a/package.json
+++ b/package.json
@@ -63,6 +63,7 @@
"typeorm": "^0.2.45",
"ua-parser-js": "^1.0.2",
"uuid": "^8.3.2",
+ "validate-ip-node": "^1.0.8",
"validator": "^13.7.0"
},
"devDependencies": {
diff --git a/src/common/constants.ts b/src/common/constants.ts
index ec1234d79..6d36d6815 100644
--- a/src/common/constants.ts
+++ b/src/common/constants.ts
@@ -131,9 +131,6 @@ const HISTORY_LIFE_TIME_DAYS = 30
const 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 keys
const getRedisProjectKey = (pid: string) => `pid_${pid}`
const getRedisUserCountKey = (uid: string) => `user_c_${uid}`
@@ -166,7 +163,7 @@ const SEND_WARNING_AT_PERC = 85
const PROJECT_INVITE_EXPIRE = 48
export {
- clickhouse, JWT_LIFE_TIME, HISTORY_LIFE_TIME_DAYS, redis, isValidPID, isValidIP, getRedisProjectKey,
+ clickhouse, JWT_LIFE_TIME, HISTORY_LIFE_TIME_DAYS, redis, isValidPID, 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.ts
index 25f6fb8fd..6b58505a7 100644
--- a/src/project/project.service.ts
+++ b/src/project/project.service.ts
@@ -13,6 +13,7 @@ import * as _findIndex from 'lodash/findIndex'
import * as _includes from 'lodash/includes'
import * as dayjs from 'dayjs'
import * as utc from 'dayjs/plugin/utc'
+import validateIP from 'validate-ip-node'
import { Pagination, PaginationOptionsInterface } from '../common/pagination'
import { Project } from './entity/project.entity'
@@ -21,7 +22,7 @@ import { ProjectDTO } from './dto/project.dto'
import { UserType } from '../user/entities/user.entity'
import { Role } from '../project/entity/project-share.entity'
import {
- isValidPID, isValidIP, redisProjectCountCacheTimeout, getRedisUserCountKey, redis, clickhouse, isSelfhosted,
+ isValidPID, redisProjectCountCacheTimeout, getRedisUserCountKey, redis, clickhouse, isSelfhosted,
} from '../common/constants'
dayjs.extend(utc)
@@ -221,9 +222,9 @@ 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.')
- projectDTO.ipBlacklist.map((ip) => {
- if (!isValidIP(ip)) throw new ConflictException(`IP address ${ip} is not correct`)
- })
+ _map(projectDTO.ipBlacklist, ip => {
+ if (!validateIP(ip)) throw new ConflictException(`IP address ${ip} is not correct`)
+ });
}
// Returns amount of existing events starting from month