Skip to content

fix(account): delete identities and targets when deleting own account - #14208

Merged
HarshMN2345 merged 5 commits into
mainfrom
fix/account-delete-identities
Oct 8, 2026
Merged

HarshMN2345 merged 5 commits into
mainfrom
fix/account-delete-identities

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

DELETE /v1/account deleted the user document and left identities, targets and sessions to the deletes worker. Until the worker ran, signing up again with the same email hit the identity email check in POST /v1/account and returned a generic general_bad_request.

This deletes the account's key rows (user, identities, targets, sessions) in one transaction, then queues the deletes job for everything else. A failure rolls back to an intact account that can be deleted again. The bulk deletes skip authorization, the same as the worker. The error stays generic on purpose (enumeration protection).

Closes #8135

Test Plan

New e2e testCreateAccountAfterOAuth2AccountDelete: OAuth sign-in with the mock provider → DELETE /v1/account → immediate POST /v1/account with the same email returns 201. It fails with 400 on the code before this PR.

Manual runs on a local stack, each one OAuth sign-in, self-delete, then an immediate signup with the same email:

Re-signup Email targets after worker
Before 400 general_bad_request ×5 n/a
After 201 ×8 1 ×8

Related PRs and Issues

DELETE /v1/account left identity and target cleanup to the deletes
worker. Signing up again with the same email before the worker ran hit
the identity email check in POST /v1/account and returned
general_bad_request. Delete them synchronously, as DELETE
/v1/users/:userId already does. The session has no delete permission
over every row, so the deletes skip authorization like the worker.
@luxor-code-review

luxor-code-review Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR extends account self-deletion so that the caller's OAuth identities and messaging targets are removed inline along with the user document, instead of relying solely on the async Deletes worker's later sweep. It imports the existing DeleteIdentities and DeleteTargets helpers and runs them inside an $authorization->skip() block scoped to the deleted user's internal id, matching the pattern already used by admin user deletion.

Files Change
app/controllers/api/account.php On account delete, cascade-delete the user's identities and targets via DeleteIdentities/DeleteTargets before enqueuing the async DeleteMessage.

One caveat noted during review but below the reporting threshold: the user document is deleted before the inline cascade, so a mid-batch cascade failure (e.g. the defensive throw in DeleteTargets for an unexpected providerType, or a transient DB error) would leave the async Deletes worker unenqueued and some rows orphaned — the same ordering already exists in src/Appwrite/Platform/Modules/Users/Http/Users/Delete.php, so this replicates an established pattern rather than introducing a new one. A try/finally around the cascade that always enqueues the DeleteMessage would harden both paths.

Reviewed commit: 837aa2f

@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The existing testing finding is partially addressed, but the regression still does not check that the recreated account owns its email target.

Account deletion now synchronously removes the user, OAuth identities, messaging targets, and sessions in an authorization-skipped transaction before queuing the remaining cleanup. A new E2E test uses a fresh project to cover mock OAuth sign-in, self-deletion, and immediate signup with the same email.

Latest changes: The newest commits make synchronous cleanup transactional, include session deletion, and add the immediate same-email signup E2E regression.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
Fix with agent prompt
### Issue 1
app/controllers/api/account.php:574-575
**Add an E2E regression for immediate signup after OAuth account deletion**

The existing `AccountBase::testDeleteAccount` only checks the 204 response, so it still passes without this fix; the repository already has mock-provider OAuth E2E coverage. Please add the OAuth sign-in → self-delete → immediate same-email signup regression required by AGENTS.md's HTTP contract testing rule, including checking that the new account owns its email target.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 2
File Change
app/controllers/api/account.php Import cleanup helpers and transactionally delete the account, identities, targets, and sessions before enqueueing remaining cleanup.
tests/e2e/Services/Account/AccountCustomClientTest.php Add a fresh-project mock OAuth regression for immediate same-email signup after self-deletion.
⏳ Still open from earlier reviews · 1

Reviewed the commits since 59b465a · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

Comment thread app/controllers/api/account.php Resolved
Comment on lines +574 to +575
DeleteIdentities::delete($dbForProject, Query::equal('userInternalId', [$targetUser->getSequence()]));
DeleteTargets::delete($dbForProject, Query::equal('userInternalId', [$targetUser->getSequence()]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an E2E regression for immediate signup after OAuth account deletion

The existing AccountBase::testDeleteAccount only checks the 204 response, so it still passes without this fix; the repository already has mock-provider OAuth E2E coverage. Please add the OAuth sign-in → self-delete → immediate same-email signup regression required by AGENTS.md's HTTP contract testing rule, including checking that the new account owns its email target.

Prompt To Fix With AI
This is a comment left during a code review.
Path: app/controllers/api/account.php
Line: 574-575

Comment:
**Add an E2E regression for immediate signup after OAuth account deletion**

The existing `AccountBase::testDeleteAccount` only checks the 204 response, so it still passes without this fix; the repository already has mock-provider OAuth E2E coverage. Please add the OAuth sign-in → self-delete → immediate same-email signup regression required by AGENTS.md's HTTP contract testing rule, including checking that the new account owns its email target.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

If deleting identities or targets throws after the user document is
gone, the request never reached the enqueue, leaving sessions, tokens
and memberships without a cleanup job. Queue the job first; the worker
deleting rows the request already removed is a no-op.
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/account-delete-identities (after).

Metric Before After Change
🚀 Requests/sec 205.25 208.38 ⚪ +1.5%
⏱️ Latency P50 82.75 ms 82.39 ms ⚪ -0.4%
⏱️ Latency P95 203.84 ms 194.6 ms ⚪ -4.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 82.39 194.6 13,053 208.38 -9.24
Account 162.3 292.42 687 11.38 -62.49
TablesDB 78.2 143.99 7,099 116 -9.41
Storage 77.02 172.3 3,435 57.85 +1.09
Functions 124.51 233.25 1,832 31.53 -22.69

Top API waits (after)

API request Max wait (ms)
account.name.update 514.78
account.prefs.update 433.39
functions.variables.update 394.75
functions.create 392.39
account.get 337.62

Comment thread app/controllers/api/account.php Outdated
Comment on lines +572 to +584
DeleteIdentities::delete($dbForProject, Query::equal('userInternalId', [$targetUser->getSequence()]));
DeleteTargets::delete($dbForProject, Query::equal('userInternalId', [$targetUser->getSequence()]));
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check with Jake, we might want this as part of one transaction

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HarshMN2345 and others added 3 commits October 7, 2026 18:25
Delete the user, identities, targets and sessions together, then queue
the deletes job for the rest. A failure rolls back to an intact account
that can be deleted again, instead of a missing user whose remaining
rows nothing will clean up.
The OAuth2 identity has to go with the account, or the same email is
refused with general_bad_request until the deletes worker runs.
@HarshMN2345
HarshMN2345 merged commit c4a88bf into main Oct 8, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Receiving a general error for correct inputs using an email that account was previously deleted for

2 participants