📈 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
Migrate otplib to v13
Blue Mouseb7acb7aa772f
diff --git a/backend/apps/cloud/src/auth/auth.service.ts b/backend/apps/cloud/src/auth/auth.service.tsindex d689dfdf6..53666aa3b 100644--- a/backend/apps/cloud/src/auth/auth.service.ts+++ b/backend/apps/cloud/src/auth/auth.service.ts@@ -1167,7 +1167,7 @@ export class AuthService {!!user.twoFactorRecoveryCode &&user.twoFactorRecoveryCode === twoFactorAuthenticationCodeconst isTotpValid =- this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(+ await this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode,user,)diff --git a/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.ts b/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.tsindex a1f6b4378..9c596f846 100644--- a/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.ts+++ b/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.ts@@ -93,7 +93,7 @@ export class TwoFactorAuthController {}const isCodeValid =- this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(+ await this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode,user,)@@ -148,7 +148,7 @@ export class TwoFactorAuthController {!!user.twoFactorRecoveryCode &&user.twoFactorRecoveryCode === twoFactorAuthenticationCodeconst isTotpValid =- this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(+ await this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode,user,)@@ -199,7 +199,7 @@ export class TwoFactorAuthController {!!user.twoFactorRecoveryCode &&user.twoFactorRecoveryCode === twoFactorAuthenticationCodeconst isTotpValid =- this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(+ await this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode,user,)diff --git a/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.service.ts b/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.service.tsindex b0fe29560..12342dcdc 100644--- a/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.service.ts+++ b/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common'-import { authenticator } from 'otplib'+import { generateSecret, generateURI, verify } from 'otplib'import { UserService } from '../user/user.service'import { User } from '../user/entities/user.entity'@@ -10,12 +10,12 @@ export class TwoFactorAuthService {constructor(private userService: UserService) {}async generateTwoFactorAuthenticationSecret(user: User) {- const secret = authenticator.generateSecret()- const otpauthUrl = authenticator.keyuri(- user.email,- TWO_FACTOR_AUTHENTICATION_APP_NAME,+ const secret = generateSecret()+ const otpauthUrl = generateURI({+ issuer: TWO_FACTOR_AUTHENTICATION_APP_NAME,+ label: user.email,secret,- )+ })await this.userService.update(user.id, {twoFactorAuthenticationSecret: secret,@@ -27,16 +27,18 @@ export class TwoFactorAuthService {}}- isTwoFactorAuthenticationCodeValid(+ async isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode: string,user: User,) {if (!twoFactorAuthenticationCode) return falseif (!user?.twoFactorAuthenticationSecret) return false- return authenticator.verify({+ const result = await verify({token: twoFactorAuthenticationCode,secret: user.twoFactorAuthenticationSecret,})++ return result.valid}}diff --git a/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.ts b/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.tsindex 763fcb029..985603f18 100644--- a/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.ts+++ b/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.ts@@ -91,7 +91,7 @@ export class TwoFactorAuthController {}const isCodeValid =- this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(+ await this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode,user,)@@ -144,7 +144,7 @@ export class TwoFactorAuthController {!!user.twoFactorRecoveryCode &&user.twoFactorRecoveryCode === twoFactorAuthenticationCodeconst isTotpValid =- this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(+ await this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode,user,)@@ -195,7 +195,7 @@ export class TwoFactorAuthController {!!user.twoFactorRecoveryCode &&user.twoFactorRecoveryCode === twoFactorAuthenticationCodeconst isTotpValid =- this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(+ await this.twoFactorAuthService.isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode,user,)diff --git a/backend/apps/community/src/twoFactorAuth/twoFactorAuth.service.ts b/backend/apps/community/src/twoFactorAuth/twoFactorAuth.service.tsindex d73fc5e8a..4d9533571 100644--- a/backend/apps/community/src/twoFactorAuth/twoFactorAuth.service.ts+++ b/backend/apps/community/src/twoFactorAuth/twoFactorAuth.service.ts@@ -1,5 +1,5 @@import { Injectable } from '@nestjs/common'-import { authenticator } from 'otplib'+import { generateSecret, generateURI, verify } from 'otplib'import { UserService } from '../user/user.service'import { User } from '../common/types'@@ -10,12 +10,12 @@ export class TwoFactorAuthService {constructor(private userService: UserService) {}async generateTwoFactorAuthenticationSecret(user: User) {- const secret = authenticator.generateSecret()- const otpauthUrl = authenticator.keyuri(- user.email,- TWO_FACTOR_AUTHENTICATION_APP_NAME,+ const secret = generateSecret()+ const otpauthUrl = generateURI({+ issuer: TWO_FACTOR_AUTHENTICATION_APP_NAME,+ label: user.email,secret,- )+ })await this.userService.update(user.id, {twoFactorAuthenticationSecret: secret,@@ -27,16 +27,18 @@ export class TwoFactorAuthService {}}- isTwoFactorAuthenticationCodeValid(+ async isTwoFactorAuthenticationCodeValid(twoFactorAuthenticationCode: string,user: User,) {if (!twoFactorAuthenticationCode) return falseif (!user?.twoFactorAuthenticationSecret) return false- return authenticator.verify({+ const result = await verify({token: twoFactorAuthenticationCode,secret: user.twoFactorAuthenticationSecret,})++ return result.valid}}diff --git a/backend/package-lock.json b/backend/package-lock.jsonindex fdefaae2e..fedbaef1f 100644--- a/backend/package-lock.json+++ b/backend/package-lock.json@@ -4,7 +4,6 @@"requires": true,"packages": {"": {- "name": "backend","license": "AGPL-3.0","dependencies": {"@ai-sdk/openai": "^3.0.39",@@ -60,7 +59,7 @@"nestjs-i18n": "^10.6.0","nestjs-telegraf": "^2.9.1","nodemailer": "^8.0.1",- "otplib": "^12.0.1",+ "otplib": "^13.3.0","passport": "^0.7.0","passport-headerapikey": "^1.2.2","passport-jwt": "^4.0.1",@@ -1869,6 +1868,18 @@}}},+ "node_modules/@noble/hashes": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.0.1.tgz",+ "integrity": "sha512-XlOlEbQcE9fmuXxrVTXCTlG2nlRXa9Rj3rr5Ue/+tX+nmkgbX720YHh0VR3hBF9xDvwnb8D2shVGOwNx+ulArw==",+ "license": "MIT",+ "engines": {+ "node": ">= 20.19.0"+ },+ "funding": {+ "url": "https://paulmillr.com/funding/"+ }+ },"node_modules/@nodelib/fs.scandir": {"version": "2.1.5","resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",@@ -2460,50 +2471,59 @@}},"node_modules/@otplib/core": {- "version": "12.0.1",- "resolved": "https://registry.npmjs.org/@otplib/core/-/core-12.0.1.tgz",- "integrity": "sha512-4sGntwbA/AC+SbPhbsziRiD+jNDdIzsZ3JUyfZwjtKyc/wufl1pnSIaG4Uqx8ymPagujub0o92kgBnB89cuAMA==",+ "version": "13.3.0",+ "resolved": "https://registry.npmjs.org/@otplib/core/-/core-13.3.0.tgz",+ "integrity": "sha512-pnQDOuCmFVeF/XnboJq9TOJgLoo2idNPJKMymOF8vGqJJ+ReKRYM9bUGjNPRWC0tHjMwu1TXbnzyBp494JgRag==","license": "MIT"},- "node_modules/@otplib/plugin-crypto": {- "version": "12.0.1",- "resolved": "https://registry.npmjs.org/@otplib/plugin-crypto/-/plugin-crypto-12.0.1.tgz",- "integrity": "sha512-qPuhN3QrT7ZZLcLCyKOSNhuijUi9G5guMRVrxq63r9YNOxxQjPm59gVxLM+7xGnHnM6cimY57tuKsjK7y9LM1g==",+ "node_modules/@otplib/hotp": {+ "version": "13.3.0",+ "resolved": "https://registry.npmjs.org/@otplib/hotp/-/hotp-13.3.0.tgz",+ "integrity": "sha512-XJMZGz2bg4QJwK7ulvl1GUI2VMn/flaIk/E/BTKAejHsX2kUtPF1bRhlZ2+elq8uU5Fs9Z9FHcQK2CPZNQbbUQ==",+ "license": "MIT",+ "dependencies": {+ "@otplib/core": "13.3.0",+ "@otplib/uri": "13.3.0"+ }+ },+ "node_modules/@otplib/plugin-base32-scure": {+ "version": "13.3.0",+ "resolved": "https://registry.npmjs.org/@otplib/plugin-base32-scure/-/plugin-base32-scure-13.3.0.tgz",+ "integrity": "sha512-/jYbL5S6GB0Ie3XGEWtLIr9s5ZICl/BfmNL7+8/W7usZaUU4GiyLd2S+JGsNCslPyqNekSudD864nDAvRI0s8w==","license": "MIT","dependencies": {- "@otplib/core": "^12.0.1"+ "@otplib/core": "13.3.0",+ "@scure/base": "^2.0.0"}},- "node_modules/@otplib/plugin-thirty-two": {- "version": "12.0.1",- "resolved": "https://registry.npmjs.org/@otplib/plugin-thirty-two/-/plugin-thirty-two-12.0.1.tgz",- "integrity": "sha512-MtT+uqRso909UkbrrYpJ6XFjj9D+x2Py7KjTO9JDPhL0bJUYVu5kFP4TFZW4NFAywrAtFRxOVY261u0qwb93gA==",+ "node_modules/@otplib/plugin-crypto-noble": {+ "version": "13.3.0",+ "resolved": "https://registry.npmjs.org/@otplib/plugin-crypto-noble/-/plugin-crypto-noble-13.3.0.tgz",+ "integrity": "sha512-wmV+jBVncepgwv99G7Plrdzd0tHfbpXk2U+OD7MO7DzpDqOYEgOPi+IIneksJSTL8QvWdfi+uQEuhnER4fKouA==","license": "MIT","dependencies": {- "@otplib/core": "^12.0.1",- "thirty-two": "^1.0.2"+ "@noble/hashes": "^2.0.1",+ "@otplib/core": "13.3.0"}},- "node_modules/@otplib/preset-default": {- "version": "12.0.1",- "resolved": "https://registry.npmjs.org/@otplib/preset-default/-/preset-default-12.0.1.tgz",- "integrity": "sha512-xf1v9oOJRyXfluBhMdpOkr+bsE+Irt+0D5uHtvg6x1eosfmHCsCC6ej/m7FXiWqdo0+ZUI6xSKDhJwc8yfiOPQ==",+ "node_modules/@otplib/totp": {+ "version": "13.3.0",+ "resolved": "https://registry.npmjs.org/@otplib/totp/-/totp-13.3.0.tgz",+ "integrity": "sha512-XfjGNoN8d9S3Ove2j7AwkVV7+QDFsV7Lm7YwSiezNaHffkWtJ60aJYpmf+01dARdPST71U2ptueMsRJso4sq4A==","license": "MIT","dependencies": {- "@otplib/core": "^12.0.1",- "@otplib/plugin-crypto": "^12.0.1",- "@otplib/plugin-thirty-two": "^12.0.1"+ "@otplib/core": "13.3.0",+ "@otplib/hotp": "13.3.0",+ "@otplib/uri": "13.3.0"}},- "node_modules/@otplib/preset-v11": {- "version": "12.0.1",- "resolved": "https://registry.npmjs.org/@otplib/preset-v11/-/preset-v11-12.0.1.tgz",- "integrity": "sha512-9hSetMI7ECqbFiKICrNa4w70deTUfArtwXykPUvSHWOdzOlfa9ajglu7mNCntlvxycTiOAXkQGwjQCzzDEMRMg==",+ "node_modules/@otplib/uri": {+ "version": "13.3.0",+ "resolved": "https://registry.npmjs.org/@otplib/uri/-/uri-13.3.0.tgz",+ "integrity": "sha512-3oh6nBXy+cm3UX9cxEAGZiDrfxHU2gfelYFV+XNCx+8dq39VaQVymwlU2yjPZiMAi/3agaUeEftf2RwM5F+Cyg==","license": "MIT","dependencies": {- "@otplib/core": "^12.0.1",- "@otplib/plugin-crypto": "^12.0.1",- "@otplib/plugin-thirty-two": "^12.0.1"+ "@otplib/core": "13.3.0"}},"node_modules/@oxc-resolver/binding-android-arm-eabi": {@@ -3493,6 +3513,15 @@"hasInstallScript": true,"license": "Apache-2.0"},+ "node_modules/@scure/base": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/@scure/base/-/base-2.0.0.tgz",+ "integrity": "sha512-3E1kpuZginKkek01ovG8krQ0Z44E3DHPjc5S2rjJw9lZn3KSQOs8S7wqikF/AH7iRanHypj85uGyxk0XAyC37w==",+ "license": "MIT",+ "funding": {+ "url": "https://paulmillr.com/funding/"+ }+ },"node_modules/@selderee/plugin-htmlparser2": {"version": "0.11.0","resolved": "https://registry.npmjs.org/@selderee/plugin-htmlparser2/-/plugin-htmlparser2-0.11.0.tgz",@@ -10204,14 +10233,17 @@}},"node_modules/otplib": {- "version": "12.0.1",- "resolved": "https://registry.npmjs.org/otplib/-/otplib-12.0.1.tgz",- "integrity": "sha512-xDGvUOQjop7RDgxTQ+o4pOol0/3xSZzawTiPKRrHnQWAy0WjhNs/5HdIDJCrqC4MBynmjXgULc6YfioaxZeFgg==",+ "version": "13.3.0",+ "resolved": "https://registry.npmjs.org/otplib/-/otplib-13.3.0.tgz",+ "integrity": "sha512-VYMKyyDG8yt2q+z58sz54/EIyTh7+tyMrjeemR44iVh5+dkKtIs57irTqxjH+IkAL1uMmG1JIFhG5CxTpqdU5g==","license": "MIT","dependencies": {- "@otplib/core": "^12.0.1",- "@otplib/preset-default": "^12.0.1",- "@otplib/preset-v11": "^12.0.1"+ "@otplib/core": "13.3.0",+ "@otplib/hotp": "13.3.0",+ "@otplib/plugin-base32-scure": "13.3.0",+ "@otplib/plugin-crypto-noble": "13.3.0",+ "@otplib/totp": "13.3.0",+ "@otplib/uri": "13.3.0"}},"node_modules/oxc-resolver": {@@ -12356,14 +12388,6 @@"dev": true,"license": "MIT"},- "node_modules/thirty-two": {- "version": "1.0.2",- "resolved": "https://registry.npmjs.org/thirty-two/-/thirty-two-1.0.2.tgz",- "integrity": "sha512-OEI0IWCe+Dw46019YLl6V10Us5bi574EvlJEOcAkB29IzQ/mYD1A6RyNHLjZPiHCmuodxvgF6U+vZO1L15lxVA==",- "engines": {- "node": ">=0.2.6"- }- },"node_modules/tiny-lru": {"version": "11.4.7","resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-11.4.7.tgz",diff --git a/backend/package.json b/backend/package.jsonindex 862d8573e..a6494b71f 100644--- a/backend/package.json+++ b/backend/package.json@@ -80,7 +80,7 @@"nestjs-i18n": "^10.6.0","nestjs-telegraf": "^2.9.1","nodemailer": "^8.0.1",- "otplib": "^12.0.1",+ "otplib": "^13.3.0","passport": "^0.7.0","passport-headerapikey": "^1.2.2","passport-jwt": "^4.0.1",