Skip to content

Commit c17dd1f

Browse files
authored
Fix use case-insensitive email lookup and comparison during login (#5145)
fix: use case-insensitive email lookup and comparison
1 parent 42fed57 commit c17dd1f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

packages/server/src/enterprise/services/account.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export class AccountService {
176176
if (data.user.tempToken) {
177177
const user = await this.userService.readUserByToken(data.user.tempToken, queryRunner)
178178
if (!user) throw new InternalFlowiseError(StatusCodes.NOT_FOUND, UserErrorMessage.USER_NOT_FOUND)
179-
if (user.email !== data.user.email)
179+
if (user.email.toLowerCase() !== data.user.email?.toLowerCase())
180180
throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, UserErrorMessage.INVALID_USER_EMAIL)
181181
const name = data.user.name
182182
if (data.user.credential) user.credential = this.userService.encryptUserCredential(data.user.credential)

packages/server/src/enterprise/services/user.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
55
import { Telemetry, TelemetryEventType } from '../../utils/telemetry'
66
import { User, UserStatus } from '../database/entities/user.entity'
77
import { isInvalidEmail, isInvalidName, isInvalidPassword, isInvalidUUID } from '../utils/validation.util'
8-
import { DataSource, QueryRunner } from 'typeorm'
8+
import { DataSource, ILike, QueryRunner } from 'typeorm'
99
import { generateId } from '../../utils'
1010
import { GeneralErrorMessage } from '../../utils/constants'
1111
import { getHash } from '../utils/encryption.util'
@@ -54,8 +54,9 @@ export class UserService {
5454
}
5555

5656
public async readUserByEmail(email: string | undefined, queryRunner: QueryRunner) {
57+
if (!email) throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, UserErrorMessage.INVALID_USER_EMAIL)
5758
this.validateUserEmail(email)
58-
return await queryRunner.manager.findOneBy(User, { email })
59+
return await queryRunner.manager.findOneBy(User, { email: ILike(email) })
5960
}
6061

6162
public async readUserByToken(token: string | undefined, queryRunner: QueryRunner) {

0 commit comments

Comments
 (0)