Skip to content

fix(auth): a disabled account keeps its verified addresses, so no new account can register one - #654

Merged
PiquelChips merged 2 commits into
mainfrom
fix/653-disabled-accounts-keep-addresses
Nov 21, 2026
Merged

PiquelChips merged 2 commits into
mainfrom
fix/653-disabled-accounts-keep-addresses

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Disabling an account released its verified addresses, so a new account could verify one of them. Re-enabling the first account then failed. Its announcements and notifications could also reach an address that now belonged to someone else, or reach one address twice (#614, #620, #622).

Now a disabled account keeps its verified addresses until it is purged, as an account scheduled for deletion already did. Verifying one of them on another account is refused through the existing OwnedElsewhere path ("This address is already used by another Origin Account."). An invitation to one of them is refused too, through the existing invitation_address_taken error. Re-enabling an account can't fail on a lost address any more.

This supersedes the per-channel fixes in #619, #621, #625 and #626. Once no address can be shared, none of them is needed.

What changed

  • Migration 0002_disabled_accounts_keep_verified_emails.sql. It's a new file because released migrations are immutable (docs/dev/architecture/database.md).
    • Drops synchronize_user_email_ownership and its trigger.
    • Ownership triggers now claim and release for every account, whatever its status. The status check and the users row lock it needed are gone.
    • Renames active_verified_email_ownership to verified_email_ownership, along with its index and constraints. The rename breaks expand-then-contract: the previous release's ownership lookups fail until the new one is healthy. The migration explains this in its comments, and we accept it because there are no real users yet.
    • Cleans up existing data. Each address still verified on more than one account goes to one account: the one that owns it, otherwise the one that verified it last. The other accounts' rows lose verified and primary status. An account that lost its primary gets its earliest remaining verified address as primary. The migration then records ownership for disabled accounts' addresses.
  • Rust
    • Removed AdminError::EmailClaimed (email_claimed) and its mapping in enable_user. Only the re-enable conflict used them.
    • is_owned_elsewhere is now is_owned(address, except), and counts disabled holders. The federation import and invitation-redeem paths pass their own account as except.
    • Creating or resending an invitation now checks is_owned with no exception, so it refuses an address any account holds verified, disabled ones included. Before, it used the active-only find_active_verified, so an invitation to a disabled account's address was sent, and redeeming it silently created the account without that address. The redeem-time check stays, for an address claimed after the invitation was mailed. The InvitationAddressTaken message, which the CLI and dashboard show, now says the holder may be disabled.
    • find_active_verified still looks up only active accounts, as before.
    • Updated doc comments throughout.
  • Docs: email.md, database.md, surfaces.md, threat-model.md, administration.md (including its invitation limits), and the user guide's email troubleshooting entry.

Proof

  • just validate passes.

  • just db test passes: 501 tests, and the query cache matches.

  • New test emails::tests::a_disabled_account_keeps_its_verified_address: the owner verifies an address, then is disabled. Another account's verification of that address gets 409 and stays unverified. Re-enabling the owner succeeds, and the address is still verified.

  • New test admin::tests::invitations::a_disabled_accounts_address_cannot_be_invited: an invitation is mailed, then another account verifies the address and is disabled. Creating a new invitation to that address and resending the first one both fail with InvitationAddressTaken.

  • The repo has no harness for migration tests, so I tested the data cleanup by hand. On a scratch cluster I applied 0001 only and seeded:

    • an address held by an active owner and by a disabled account;
    • an address two disabled accounts verified;
    • a disabled account's only address;
    • a deleting account's address.

    Then I applied 0002. The owner and the latest verifier kept their addresses. The losing rows became unverified, and an account that lost its primary had a new one promoted. No verified address was left without exactly one owning account. Disabling still kept ownership. Re-enabling a loser worked. Another account claiming a disabled account's address failed with verified email already belongs to another account.

  • just docs passes.

Review

Reviewed by GPT 6.1 Sol: 9/10, both findings applied (invitations refuse a disabled account's address; stale active-only ownership wording in the docs).

Closes #653
Closes #614
Closes #620
Closes #622

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol (via T3 Code)

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b5500ac6-29f2-4adf-b14f-ac8a8459fc66
Commits

Reviewing files that changed from the base of the PR and between db61a8c and 2257407.

Files selected for processing: 20

  • apps/auth-service/src/admin/error.rs
  • apps/auth-service/src/admin/service/access.rs
  • apps/auth-service/src/admin/service/accounts.rs
  • apps/auth-service/src/admin/tests/invitations.rs
  • apps/auth-service/src/emails/error.rs
  • apps/auth-service/src/emails/mod.rs
  • apps/auth-service/src/emails/tests.rs
  • crates/database/.sqlx/query-1c76ff9d673457295b1464f192818b2b67b7937a444e62152464fb012d0d7bd1.json
  • crates/database/.sqlx/query-8b62bc977f99c53711677348abfc91446e07ccbdb52ab1c7138975eb1cc94239.json
  • crates/database/migrations/0002_disabled_accounts_keep_verified_emails.sql
  • crates/database/src/inventory/mod.rs
  • crates/database/src/repositories/emails/mod.rs
  • crates/database/src/repositories/emails/tests.rs
  • crates/database/src/repositories/users/mod.rs
  • docs/dev/architecture/database.md
  • docs/dev/architecture/email.md
  • docs/dev/architecture/surfaces.md
  • docs/dev/operations/administration.md
  • docs/dev/security/threat-model.md
  • docs/user/account/email-addresses.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@PiquelChips
PiquelChips marked this pull request as ready for review November 21, 2026 15:07
@PiquelChips
PiquelChips force-pushed the fix/653-disabled-accounts-keep-addresses branch from ee9d381 to 6ff93af Compare November 21, 2026 18:12
… account can register one

Disabling an account no longer releases its verified addresses: they stay
its own until it is purged, as an account scheduled for deletion's already
did. Verifying one on another account is refused as OwnedElsewhere, and
enabling the account again can no longer fail on a lost address.

Migration 0002 drops the status sync trigger, renames
active_verified_email_ownership to verified_email_ownership, and leaves
every verified address with one account: its owner keeps it, otherwise
the account that verified it last.
… address

An operator could create or resend an invitation to an address a disabled
account holds verified, and redeeming it created the account without the
address. Invitations now check ownership across every account, whatever its
status, through EmailRepository::is_owned. The docs on verified ownership
say it covers every account until it is purged or the address is removed.
@PiquelChips
PiquelChips force-pushed the fix/653-disabled-accounts-keep-addresses branch from 6ff93af to 2257407 Compare November 21, 2026 18:48
@PiquelChips
PiquelChips added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 33f6b90 Nov 21, 2026
14 checks passed
@PiquelChips
PiquelChips deleted the fix/653-disabled-accounts-keep-addresses branch November 21, 2026 19:16
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in sourceorigin.dev Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment