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!

fix

kruzhambusd173590fb912
diff --git a/src/common/constants.ts b/src/common/constants.ts
index 6d36d6815..64fad589e 100644
--- a/src/common/constants.ts
+++ b/src/common/constants.ts
@@ -128,6 +128,7 @@ function getPercentageChange(oldVal: number, newVal: number, round: number = 2)
const JWT_LIFE_TIME = 7 * 24 * 60 * 60
const 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 PID_REGEX = /^(?!.*--)[a-zA-Z0-9-]{12}$/
const isValidPID = (pid: string) => PID_REGEX.test(pid)
@@ -168,5 +169,5 @@ export {
GDPR_EXPORT_TIMEFRAME, getRedisUserCountKey, redisProjectCountCacheTimeout, REDIS_LOG_CUSTOM_CACHE_KEY,
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,
+ REDIS_PAGEVIEWS_COUNT_KEY, SEND_WARNING_AT_PERC, PROJECT_INVITE_EXPIRE, TWO_FACTOR_AUTHENTICATION_APP_NAME, IP_REGEX
}
diff --git a/src/project/project.service.ts b/src/project/project.service.ts
index 0672af2ed..f965500c9 100644
--- a/src/project/project.service.ts
+++ b/src/project/project.service.ts
@@ -9,6 +9,7 @@ import * as _join from 'lodash/join'
import * as _find from 'lodash/find'
import * as _map from 'lodash/map'
import * as _pick from 'lodash/pick'
+import * as _trim from 'lodash/trim'
import * as _findIndex from 'lodash/findIndex'
import * as _includes from 'lodash/includes'
import * as dayjs from 'dayjs'
@@ -22,7 +23,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, redisProjectCountCacheTimeout, getRedisUserCountKey, redis, clickhouse, isSelfhosted, IP_REGEX,
} from '../common/constants'
dayjs.extend(utc)
@@ -223,16 +224,15 @@ export class ProjectService {
if (_size(_join(projectDTO.ipBlacklist, ',')) > 300) throw new UnprocessableEntityException('The list of allowed blacklisted IP addresses must be less than 300 characters.')
_map(projectDTO.ipBlacklist, ip => {
- if (!validateIP(ip)) {
- const regex = /^(([12]?[0-9]{1,2}|2[0-4][0-9]|25[0-5])(\.|\/)){4}([1-2]?[0-9]|3[0-2])$/;
- if (!regex.test(ip)) {
+ if (!validateIP(_trim(ip))) {
+ if (!IP_REGEX.test(_trim(ip))) {
throw new ConflictException(`IP address ${ip} is not correct`)
}
}
});
}
- // Returns amount of existing events starting from month
+ // Returns amount of exirsting events starting from month
async getRedisCount(uid: string): Promise<number | null> {
const countKey = getRedisUserCountKey(uid)
let count: string | number = await redis.get(countKey)