Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PrismaService } from '@teable/db-main-prisma';
import { EmailVerifyCodeType, MailTransporterType, MailType } from '@teable/openapi';
import type { IChangePasswordRo, IInviteWaitlistVo, ISignup } from '@teable/openapi';
import * as bcrypt from 'bcrypt';
import { timingSafeEqual } from 'crypto';
import { isEmpty } from 'lodash';
import ms from 'ms';
import { ClsService } from 'nestjs-cls';
Expand Down Expand Up @@ -62,7 +63,14 @@ export class LocalAuthService {
salt: string | null
) {
const _hashPassword = await bcrypt.hash(password || '', salt || '');
return _hashPassword === hashPassword;
if (!_hashPassword || !hashPassword) {
return false;
}
try {
return timingSafeEqual(Buffer.from(_hashPassword), Buffer.from(hashPassword));
} catch {
return false;
}
}

private async getUserByIdOrThrow(userId: string) {
Expand Down
10 changes: 9 additions & 1 deletion apps/nestjs-backend/src/features/auth/permission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@teable/core';
import { PrismaService } from '@teable/db-main-prisma';
import { CollaboratorType } from '@teable/openapi';
import { timingSafeEqual } from 'crypto';
import { intersection, union } from 'lodash';
import { ClsService } from 'nestjs-cls';
import { CustomHttpException, TemplateAppTokenNotAllowedException } from '../../custom.exception';
Expand Down Expand Up @@ -580,7 +581,14 @@ export class PermissionService {
if (!baseShare?.password) {
return false;
}
return payload.password === baseShare.password;
try {
return timingSafeEqual(
Buffer.from(payload.password),
Buffer.from(baseShare.password)
);
} catch {
return false;
}
} catch {
return false;
}
Expand Down