Skip to content

Expire unactivated accounts after 24 hours - #96

Open
cyberb wants to merge 2 commits into
masterfrom
expire-unactivated-accounts
Open

cyberb wants to merge 2 commits into
masterfrom
expire-unactivated-accounts

Conversation

@cyberb

@cyberb cyberb commented Nov 29, 2026

Copy link
Copy Markdown
Member

An account that never confirmed its email was stuck for 40+ days: sign in refused, signing up again said "Email is already registered", reset skipped it, no resend. Meanwhile the cleaner sent it the welcome, plan, lock and removal emails at an unconfirmed address.

  • Activation tokens expire after 24h (cleaner.activation_token_ttl_seconds; 45s in integration).
  • Signing up on an email held by an expired unactivated account removes it and starts over with a new activation email.
  • The cleaner purges expired unactivated accounts silently every tick (batched, indexed query).
  • Lifecycle emails go only to activated accounts.

First prod deploy will purge all historical unactivated accounts older than a day, 100 per minute.

Tests: unit tests for token expiry, sign-up restart and the purge; API test test_user_activation_expired_signup_starts_over covers signup → expiry → old token rejected → sign up again → activate → sign in.

Closes syncloud/platform#673

An account whose email was never confirmed could never be recovered. Sign in
refuses an inactive user, signing up again answered "Email is already
registered", password reset skipped inactive users, and there is no resend of
the activation email. The account only disappeared after the cleaner walked it
through the whole trial lifecycle (welcome, plan reminder, lock warning, lock,
removal), at least 40 days and in practice longer because Clean() advances one
user per minute. Those four emails went to an address nobody had confirmed, so
anyone who typed a stranger's address had that stranger mailed for weeks.

#79 kept activation tokens non-expiring precisely because re-registering was
blocked and expiry would strand the user. That block is what this removes:

- Activation tokens expire after cleaner.activation_token_ttl_seconds
  (86400 in prod, uat and local, 45 in integration so the API test can wait
  it out). GetActivateAction refuses an expired token.
- CreateNewUser on an email held by an inactive user whose activation has
  expired (or who has no activation action at all) removes that account and
  registers afresh, sending a new activation email. An active account, or an
  inactive one still inside the window, still answers "already registered".
- The cleaner purges expired unactivated accounts every tick with one indexed
  query, batched at 100, removing domains, actions and the user with no email.
  The query also requires registered_at to be older than the TTL, so a user
  inserted a moment before its activation action cannot be caught in between.
- Clean() skips inactive users, so lifecycle emails only go to confirmed
  addresses.

The sign-up path is the one the API test exercises, because the integration
environment runs with the user cleaner disabled. The new key has no default
and fails startup when missing, like cleaner.user.

On the first prod deploy the purge removes every historical unactivated
account older than a day, 100 per minute.

Closes syncloud/platform#673
WebUserActivate wrapped every error from Users.Activate in a plain
"invalid request", which ErrorToResponse maps to 500. An expired, unknown or
already used link is the visitor's problem, not the server's, and Activate.vue
already shows the message of a 400 response but sends anything else to /error.
Service errors now pass through as 400 with their message, following the
switch-subscription handler; anything else stays hidden behind "invalid
request". The expiry message tells the visitor to register again, which since
the previous commit is what frees the email.

Build 1697 caught this: the API test got 500 for the expired token.
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.

Redirect should allow to reset password for inactive user

1 participant