📈 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
fix: Require user password to delete their account
Blue Mouse4315479ecc6e
diff --git a/backend/apps/cloud/src/auth/auth.service.ts b/backend/apps/cloud/src/auth/auth.service.tsindex 2a02fc9bf..04b51e6a8 100644--- a/backend/apps/cloud/src/auth/auth.service.ts+++ b/backend/apps/cloud/src/auth/auth.service.ts@@ -309,7 +309,7 @@ export class AuthService {})}- private async comparePassword(+ public async comparePassword(password: string,hashedPassword: string,): Promise<boolean> {diff --git a/backend/apps/cloud/src/user/dto/delete-self.dto.ts b/backend/apps/cloud/src/user/dto/delete-self.dto.tsindex 674b2823e..d0d8f5b2c 100644--- a/backend/apps/cloud/src/user/dto/delete-self.dto.ts+++ b/backend/apps/cloud/src/user/dto/delete-self.dto.ts@@ -1,7 +1,15 @@import { ApiProperty } from '@nestjs/swagger'-import { IsString, IsOptional } from 'class-validator'+import { IsString, IsOptional, IsNotEmpty } from 'class-validator'export class DeleteSelfDTO {+ @ApiProperty({+ example: 'hunter2',+ required: true,+ })+ @IsString()+ @IsNotEmpty()+ password: string+@ApiProperty({example: 'I want to delete my account because ... and ...',required: false,diff --git a/backend/apps/cloud/src/user/user.controller.ts b/backend/apps/cloud/src/user/user.controller.tsindex 782d067bf..d8fa34acb 100644--- a/backend/apps/cloud/src/user/user.controller.ts+++ b/backend/apps/cloud/src/user/user.controller.ts@@ -211,13 +211,22 @@ export class UserController {const user = await this.userService.findOne({where: { id },- select: ['id', 'planCode'],+ select: ['id', 'planCode', 'password'],})if (_isEmpty(user)) {throw new BadRequestException('User not found')}+ const isPasswordValid = await this.authService.comparePassword(+ deleteSelfDTO.password,+ user.password,+ )++ if (!isPasswordValid) {+ throw new BadRequestException('incorrectPassword')+ }+if (!_includes(UNPAID_PLANS, user.planCode)) {throw new BadRequestException('cancelSubFirst')}diff --git a/backend/apps/community/src/auth/auth.service.ts b/backend/apps/community/src/auth/auth.service.tsindex aeb8479e6..7dc6123e6 100644--- a/backend/apps/community/src/auth/auth.service.ts+++ b/backend/apps/community/src/auth/auth.service.ts@@ -268,7 +268,7 @@ export class AuthService {return null}- private async comparePassword(+ public async comparePassword(password: string,hashedPassword: string,): Promise<boolean> {diff --git a/backend/apps/community/src/user/user.controller.ts b/backend/apps/community/src/user/user.controller.tsindex 0c3a9682f..64dd758fd 100644--- a/backend/apps/community/src/user/user.controller.ts+++ b/backend/apps/community/src/user/user.controller.ts@@ -147,9 +147,16 @@ export class UserController {@ApiBearerAuth()@Delete('/')@HttpCode(204)- async deleteSelf(@CurrentUserId() id: string): Promise<any> {+ async deleteSelf(+ @CurrentUserId() id: string,+ @Body() body: { password: string },+ ): Promise<any> {this.logger.log({ id }, 'DELETE /user')+ if (!body?.password) {+ throw new BadRequestException('Password is required')+ }+const user = await this.userService.findOne({id,})@@ -158,6 +165,15 @@ export class UserController {throw new BadRequestException('User not found')}+ const isPasswordValid = await this.authService.comparePassword(+ body.password,+ user.password,+ )++ if (!isPasswordValid) {+ throw new BadRequestException('incorrectPassword')+ }+const chResults = await getProjectsClickhouse(id)const projects = _map(chResults, this.projectService.formatFromClickhouse)diff --git a/web/app/pages/UserSettings/UserSettings.tsx b/web/app/pages/UserSettings/UserSettings.tsxindex 7f5193b3f..937989870 100644--- a/web/app/pages/UserSettings/UserSettings.tsx+++ b/web/app/pages/UserSettings/UserSettings.tsx@@ -412,6 +412,7 @@ const UserSettings = () => {[t],)const [deletionFeedback, setDeletionFeedback] = useState('')+ const [deletionPassword, setDeletionPassword] = useState('')const lastHandledData = useRef<UserSettingsActionData | null>(null)const passwordChangedRef = useRef(false)@@ -485,7 +486,12 @@ const UserSettings = () => {})pendingToggles.current.delete('login-notifications')}- toast.error(fetcher.data.error)+ const translated = t(`apiNotifications.${fetcher.data.error}`)+ toast.error(+ translated !== `apiNotifications.${fetcher.data.error}`+ ? translated+ : fetcher.data.error,+ )}}, [fetcher.data, fetcher.state, mergeUser, t, logout, navigate, loadUser])@@ -644,8 +650,12 @@ const UserSettings = () => {const onAccountDelete = () => {const formData = new FormData()formData.set('intent', 'delete-account')+ formData.set('password', deletionPassword)formData.set('feedback', deletionFeedback)fetcher.submit(formData, { method: 'post' })+ setTimeout(() => {+ setDeletionPassword('')+ }, 300)}const onEmailConfirm = () => {@@ -1689,6 +1699,7 @@ const UserSettings = () => {<ModalonClose={() => {setDeletionFeedback('')+ setDeletionPassword('')setShowModal(false)}}onSubmit={() => {@@ -1700,9 +1711,20 @@ const UserSettings = () => {title={t('profileSettings.qDelete')}submitType='danger'type='error'+ submitDisabled={!deletionPassword}message={<>{t('profileSettings.deactivateConfirmation')}+ <div className='mt-4'>+ <Input+ name='deletePassword'+ type='password'+ label={t('profileSettings.enterPasswordToDelete')}+ value={deletionPassword}+ placeholder={t('auth.common.password')}+ onChange={(e) => setDeletionPassword(e.target.value)}+ />+ </div>{isSelfhosted ? null : (<Textareaclasses={{diff --git a/web/app/routes/user-settings.tsx b/web/app/routes/user-settings.tsxindex c30640cc3..3ccb2d58d 100644--- a/web/app/routes/user-settings.tsx+++ b/web/app/routes/user-settings.tsx@@ -269,10 +269,18 @@ export async function action({ request }: ActionFunctionArgs) {case 'delete-account': {const feedback = formData.get('feedback')?.toString() || ''+ const password = formData.get('password')?.toString() || ''++ if (!password) {+ return data<UserSettingsActionData>(+ { intent, error: 'Password is required' },+ { status: 400 },+ )+ }const result = await serverFetch(request, 'user', {method: 'DELETE',- body: { feedback },+ body: { password, feedback },})if (result.error) {diff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex c0d8d449e..da9bbb826 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -867,6 +867,7 @@"notifications": "Notifications","notificationsDesc": "Configure when and how you receive notifications.","deactivateConfirmation": "Are you sure you want to deactivate your account?\nAll of your data will be permanently removed from our servers forever.\nThis action cannot be undone.",+ "enterPasswordToDelete": "Enter your password to confirm","deletionFeedbackLabel": "Why are you leaving? (optional)","deletionFeedback": "We're sad to see you go, could you please tell us why you're leaving so we could improve our service?","dataExport": "Data export",