Repository navigation
Closed
Description
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.
softDeleteUsersclears the profile andnotification_preferences, stampsusers.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_expiryis 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_updatepolicy checks onlyid = (select auth.uid())(packages/supabase/scripts/13-RLS.sql:78-81).update_profileisSECURITY INVOKER, so the same policy governs it (packages/supabase/scripts/10-1-func-users.sql:207-238).authenticatedmay updateusername,full_name,avatar_url,avatar_updated_at,profile_dataandstatus(13-RLS.sql:96-98). - Notification preferences.
update_notification_preferencesissecurity definer, granted toauthenticated, and itsWHEREchecks onlyid = 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 nodeleted_atcheck (packages/supabase/scripts/07-4-push-notifications-pgmq.sql:75-76).
- Profile. The
- 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
- Add
and deleted_at is nullto theUSINGclause ofusers_self_update. One term covers both the direct writes andupdate_profile. KeepWITH CHECKas it is.deleted_atis not in the UPDATE grant, so the user cannot clear it. - Add
and deleted_at is nullto theWHEREofupdate_notification_preferences. - Add a check that the user's
users.deleted_atis null to thepush_subscriptionspolicy. Add the same check at the start ofregister_push_subscription, so it writes nothing and returns null for an erased account. That function issecurity definer, so the policy does not reach it. - Make each change in its
scripts/*.sqlfile and in one paired migration. - Check that the status heartbeat of an erased account now updates zero rows, and that the client shows no error for it.
- Run
bun run --filter @docs.plus/supabase_back types, and include the regenerated file, aspackages/supabase/CLAUDE.mdrequires after any SQL change. - 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_atset and a live token, an UPDATE on theirusersrow changes zero rows.update_profilereturns null and writes nothing. -
update_notification_preferenceswrites nothing for an erased account. - An erased account cannot insert a
push_subscriptionsrow, directly or throughregister_push_subscription. - A user without
deleted_atstill saves their profile and preferences, registers push, and writesstatus. - The scripts and the migration hold the same text.
- Checked locally with
psqlasauthenticated, withrequest.jwt.claimsset. 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
- 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).
- 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
[-]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[/+]HMarzban commentedon Oct 24, 2026
Maintainer ruling, 2026-10-24
users_self_update,update_notification_preferencesand thepush_subscriptionspolicy.This issue is unblocked. Decision 2 (also end the sessions on erase) is still open, so it stays out of this issue.
HMarzban commentedon Oct 24, 2026
Maintainer ruling, 2026-10-24
deleted_atchecks close the window. File it separately if it is ever wanted.Both decisions on this issue are now made.
HMarzban commentedon Oct 25, 2026
Built and committed on local main. Awaits the maintainer's final push.
Remaining gates: the Supabase production push, then
check-grants.sqlon production (0 rows).fix(supabase): block profile, preference and push writes after an acc…
fix(supabase): drop the unused get_bookmark_count and admin_get_user_…
refactor: cross-review wave-1
fix(supabase): keep the view duration when a visit closes before the …
test(supabase): add pgTAP policy tests for chat, media and erase writ…
HMarzban commentedon Nov 3, 2026
Status, 2026-11-03. The fix in
21e9dd308is pushed on 2026-11-03, and the pgTAP cases are in60ad50001. It is not live yet, because the deploy does not push Supabase migrations. Left:20261024120000to production, in the order in the hocuspocus CHANGELOG Migration section.packages/supabase/scripts/check-grants.sqlon production after all six migrations, and expect 0 rows.HMarzban commentedon Nov 3, 2026
Live in production. Migration
20261024120000(21e9dd308) is applied. On 2026-11-03 the maintainer pushed every pending Supabase migration to production withsupabase db push, andpackages/supabase/scripts/check-grants.sqlthen returned 0 rows. So an erased account can no longer write back its profile, preferences or push devices.