fix(compliance): complete right-to-erasure cascade (audit H9, PR 1/5) [REVIEW BEFORE MERGE] - #184
Open
mdenner1234 wants to merge 1 commit into
Open
fix(compliance): complete right-to-erasure cascade (audit H9, PR 1/5) [REVIEW BEFORE MERGE]#184mdenner1234 wants to merge 1 commit into
mdenner1234 wants to merge 1 commit into
Conversation
…1/5) >⚠️ REVIEW BEFORE MERGE — this changes what account deletion does to a live > product's data and encodes GDPR/retention **policy defaults**. Confirm the > policy calls below before merging. `handle_user_deletion()` (BEFORE DELETE ON auth.users) erased a hardcoded 15-table list; ~20 more tables clean up via ON DELETE CASCADE. Four tables carried user PII with NEITHER — they orphaned personal data after account deletion: `gumroad_sales.email`, `cookie_consents`, `support_provisioning_log`, `support_ticket_events`. This extends the function to cover them, `to_regclass`-guarded so a missing/renamed table can't abort the whole cascade, idempotent. **Policy defaults applied (please confirm):** - `gumroad_sales` — **retain the row, de-identify it** (redact email, null resolved_user_id). Rationale: financial records typically sit under a legal retention obligation (tax) that overrides erasure; we keep the transaction but drop the person link. (Alternative: hard-delete — say the word.) - `cookie_consents` — **retain as proof-of-consent, de-identify** (null user_id, user_agent, ip_country). Rationale: GDPR accountability may require keeping that consent was given. (Alternative: hard-delete.) - `support_provisioning_log` / `support_ticket_events` — **delete** the user's rows (append-only operational logs). Bypasses the append-only guard for just that erase (transactional → auto-reverts on error), mirroring support_prune_webhook_events. - `audit_log` and other tamper-evident tables are **not** touched here — they get redact-in-place via the admin-erasure PR (PR 2/5), never hard-deleted. Test: `supabase/tests/h9_erasure_cascade_test.sql` (pgTAP, 6 cases) creates a user with PII in all four orphan tables, deletes the account, and asserts each is erased/de-identified and the profile is gone. Full `supabase test db` = 105/105. Part of the H9 series: (1) this cascade, (2) admin erasure RPC + DSAR-queue wiring, (3) fix the broken/contradictory audit-log purge, (4) enforce documented retention floors, (5) complete export_my_data + DSAR SLA watchdog. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
🛡️ Penetration test resultsPen-test suite: sastGenerated 2026-04-29T03:40:44.503Z Totals: ✅ 49 pass · ❌ 0 fail · ⊘ 0 skip ·
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(compliance): complete the right-to-erasure cascade (audit H9, PR 1/5)
handle_user_deletion()(BEFORE DELETE ON auth.users) erased a hardcoded 15-tablelist; ~20 more tables clean up via ON DELETE CASCADE. Four tables carried user PII
with NEITHER — they orphaned personal data after account deletion:
gumroad_sales.email,cookie_consents,support_provisioning_log,support_ticket_events.This extends the function to cover them,
to_regclass-guarded so a missing/renamedtable can't abort the whole cascade, idempotent.
Policy defaults applied (please confirm):
gumroad_sales— retain the row, de-identify it (redact email, nullresolved_user_id). Rationale: financial records typically sit under a legal
retention obligation (tax) that overrides erasure; we keep the transaction but
drop the person link. (Alternative: hard-delete — say the word.)
cookie_consents— retain as proof-of-consent, de-identify (null user_id,user_agent, ip_country). Rationale: GDPR accountability may require keeping that
consent was given. (Alternative: hard-delete.)
support_provisioning_log/support_ticket_events— delete the user's rows(append-only operational logs). Bypasses the append-only guard for just that
erase (transactional → auto-reverts on error), mirroring support_prune_webhook_events.
audit_logand other tamper-evident tables are not touched here — they getredact-in-place via the admin-erasure PR (PR 2/5), never hard-deleted.
Test:
supabase/tests/h9_erasure_cascade_test.sql(pgTAP, 6 cases) creates a userwith PII in all four orphan tables, deletes the account, and asserts each is
erased/de-identified and the profile is gone. Full
supabase test db= 105/105.Part of the H9 series: (1) this cascade, (2) admin erasure RPC + DSAR-queue wiring,
(3) fix the broken/contradictory audit-log purge, (4) enforce documented retention
floors, (5) complete export_my_data + DSAR SLA watchdog.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
🤖 Generated with Claude Code