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!

protected project related improvementsrelated

Blue Mouseec27745a6d64
diff --git a/apps/production/src/analytics/analytics.controller.ts b/apps/production/src/analytics/analytics.controller.ts
index 11b8e7a13..07f93fd58 100644
--- a/apps/production/src/analytics/analytics.controller.ts
+++ b/apps/production/src/analytics/analytics.controller.ts
@@ -46,7 +46,6 @@ import { EventsDTO } from './dto/events.dto'
import { AnalyticsGET_DTO } from './dto/getData.dto'
import { GetUserFlowDTO } from './dto/getUserFlow.dto'
import { AppLoggerService } from '../logger/logger.service'
-import { ProjectPasswordDto } from '../project/dto/project-password.dto'
import {
REDIS_LOG_DATA_CACHE_KEY,
REDIS_LOG_PERF_CACHE_KEY,
@@ -262,7 +261,7 @@ export class AnalyticsController {
@Query() data: AnalyticsGET_DTO,
@CurrentUserId() uid: string,
isCaptcha = false,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<any> {
const {
pid,
@@ -295,7 +294,7 @@ export class AnalyticsController {
period,
safeTimezone,
)
- await this.analyticsService.checkProjectAccess(pid, uid, body.password)
+ await this.analyticsService.checkProjectAccess(pid, uid, headers['x-password'])
let queryCustoms = `SELECT ev, count() FROM customEV WHERE pid = {pid:FixedString(12)} ${filtersQuery} AND created BETWEEN {groupFrom:String} AND {groupTo:String} GROUP BY ev`
let subQuery = `FROM ${
@@ -373,7 +372,7 @@ export class AnalyticsController {
async getChartData(
@Query() data: AnalyticsGET_DTO,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<any> {
const {
pid,
@@ -402,7 +401,7 @@ export class AnalyticsController {
period,
safeTimezone,
)
- await this.analyticsService.checkProjectAccess(pid, uid, body.password)
+ await this.analyticsService.checkProjectAccess(pid, uid, headers['x-password'])
let subQuery = `FROM analytics WHERE pid = {pid:FixedString(12)} ${filtersQuery} AND created BETWEEN {groupFrom:String} AND {groupTo:String}`
let customEVFilterApplied = false
@@ -445,7 +444,7 @@ export class AnalyticsController {
async getPerfData(
@Query() data: AnalyticsGET_DTO,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<any> {
const {
pid,
@@ -474,7 +473,7 @@ export class AnalyticsController {
period,
safeTimezone,
)
- await this.analyticsService.checkProjectAccess(pid, uid, body.password)
+ await this.analyticsService.checkProjectAccess(pid, uid, headers['x-password'])
const subQuery = `FROM performance WHERE pid = {pid:FixedString(12)} ${filtersQuery} AND created BETWEEN {groupFrom:String} AND {groupTo:String}`
@@ -508,7 +507,7 @@ export class AnalyticsController {
async getPerfChartData(
@Query() data: AnalyticsGET_DTO,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<any> {
const {
pid,
@@ -537,7 +536,7 @@ export class AnalyticsController {
period,
safeTimezone,
)
- await this.analyticsService.checkProjectAccess(pid, uid, body.password)
+ await this.analyticsService.checkProjectAccess(pid, uid, headers['x-password'])
const paramsData = {
params: {
@@ -577,7 +576,7 @@ export class AnalyticsController {
async getUserFlow(
@Query() data: GetUserFlowDTO,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<IUserFlow | { appliedFilters: any[] }> {
const { pid, period, from, to, timezone = DEFAULT_TIMEZONE, filters } = data
this.analyticsService.validatePID(pid)
@@ -586,7 +585,7 @@ export class AnalyticsController {
this.analyticsService.validatePeriod(period)
}
- await this.analyticsService.checkProjectAccess(pid, uid, body.password)
+ await this.analyticsService.checkProjectAccess(pid, uid, headers['x-password'])
const safeTimezone = this.analyticsService.getSafeTimezone(timezone)
const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(
@@ -621,7 +620,7 @@ export class AnalyticsController {
async getOverallStats(
@Query() data,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<any> {
const { pids, pid } = data
const pidsArray = getPIDsArray(pids, pid)
@@ -633,7 +632,7 @@ export class AnalyticsController {
// fix needed
// fix needed
// passwords and for projects protected []
- await this.analyticsService.checkProjectAccess(currentPID, uid, body.password)
+ await this.analyticsService.checkProjectAccess(currentPID, uid, headers['x-password'])
})
await Promise.all(validationPromises)
@@ -694,14 +693,14 @@ export class AnalyticsController {
async getHeartBeatStats(
@Query() data,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<object> {
const { pids, pid } = data
const pidsArray = getPIDsArray(pids, pid)
const validationPromises = _map(pidsArray, async currentPID => {
this.analyticsService.validatePID(currentPID)
- await this.analyticsService.checkProjectAccess(currentPID, uid, body.password)
+ await this.analyticsService.checkProjectAccess(currentPID, uid, headers['x-password'])
})
await Promise.all(validationPromises)
@@ -729,12 +728,12 @@ export class AnalyticsController {
async getLiveVisitors(
@Query() data,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<object> {
const { pid } = data
this.analyticsService.validatePID(pid)
- await this.analyticsService.checkProjectAccess(pid, uid, body.password)
+ await this.analyticsService.checkProjectAccess(pid, uid, headers['x-password'])
const keys = await redis.keys(`sd:*:${pid}`)
@@ -1036,7 +1035,7 @@ export class AnalyticsController {
async getCustomEvents(
@Query() data: GetCustomEventsDto,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<any> {
const {
pid,
@@ -1057,7 +1056,7 @@ export class AnalyticsController {
this.analyticsService.validateTimebucket(timeBucket)
const [filtersQuery, filtersParams, parsedFilters] =
this.analyticsService.getFiltersQuery(filters, DataType.ANALYTICS)
- await this.analyticsService.checkProjectAccess(pid, uid, body.password)
+ await this.analyticsService.checkProjectAccess(pid, uid, headers['x-password'])
const safeTimezone = this.analyticsService.getSafeTimezone(timezone)
const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(
diff --git a/apps/production/src/project/dto/project-password.dto.ts b/apps/production/src/project/dto/project-password.dto.ts
index d04e8de8f..d22890d20 100644
--- a/apps/production/src/project/dto/project-password.dto.ts
+++ b/apps/production/src/project/dto/project-password.dto.ts
@@ -1,15 +1,11 @@
-import { IsOptional, Matches, ValidateIf } from 'class-validator'
+import { IsOptional, IsString, MaxLength, MinLength, ValidateIf } from 'class-validator'
+
+export const MAX_PROJECT_PASSWORD_LENGTH = 80
export class ProjectPasswordDto {
- @IsOptional()
- @ValidateIf(o => o.password !== null)
- @Matches(
- /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[a-zA-Z\d!@#$%^&*]{8,72}$/,
- {
- message:
- 'Password must contain at least 8 characters, one uppercase, one lowercase, one number and one special character (!@#$%^&*).',
- },
- )
+ @IsString()
+ @MaxLength(MAX_PROJECT_PASSWORD_LENGTH, { message: 'Max length is $constraint1 characters' })
+ @MinLength(1, { message: 'Min length is $constraint1 characters' })
password?: string | null
@IsOptional()
diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.ts
index 042e3ff42..a1d588b8b 100644
--- a/apps/production/src/project/project.controller.ts
+++ b/apps/production/src/project/project.controller.ts
@@ -76,8 +76,6 @@ import {
TransferProjectBodyDto,
ConfirmTransferProjectQueriesDto,
CancelTransferProjectQueriesDto,
- GetProtectedProjectDto,
- ProjectPasswordDto,
UpdateProjectDto,
} from './dto'
@@ -981,7 +979,7 @@ export class ProjectController {
async checkPassword(
@Param('projectId') projectId: string,
@CurrentUserId() userId: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<Boolean> {
this.logger.log({ projectId }, 'GET /project/password/:projectId')
@@ -992,7 +990,7 @@ export class ProjectController {
}
try {
- this.projectService.allowedToView(project, userId, body.password)
+ this.projectService.allowedToView(project, userId, headers['x-password'])
} catch {
return false
}
@@ -1304,7 +1302,7 @@ export class ProjectController {
async getOne(
@Param('id') id: string,
@CurrentUserId() uid: string,
- @Headers() body: ProjectPasswordDto,
+ @Headers() headers: { 'x-password'?: string },
): Promise<Project | object> {
this.logger.log({ id }, 'GET /project/:id')
if (!isValidPID(id)) {
@@ -1321,14 +1319,14 @@ export class ProjectController {
throw new NotFoundException('Project was not found in the database')
}
- if (project.isPasswordProtected && _isEmpty(body.password)) {
+ if (project.isPasswordProtected && _isEmpty(headers['x-password'])) {
return {
isPasswordProtected: true,
id: project.id,
}
}
- this.projectService.allowedToView(project, uid, body.password)
+ this.projectService.allowedToView(project, uid, headers['x-password'])
return {
..._omit(project, ['admin', 'passwordHash']),
diff --git a/apps/production/src/project/project.service.ts b/apps/production/src/project/project.service.ts
index d21b27340..f942d16d9 100644
--- a/apps/production/src/project/project.service.ts
+++ b/apps/production/src/project/project.service.ts
@@ -32,6 +32,7 @@ import { Project } from './entity/project.entity'
import { ProjectShare, Role } from './entity/project-share.entity'
import { ProjectDTO } from './dto/project.dto'
import { UserType } from '../user/entities/user.entity'
+import { MAX_PROJECT_PASSWORD_LENGTH } from './dto/project-password.dto'
import {
isValidPID,
redisProjectCountCacheTimeout,
@@ -298,7 +299,7 @@ export class ProjectService {
allowedToView(project: Project, uid: string | null, password?: string | null): void {
if (project.isPasswordProtected && password) {
- if (compareSync(password, project.passwordHash)) {
+ if (_size(password) <= MAX_PROJECT_PASSWORD_LENGTH && compareSync(password, project.passwordHash)) {
return null
}