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!

update servisec

kruzhambus23132f0eb520
diff --git a/apps/production/src/project/project.service.ts b/apps/production/src/project/project.service.ts
index 81e9d5b09..d3edb9095 100644
--- a/apps/production/src/project/project.service.ts
+++ b/apps/production/src/project/project.service.ts
@@ -18,6 +18,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 { compareSync } from 'bcrypt'
// @ts-ignore
import * as validateIP from 'validate-ip-node'
@@ -134,6 +135,8 @@ export class ProjectService {
'ipBlacklist',
'captchaSecretKey',
'isCaptchaEnabled',
+ 'passwordHash',
+ 'isPasswordProtected',
],
})
if (_isEmpty(project))
@@ -293,7 +296,23 @@ export class ProjectService {
return this.projectsRepository.findOne({ where, ...params })
}
- allowedToView(project: Project, uid: string | null): void {
+ allowedToView(project: Project, uid: string | null, password?: string | null): void {
+ if (project.public && project.isPasswordProtected && password) {
+ if (compareSync(password, project.passwordHash)) {
+ return null
+ }
+
+ throw new ConflictException('Incorrect password')
+ }
+
+ if (
+ (project.isPasswordProtected && uid !== project.admin?.id) ||
+ (project.isPasswordProtected &&
+ _findIndex(project.share, ({ user }) => user?.id !== uid) !== -1)
+ ) {
+ throw new ForbiddenException('This project is password protected')
+ }
+
if (
project.public ||
uid === project.admin?.id ||