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 browser version detection & properly use supplied client hints

Blue Mouse4eaea0f70d97
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.ts
index 3f27d743a..f25825d5f 100644
--- a/backend/apps/cloud/src/analytics/analytics.service.ts
+++ b/backend/apps/cloud/src/analytics/analytics.service.ts
@@ -2758,7 +2758,11 @@ export class AnalyticsService {
}
async getRequestInformation(headers: any) {
- const ua = await UAParser(headers, extensions).withClientHints()
+ const ua = await UAParser(
+ headers?.['user-agent'],
+ extensions,
+ headers,
+ ).withClientHints()
return {
deviceType: ua.device.type || 'desktop',
diff --git a/backend/apps/cloud/src/auth/auth.controller.ts b/backend/apps/cloud/src/auth/auth.controller.ts
index 33b53ac79..955d3d731 100644
--- a/backend/apps/cloud/src/auth/auth.controller.ts
+++ b/backend/apps/cloud/src/auth/auth.controller.ts
@@ -85,7 +85,7 @@ export class AuthController {
public async register(
@Body() body: RegisterRequestDto,
@I18n() i18n: I18nContext,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() requestIp: string,
) {
const ip = getIPFromHeaders(headers) || requestIp || ''
@@ -138,7 +138,7 @@ export class AuthController {
public async login(
@Body() body: LoginRequestDto,
@I18n() i18n: I18nContext,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() requestIp: string,
): Promise<LoginResponseDto> {
const ip = getIPFromHeaders(headers) || requestIp || ''
@@ -213,7 +213,7 @@ export class AuthController {
public async requestResetPassword(
@Body() body: RequestResetPasswordDto,
@I18n() i18n: I18nContext,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() requestIp: string,
): Promise<void> {
const ip = getIPFromHeaders(headers) || requestIp || ''
@@ -464,7 +464,7 @@ export class AuthController {
@Public()
async generateAuthURL(
@Body() body: SSOGenerateDto,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() reqIP: string,
): Promise<any> {
const ip = getIPFromHeaders(headers) || reqIP || ''
@@ -489,7 +489,7 @@ export class AuthController {
@Public()
async processSSOToken(
@Body() body: ProcessSSOCodeDto,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() reqIP: string,
): Promise<any> {
const ip = getIPFromHeaders(headers) || reqIP || ''
@@ -507,7 +507,7 @@ export class AuthController {
// Validates the authorisation code and returns the JWT tokens
async getJWTByHash(
@Body() body: SSOGetJWTByHashDto,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() reqIP: string,
): Promise<any> {
const ip = getIPFromHeaders(headers) || reqIP || ''
diff --git a/backend/apps/cloud/src/auth/auth.service.ts b/backend/apps/cloud/src/auth/auth.service.ts
index c5567362d..0331a0e59 100644
--- a/backend/apps/cloud/src/auth/auth.service.ts
+++ b/backend/apps/cloud/src/auth/auth.service.ts
@@ -221,7 +221,7 @@ export class AuthService {
public async sendTelegramNotification(
userId: string,
- headers: unknown,
+ headers: Record<string, string>,
ip: string,
) {
const user = await this.userService.findUserById(userId)
@@ -248,8 +248,12 @@ export class AuthService {
}
}
- private async getHeadersInfo(headers: unknown, ip: string) {
- const ua = await UAParser(headers).withClientHints()
+ private async getHeadersInfo(headers: Record<string, string>, ip: string) {
+ const ua = await UAParser(
+ headers?.['user-agent'],
+ undefined,
+ headers,
+ ).withClientHints()
const browser = ua.browser.name || 'Unknown'
const device = ua.device.type || 'Desktop'
const os = ua.os.name || 'Unknown'
@@ -478,7 +482,11 @@ export class AuthService {
Google SSO section
--------------------------------
*/
- async handleExistingUserGoogle(user: User, headers: unknown, ip: string) {
+ async handleExistingUserGoogle(
+ user: User,
+ headers: Record<string, string>,
+ ip: string,
+ ) {
if (!user.googleId) {
throw new BadRequestException()
}
@@ -623,7 +631,7 @@ export class AuthService {
async authenticateSSO(
ssoHash: string,
- headers: unknown,
+ headers: Record<string, string>,
ip: string,
provider: SSOProviders,
refCode?: string,
@@ -641,7 +649,7 @@ export class AuthService {
async authenticateGoogle(
ssoHash: string,
- headers: unknown,
+ headers: Record<string, string>,
ip: string,
refCode?: string,
) {
@@ -945,7 +953,11 @@ export class AuthService {
}
}
- async handleExistingUserGithub(user: User, headers: unknown, ip: string) {
+ async handleExistingUserGithub(
+ user: User,
+ headers: Record<string, string>,
+ ip: string,
+ ) {
if (!user.githubId) {
throw new BadRequestException()
}
@@ -1032,7 +1044,7 @@ export class AuthService {
async authenticateGithub(
ssoHash: string,
- headers: unknown,
+ headers: Record<string, string>,
ip: string,
refCode?: string,
) {
diff --git a/backend/apps/cloud/src/captcha/captcha.service.ts b/backend/apps/cloud/src/captcha/captcha.service.ts
index 85ee38c22..040ddcdd3 100644
--- a/backend/apps/cloud/src/captcha/captcha.service.ts
+++ b/backend/apps/cloud/src/captcha/captcha.service.ts
@@ -100,11 +100,15 @@ export class CaptchaService {
async logCaptchaPass(
pid: string,
- headers: string,
+ headers: Record<string, string>,
timestamp: number,
ip: string,
) {
- const ua = await UAParser(headers).withClientHints()
+ const ua = await UAParser(
+ headers?.['user-agent'],
+ undefined,
+ headers,
+ ).withClientHints()
const deviceType = ua.device.type || 'desktop'
const browserName = ua.browser.name
const osName = ua.os.name
diff --git a/backend/apps/community/src/analytics/analytics.service.ts b/backend/apps/community/src/analytics/analytics.service.ts
index 99d56ebd8..499868fca 100644
--- a/backend/apps/community/src/analytics/analytics.service.ts
+++ b/backend/apps/community/src/analytics/analytics.service.ts
@@ -2566,7 +2566,11 @@ export class AnalyticsService {
}
async getRequestInformation(headers: any) {
- const ua = await UAParser(headers, extensions).withClientHints()
+ const ua = await UAParser(
+ headers?.['user-agent'],
+ extensions,
+ headers,
+ ).withClientHints()
return {
deviceType: ua.device.type || 'desktop',
diff --git a/backend/apps/community/src/auth/auth.controller.ts b/backend/apps/community/src/auth/auth.controller.ts
index d7f623feb..3d4f33762 100644
--- a/backend/apps/community/src/auth/auth.controller.ts
+++ b/backend/apps/community/src/auth/auth.controller.ts
@@ -59,7 +59,7 @@ export class AuthController {
public async login(
@Body() body: LoginRequestDto,
@I18n() i18n: I18nContext,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() reqIP: string,
): Promise<LoginResponseDto> {
// If OIDC-only mode is enabled, disable traditional login
@@ -161,7 +161,7 @@ export class AuthController {
@HttpCode(HttpStatus.OK)
async initiateOidc(
@Body() body: OIDCInitiateDto,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() reqIP: string,
) {
if (!OIDC_ENABLED) {
@@ -183,7 +183,7 @@ export class AuthController {
@HttpCode(HttpStatus.CREATED)
async oidcProcessToken(
@Body() body: OIDCProcessTokenDto,
- @Headers() headers: unknown,
+ @Headers() headers: Record<string, string>,
@Ip() reqIP: string,
@Res() res: Response,
) {