Repository navigation
feat(users): ✨ GDPR account deletion and personal data export - #928
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
React Doctor found 10 new issues in 8 files · 10 warnings · score 88 / 100 (Great) · 0 fixed · vs 10 warnings
Reviewed by React Doctor for commit |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa1f151cfc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const result = await eraseAccount(c, { | ||
| deletionId, | ||
| userId: row.userId, | ||
| }); |
There was a problem hiding this comment.
Apply target-account permission checks before retrying erasure
An administrator with users.canDelete can use this endpoint to immediately erase a pending or failed request for a higher-privileged staff account, even without can_edit_admin or the target's permission ceiling. Unlike deleteUserAdminRoute, this handler never calls assertCanEditAdminTarget or rejects the caller's own account before invoking eraseAccount. A request previously scheduled by a more privileged administrator therefore provides a bypass around the direct deletion endpoint's protections. Resolve and authorize the target before changing the request or running erasure.
Useful? React with 👍 / 👎.
| let files = { deleted: 0, kept: 0 }; | ||
| try { | ||
| await revokeSessions(c, { userId }); | ||
| files = await deleteUserFiles(c, userId); | ||
|
|
||
| await db.transaction(async tx => { |
There was a problem hiding this comment.
Coordinate cancellation with the erasure worker
If a member cancels after processDueAccountDeletions selects its batch but before their account is processed, cancellation returns success, yet eraseAccount still deletes their files and account. The worker retains the selected IDs, and this update unconditionally overwrites the now-cancelled request with completed. This window also includes time spent erasing earlier accounts in the batch. Atomically claim or lock the request in coordination with cancellation, and verify it is still eligible before performing destructive side effects.
Useful? React with 👍 / 👎.
| await tx | ||
| .update(core_audit_logs) | ||
| .set({ targetLabel: null }) |
There was a problem hiding this comment.
Remove historical account names from retained audit changes
For an account whose name or handle was edited in the AdminCP, clearing targetLabel does not anonymize the retained audit entries: adminUserAuditChanges explicitly preserves name and nameCode values, and updateUserAdminRoute stores them in core_audit_logs.changes. Those old and new names remain readable and linked to the erased user ID after this handler completes. Redact the identifying fields in the retained changes as well as the label so account erasure actually stops these records from naming the member.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f458f74b15
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .where( | ||
| and( | ||
| eq(core_users_deletions.id, deletionId), | ||
| eq(core_users_deletions.status, "pending"), |
There was a problem hiding this comment.
Allow administrators to cancel failed deletion requests
Once an erasure reaches five failed attempts, this predicate makes the AdminCP's Cancel deletion action always return 404. Both UserDeleteCard and AccountDeletionActions offer cancellation for failed requests, and the underlying cancelAccountDeletion helper already accepts both pending and failed, but this preliminary lookup excludes the latter. Consequently, staff cannot cancel a failed request to restore the account's visibility without first retrying the destructive operation. Accept both open statuses here.
Useful? React with 👍 / 👎.
| erase: async ({ tx, userId }) => { | ||
| // Debug logs exist for operators, not as a record of the member. | ||
| await tx.delete(core_logs).where(eq(core_logs.userId, userId)); |
There was a problem hiding this comment.
Anonymize authors embedded in retained moderation snapshots
When the erased member authored reported content, their ID and name remain in core_moderation_reports.snapshot.authors: content/server/report-target.ts explicitly copies both into the snapshot, and deleting core_users cannot clear these JSON values. The report-detail API returns the snapshot unchanged, and report-content.tsx even falls back to that saved name when the live author no longer exists, so moderators continue seeing the erased identity after successful erasure. Redact matching snapshot authors in this core erasure handler while retaining the report's content.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f77f3ce14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await c | ||
| .get("storage") | ||
| .deleteFile(file.id, { force: true, ownerId: userId }); | ||
| deleted++; |
There was a problem hiding this comment.
Persist failed storage deletions before completing erasure
If the storage provider fails while deleting an upload, StorageModel.deleteFile removes the core_files row first and suppresses the provider's deletion error (packages/api/src/models/storage.ts:550–558). This call therefore counts the file as deleted and lets account erasure complete even though its bytes remain stored—and public uploads remain accessible at their existing URLs. Since the file row is already gone and the request is completed, subsequent erasure runs cannot discover or retry that object. Use a deletion path that durably records failed object removals and retries them rather than treating this best-effort operation as confirmed erasure.
Useful? React with 👍 / 👎.
882b581 to
035769a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 035769ac06
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }) | ||
| .where(eq(core_users_deletions.id, deletionId)); | ||
|
|
||
| await tx.delete(core_users).where(eq(core_users.id, userId)); |
There was a problem hiding this comment.
Reconcile reaction totals before cascading account deletion
When an erased member has reacted to other members' content, deleting core_users cascades to core_reactions_entries without updating core_reactions_counts or the recipients' core_users.reputation. Unlike removeReaction in lib/reactions/service.ts, this path never applies the corresponding count and reputation deltas, so retained content displays reactions that no longer exist and surviving authors keep the deleted reactions' points. The reactions cleanup cron only reconciles deleted content targets, so it does not repair this case. Remove the member's reactions and reconcile their aggregates within the erasure transaction before deleting the account.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e2831a68e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const deletion = await findOpenAccountDeletion(c, payload.u); | ||
| if (deletion?.id !== payload.d) return null; | ||
|
|
||
| if (!(await cancelAccountDeletion(c, payload.u))) return null; |
There was a problem hiding this comment.
Invalidate held sign-ins when credentials are reset
If someone obtains a password-based deletion-hold token and the account owner resets their password before that token expires, the token still cancels deletion and creates a fresh session for its holder. change-password.route.ts explicitly revokes existing sessions after a reset, and the normal password sign-in path uses revokeIfPasswordChanged to prevent authentication with stale credentials, but this release path checks only the token's expiry and deletion ID. Consequently, a holder of the old credentials can regain access for up to ten minutes after the owner's reset. Bind held authentication to revocable authentication state and verify it before cancelling the request or issuing a session.
Useful? React with 👍 / 👎.
Members download their data and delete their account from Settings → Privacy & data; staff delete accounts from the AdminCP; the Debug Panel tracks every request against GDPR's one-month limit. API (@vitnode/api) - core_users_deletions: request tombstone (pending, completed, cancelled, failed) that outlives the account; one open request per user. - definePersonalData + buildApiPlugin `personalData`: plugins export and erase their own rows; core handles its tables (logs, audit, payments). - Erasure: revoke sessions, delete files, run every plugin's erase and delete the user in one transaction, then emit user.deleted and email a goodbye. Failures are recorded and retried hourly up to five times. - Member routes: GET/POST/DELETE /me/account-deletion (password or recent sign-in), GET /me/personal-data. Profiles of accounts being deleted 404. - Admin routes: delete a user (scheduled or immediately), list, summary, retry and cancel requests; users list `deletion` filter and badge data. All need the new users:can_delete staff permission. - Roles: allowDeleteAccount (default on) gates self-deletion. - Cron: account-deletion (hourly) and ip-retention (daily). - Config: users.accountDeletion.graceDays (14, max 30) and users.ipRetentionDays (180). users.ipAddress is nullable. - Events: user.deletion.requested, user.deletion.cancelled; user.deleted is now emitted. Audit actions and scheduled/deleted emails. UI (@vitnode/core) - Settings → Privacy & data with download and a red danger zone. - DangerZone component; user page danger zone with delete (optionally immediately), cancel and retry. - Users list deletion badge and filter; role form switch. - Debug Panel: Account deletions tab (checks, needs you, all requests with a details sheet) and a Privacy requests card on the Overview. Docs: Account Deletion and Data Export, Export and Erase Plugin Data, built-in events. EN and PL locales. Deletion hold (sign-in during the grace period) - AccountDeletionHold: signing in to an account pending deletion shows a countdown instead of a session; the member can cancel the deletion with a signed token (zod-validated) and continue, or leave it scheduled. - requestAccountDeletion returns scheduledAt; SSO callbacks report a deletion_pending state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b3713fc to
0171318
Compare
| let kept = 0; | ||
| for (const file of files) { | ||
| try { | ||
| await c |
There was a problem hiding this comment.
React Doctor · react-doctor/async-await-in-loop (warning)
This for…of loop waits before starting the next iteration. If iterations perform independent asynchronous work, consider bounded concurrency; await syntax alone does not establish a speedup.
Fix → Consider concurrent calls only for independent asynchronous work. Shared queues or synchronous work may not benefit. Preserve resource limits, transaction ordering, and failure/cancellation semantics; observe all callback promises.
|
|
||
| await db.transaction(async tx => { | ||
| for (const entry of c.get("core").personalData) { | ||
| await entry.erase?.({ c, tx, userId }); |
There was a problem hiding this comment.
React Doctor · react-doctor/async-await-in-loop (warning)
This for…of loop waits before starting the next iteration. If iterations perform independent asynchronous work, consider bounded concurrency; await syntax alone does not establish a speedup.
Fix → Consider concurrent calls only for independent asynchronous work. Shared queues or synchronous work may not benefit. Preserve resource limits, transaction ordering, and failure/cancellation semantics; observe all callback promises.
|
|
||
| const cutoff = new Date(now.getTime() - retentionDays * 86_400_000); | ||
|
|
||
| const logs = await inBatches(async () => { |
There was a problem hiding this comment.
React Doctor · react-doctor/async-parallel (warning)
These 3 sequential await statements run one after another even though they look independent, so the page waits longer than it needs to. Run them together with Promise.all() instead
Fix → Use const [a, b] = await Promise.all([fetchA(), fetchB()]) so independent calls run at the same time
| return rows.length; | ||
| }); | ||
|
|
||
| const activityLogs = await inBatches(async () => { |
There was a problem hiding this comment.
React Doctor · react-doctor/server-sequential-independent-await (warning)
This awaited initializer does not read the previous result. If the operations are independent asynchronous work, they may overlap; await syntax alone does not establish a speedup.
Fix → Consider Promise.all([...]) only for independent asynchronous work. Shared queues or synchronous work may not benefit. Preserve resource limits, transaction ordering, and failure/cancellation semantics.
| known: readonly T[], | ||
| ): T[] => | ||
| (raw?.split(",") ?? []).filter((value): value is T => | ||
| (known as readonly string[]).includes(value), |
There was a problem hiding this comment.
React Doctor · react-doctor/js-set-map-lookups (warning)
This scales poorly because array.includes() inside a loop scans the whole list every time. Use a Set for constant-time lookups.
Fix → Use a Set or Map when you check for the same items over and over. Array.includes/find scans the whole list each time
| const plugins: Record<string, Record<string, unknown>> = {}; | ||
| for (const entry of c.get("core").personalData) { | ||
| if (!entry.export) continue; | ||
| plugins[entry.pluginId] = await entry.export({ c, userId: user.id }); |
There was a problem hiding this comment.
React Doctor · react-doctor/async-await-in-loop (warning)
This for…of loop waits before starting the next iteration. If iterations perform independent asynchronous work, consider bounded concurrency; await syntax alone does not establish a speedup.
Fix → Consider concurrent calls only for independent asynchronous work. Shared queues or synchronous work may not benefit. Preserve resource limits, transaction ordering, and failure/cancellation semantics; observe all callback promises.
| return ( | ||
| <Frame render={<section aria-labelledby="privacy-requests-title" />}> | ||
| <FrameHeader> | ||
| <FrameTitle id="privacy-requests-title" render={<h2 />}> |
There was a problem hiding this comment.
React Doctor · react-doctor/heading-has-content (warning)
Blind users can't use this heading to navigate because screen readers skip it empty, so add text, aria-label, or aria-labelledby.
Fix → Put readable text in every heading.
| <FrameTitle | ||
| className="flex items-center gap-2" | ||
| id="deletions-attention-title" | ||
| render={<h3 />} |
There was a problem hiding this comment.
React Doctor · react-doctor/heading-has-content (warning)
Blind users can't use this heading to navigate because screen readers skip it empty, so add text, aria-label, or aria-labelledby.
Fix → Put readable text in every heading.
| ]; | ||
|
|
||
| const matchesKinds = (device: AdminUserDevice, kinds: SessionKind[]) => | ||
| kinds.length === 0 || kinds.some(kind => device.sessionKinds.includes(kind)); |
There was a problem hiding this comment.
React Doctor · react-doctor/js-set-map-lookups (warning)
This scales poorly because array.includes() inside a loop scans the whole list every time. Use a Set for constant-time lookups.
Fix → Use a Set or Map when you check for the same items over and over. Array.includes/find scans the whole list each time
| <FrameTitle | ||
| className="flex items-center gap-2" | ||
| id={titleId} | ||
| render={<h2 />} |
There was a problem hiding this comment.
React Doctor · react-doctor/heading-has-content (warning)
Blind users can't use this heading to navigate because screen readers skip it empty, so add text, aria-label, or aria-labelledby.
Fix → Put readable text in every heading.
your account (password or recent sign-in, grace period, cancel anytime)
definePersonalData/personalDataonbuildApiPluginso pluginsexport and erase their own rows; core handles its tables
erase and deletes the account in one transaction, emits
user.deletedaccount-deletioncron with retries; failures recorded on therequest
Users → Account deletions list with retry/cancel,
users:can_deletecore_users_deletionskeeps a tombstone of each request as proofip-retentioncron (users.ipRetentionDays, default 180)user.deletion.requested/user.deletion.cancelled;user.deletedis now emittedCo-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01CnAiFYkyMmyrtbd7GB46gY