Skip to content

Stop an erased account from writing back its profile, preferences and push devices #579

Closed

Description

@HMarzban

Goal

After an admin erases an account, that account must not be able to write back what the erase cleared.

Facts

Code references are at b131fc7b1. Read from code, not measured.

  • softDeleteUsers clears the profile and notification_preferences, stamps users.deleted_at, deletes the push subscriptions and bans the Auth user (apps/hocuspocus.server/src/api/services/adminGhostAccounts.service.ts:301-331). It does not end the user's sessions.
  • The ban stops a token refresh. An access token that was already issued stays valid until it expires. jwt_expiry is 3600 s in the local config (packages/supabase/config.toml:157), which is also the hosted default.
  • Three write paths stay open for that hour:
    • Profile. The users_self_update policy checks only id = (select auth.uid()) (packages/supabase/scripts/13-RLS.sql:78-81). update_profile is SECURITY INVOKER, so the same policy governs it (packages/supabase/scripts/10-1-func-users.sql:207-238). authenticated may update username, full_name, avatar_url, avatar_updated_at, profile_data and status (13-RLS.sql:96-98).
    • Notification preferences. update_notification_preferences is security definer, granted to authenticated, and its WHERE checks only id = v_user_id (packages/supabase/scripts/07-0-notifications.sql:41-98). RLS does not apply inside a definer, so a policy term does not reach it.
    • Push subscriptions. The policy "Users can manage own subscriptions" is for all using ((select auth.uid()) = user_id), with no deleted_at check (packages/supabase/scripts/07-4-push-notifications-pgmq.sql:75-76).
  • Delivery stays off either way. The notification gate drops every row for an erased receiver. So this is about stored data that the erase promised to clear.

What to build

  1. Add and deleted_at is null to the USING clause of users_self_update. One term covers both the direct writes and update_profile. Keep WITH CHECK as it is. deleted_at is not in the UPDATE grant, so the user cannot clear it.
  2. Add and deleted_at is null to the WHERE of update_notification_preferences.
  3. Add a check that the user's users.deleted_at is null to the push_subscriptions policy. Add the same check at the start of register_push_subscription, so it writes nothing and returns null for an erased account. That function is security definer, so the policy does not reach it.
  4. Make each change in its scripts/*.sql file and in one paired migration.
  5. Check that the status heartbeat of an erased account now updates zero rows, and that the client shows no error for it.
  6. Run bun run --filter @docs.plus/supabase_back types, and include the regenerated file, as packages/supabase/CLAUDE.md requires after any SQL change.
  7. After the push, run packages/supabase/scripts/check-grants.sql, the post-push grant guard.

An avatar upload to storage is path-based and stays out of scope. With avatar_updated_at closed, an uploaded file does not show.

Acceptance criteria

  • For a user with deleted_at set and a live token, an UPDATE on their users row changes zero rows. update_profile returns null and writes nothing.
  • update_notification_preferences writes nothing for an erased account.
  • An erased account cannot insert a push_subscriptions row, directly or through register_push_subscription.
  • A user without deleted_at still saves their profile and preferences, registers push, and writes status.
  • The scripts and the migration hold the same text.
  • Checked locally with psql as authenticated, with request.jwt.claims set. No SQL test harness exists yet; Build an SQL test harness for chat RLS and storage policies, and run it in CI #583 builds one, and these cases join it.

Decisions

  1. Close the window now, on all three paths? Recommended: yes. The other choice is to accept up to 3600 s of writes after an erase. Owner: the maintainer (ruling 2 on [Tracking] Test gaps and backend performance from the 2026-10-23 review #575).
  2. Should the erase also end the user's sessions? Recommended: not for this issue. Ending a session does not revoke an access token that was already issued, so the checks above are what close the window. Owner: the maintainer.

Effort and order

Effort S. Both rulings are made, so work can start now.


Parent: #575. Source: the 2026-10-23 test coverage review, refined on 2026-10-24.

Activity

  1. added this to the v2.3.0 milestone on Oct 24, 2026
  2. added
    bug
    Security
    on Oct 24, 2026
  3. changed the title [-]Stop an erased account from editing its profile while its token is still valid[/-] [+]Stop an erased account from writing back its profile, preferences and push devices[/+] on Oct 24, 2026
  4. HMarzban commented on Oct 24, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-10-24

    1. Close the window now, on all three paths: users_self_update, update_notification_preferences and the push_subscriptions policy.

    This issue is unblocked. Decision 2 (also end the sessions on erase) is still open, so it stays out of this issue.

  5. HMarzban commented on Oct 24, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-10-24

    1. The erase does not end the user's sessions in this issue. The three deleted_at checks close the window. File it separately if it is ever wanted.

    Both decisions on this issue are now made.

  6. HMarzban commented on Oct 25, 2026

    @HMarzban
    CollaboratorAuthor

    Built and committed on local main. Awaits the maintainer's final push.

    Remaining gates: the Supabase production push, then check-grants.sql on production (0 rows).

  7. HMarzban commented on Nov 3, 2026

    @HMarzban
    CollaboratorAuthor

    Status, 2026-11-03. The fix in 21e9dd308 is pushed on 2026-11-03, and the pgTAP cases are in 60ad50001. It is not live yet, because the deploy does not push Supabase migrations. Left:

    • maintainer: push migration 20261024120000 to production, in the order in the hocuspocus CHANGELOG Migration section.
    • maintainer: run packages/supabase/scripts/check-grants.sql on production after all six migrations, and expect 0 rows.
  8. HMarzban commented on Nov 3, 2026

    @HMarzban
    CollaboratorAuthor

    Live in production. Migration 20261024120000 (21e9dd308) is applied. On 2026-11-03 the maintainer pushed every pending Supabase migration to production with supabase db push, and packages/supabase/scripts/check-grants.sql then returned 0 rows. So an erased account can no longer write back its profile, preferences or push devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthSecuritybug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions