📈 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
general improvements
Blue Mouse2db03bfbcb11
diff --git a/package.json b/package.jsonindex 67061e5e1..23ad3e854 100644--- a/package.json+++ b/package.json@@ -24,48 +24,48 @@"test:e2e": "jest --config ./test/jest-e2e.json"},"dependencies": {- "@nestjs/common": "^8.2.4",+ "@nestjs/common": "^8.2.6","@nestjs/config": "^1.1.6",- "@nestjs/core": "^8.2.4",- "@nestjs/passport": "^8.0.1",- "@nestjs/platform-express": "^8.2.4",+ "@nestjs/core": "^8.2.6",+ "@nestjs/passport": "^8.1.0",+ "@nestjs/platform-express": "^8.2.6","@nestjs/schedule": "^1.0.2",- "@nestjs/swagger": "^5.1.5",- "@nestjs/typeorm": "^8.0.2",- "axios": "^0.23.0",+ "@nestjs/swagger": "^5.2.0",+ "@nestjs/typeorm": "^8.0.3","bcrypt": "^5.0.1","blake3": "^2.1.7","body-parser": "^1.19.1",- "class-transformer": "^0.4.0",+ "class-transformer": "^0.5.1","class-validator": "^0.13.2",- "clickhouse": "^2.4.2",+ "clickhouse": "^2.4.3","cookie-parser": "^1.4.6","cross-env": "^7.0.3","dayjs": "^1.10.7","dotenv": "^10.0.0","express": "^4.17.2","handlebars": "^4.7.7",- "ioredis": "^4.28.2",+ "ioredis": "^4.28.3",+ "isbot": "^3.4.1","jsonwebtoken": "^8.5.1","lodash": "^4.17.21","mysql": "^2.18.1","nodemailer": "^6.7.2",- "passport": "^0.4.1",+ "passport": "^0.5.2","passport-jwt": "^4.0.0","php-serialize": "^4.0.2","reflect-metadata": "^0.1.13","rimraf": "^3.0.2",- "rxjs": "^7.5.1",+ "rxjs": "^7.5.2","stripe": "^8.195.0","typeorm": "^0.2.41",- "ua-parser-js": "^0.7.31",+ "ua-parser-js": "^1.0.2","uuid": "^8.3.2","verify-paddle-webhook": "^1.1.0"},"devDependencies": {- "@nestjs/cli": "^7.6.0",- "@nestjs/testing": "^7.6.18",- "@types/bcrypt": "^3.0.1",+ "@nestjs/cli": "^8.2.0",+ "@nestjs/testing": "^8.2.6",+ "@types/bcrypt": "^5.0.0","@types/express": "^4.17.13","@types/ioredis": "^4.28.7","@types/jest": "^27.4.0",@@ -80,12 +80,12 @@"eslint-plugin-prettier": "^3.4.1","jest": "^27.4.7","prettier": "^2.5.1",- "supertest": "^6.1.6",+ "supertest": "^6.2.2","ts-jest": "^26.5.6","ts-loader": "^8.3.0","ts-node": "^9.1.1","tsconfig-paths": "^3.12.0",- "typescript": "^4.5.4"+ "typescript": "^4.5.5"},"jest": {"moduleFileExtensions": [diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.tsindex c46ebfc9f..e7f42e750 100644--- a/src/analytics/analytics.controller.ts+++ b/src/analytics/analytics.controller.ts@@ -11,10 +11,11 @@ import { v4 as uuidv4 } from 'uuid'import { hash } from 'blake3'import {Controller, Body, Query, UseGuards, Get, Post, Headers, BadRequestException, InternalServerErrorException,- NotImplementedException, UnprocessableEntityException, PreconditionFailedException, Ip,+ NotImplementedException, UnprocessableEntityException, PreconditionFailedException, Ip, ForbiddenException,} from '@nestjs/common'import { ApiTags } from '@nestjs/swagger'import * as UAParser from 'ua-parser-js'+import * as isbot from 'isbot'import { AnalyticsService, getSessionKey } from './analytics.service'import { TaskManagerService } from '../task-manager/task-manager.service'@@ -186,6 +187,12 @@ export class AnalyticsController {@Post('/custom')async logCustom(@Body() eventsDTO: EventsDTO, @Headers() headers, @Ip() reqIP): Promise<any> {const { 'user-agent': userAgent, origin } = headers++ // todo: create a decorator for bot traffic detection+ if (isbot(userAgent)) {+ throw new ForbiddenException('Bot traffic is ignored')+ }+await this.analyticsService.validate(eventsDTO, origin)const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''@@ -228,6 +235,12 @@ export class AnalyticsController {@Post('/')async log(@Body() logDTO: PageviewsDTO, @Headers() headers, @Ip() reqIP): Promise<any> {const { 'user-agent': userAgent, origin } = headers++ // todo: create a decorator for bot traffic detection+ if (isbot(userAgent)) {+ throw new ForbiddenException('Bot traffic is ignored')+ }+await this.analyticsService.validate(logDTO, origin)const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.tsindex 5b76322e5..de4272bfd 100644--- a/src/auth/auth.controller.ts+++ b/src/auth/auth.controller.ts@@ -61,7 +61,7 @@ export class AuthController {async loginUser(@Body() userLoginDTO: UserLoginDTO, @Headers() headers, @Ip() reqIP): Promise<any> {this.logger.log({ userLoginDTO }, 'POST /auth/login')const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''- await checkRateLimit(ip, 'login', 10, 3600)+ await checkRateLimit(ip, 'login', 10, 1800)// await this.authService.checkCaptcha(userLoginDTO.recaptcha)if (isSelfhosted) {@@ -80,6 +80,11 @@ export class AuthController {async register(@Body() userDTO: SignupUserDTO, /*@Body('recaptcha') recaptcha: string,*/ @Req() request: Request, @Headers() headers, @Ip() reqIP): Promise<any> {this.logger.log({ userDTO }, 'POST /auth/register')const ip = headers['cf-connecting-ip'] || headers['x-forwarded-for'] || reqIP || ''++ if (userDTO.checkIfLeaked) {+ await this.authService.checkIfPasswordLeaked(userDTO.password)+ }+await checkRateLimit(ip, 'register', 6)// await this.authService.checkCaptcha(recaptcha)@@ -93,10 +98,6 @@ export class AuthController {throw new BadRequestException('emailRegistered')}- if (userDTO.checkIfLeaked) {- await this.authService.checkIfPasswordLeaked(userDTO.password)- }-userDTO.password = await this.authService.hashPassword(userDTO.password)try {