From b51078314b4b34a8d09e9c7a18e7941fbbc86eff Mon Sep 17 00:00:00 2001 From: sulimanbenhalim Date: Tue, 27 Oct 2026 14:47:33 +0200 Subject: [PATCH 1/4] fix: erase the link cards of commits a deleted account takes with it --- KNOWLEDGE_BASE.md | 2 +- app/Actions/DeleteUser.php | 21 +++++++++++++++++---- tests/Unit/Actions/DeleteUserTest.php | 21 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index f0a4566249..c163539f6e 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -538,7 +538,7 @@ Sources: [export settings](resources/js/pages/user-profile/edit.tsx), [export co ### Deleting your account -Settings → Profile → **Delete account** opens a confirmation for permanent deletion of your /dev/null account; an app can also delete it through the signed API. It does not delete your GitHub account. Your top-level commits and every reply under those threads are erased. Your replies are also removed, except that replies from other people beneath them survive under authorless `[deleted]` placeholders. Your devices, the messages and reactions you sent, and all your uploaded images are erased too; other people's messages in your conversations stay with them. Account deletion is not covered by the 30-second commit undo. +Settings → Profile → **Delete account** opens a confirmation for permanent deletion of your /dev/null account; an app can also delete it through the signed API. It does not delete your GitHub account. Your top-level commits and every reply under those threads are erased. Your replies are also removed, except that replies from other people beneath them survive under authorless `[deleted]` placeholders. Your devices, the messages and reactions you sent, and all your uploaded images are erased too; other people's messages in your conversations stay with them. Link cards elsewhere that point to the erased commits are removed as well, since they repeat their text. Account deletion is not covered by the 30-second commit undo. You can sign in with GitHub again later, but start from a new account rather than restoring the deleted one. Export your data first if you want a copy. Deleting from /dev/null cannot retract copies of public content held elsewhere. diff --git a/app/Actions/DeleteUser.php b/app/Actions/DeleteUser.php index 479931c44f..a31a2cb137 100644 --- a/app/Actions/DeleteUser.php +++ b/app/Actions/DeleteUser.php @@ -9,6 +9,7 @@ use App\Models\CommitImage; use App\Models\CommitReport; use App\Models\Conversation; +use App\Models\LinkPreview; use App\Models\Message; use App\Models\MessageImage; use App\Models\MessageVoice; @@ -34,7 +35,7 @@ public function __construct(private UpdateCommitHotScores $updateCommitHotScores * other people replied to: those stay behind as tombstones with no author or body, so the replies under them keep their thread. * The database cascades the image rows of erased commits and the user's scheduled commits, and the voice notes of their * messages, but the files are erased here. Orgs the user was the last one in go too, with everything sent in them, - * as they do when the last member leaves. + * as they do when the last member leaves. So do the previews of links to the erased commits, which hold their bodies. */ public function handle(User $user): void { @@ -43,13 +44,15 @@ public function handle(User $user): void $imagePaths = [...$this->imagePaths($user), ...$this->scheduledImagePaths($user), ...$this->messageImagePaths($user), ...$this->messageVoicePaths($user)]; - $translationKeys = Commit::query()->withTrashed() - ->where(fn (CommitBuilder $query): CommitBuilder => $query->where('user_id', $user->id) - ->orWhereIn('root_id', $user->commits()->withTrashed()->topLevel()->select('id'))) + $translationKeys = $this->erasedCommits($user) ->select(['id', 'body']) ->lazyById(500) ->map(resolve(CommitTranslations::class)->key(...))->unique()->all(); + LinkPreview::query() + ->whereIn(DB::raw("substring(lower(url) from '/commits/([0-9a-f-]{36})')"), $this->erasedCommits($user)->selectRaw('id::text')) + ->delete(); + $user->commits()->withTrashed()->topLevel()->forceDelete(); CommitImage::query()->whereIn('commit_id', $this->replies($user)->select('id'))->delete(); CommitReport::query()->whereIn('commit_id', $this->replies($user)->select('id'))->delete(); @@ -95,6 +98,16 @@ private function engagedCommitIds(User $user): array ]; } + /** + * The commits that are erased or emptied with the user: their own, and every reply in the threads they started. + */ + private function erasedCommits(User $user): CommitBuilder + { + return Commit::query()->withTrashed() + ->where(fn (CommitBuilder $query): CommitBuilder => $query->where('user_id', $user->id) + ->orWhereIn('root_id', $user->commits()->withTrashed()->topLevel()->select('id'))); + } + /** * @return HasMany */ diff --git a/tests/Unit/Actions/DeleteUserTest.php b/tests/Unit/Actions/DeleteUserTest.php index df3242c95d..f1213a15fd 100644 --- a/tests/Unit/Actions/DeleteUserTest.php +++ b/tests/Unit/Actions/DeleteUserTest.php @@ -51,6 +51,27 @@ expect(Commit::withTrashed()->pluck('id')->all())->toBe([$unrelated->id]); }); +it('erases the previews of links to the commits it erases, which hold their bodies', function (): void { + $user = User::factory()->create(); + $commit = Commit::factory()->for($user)->create(); + $reply = Commit::factory()->for($commit, 'parent')->create(); + $tombstone = Commit::factory()->for($user)->for(Commit::factory(), 'parent')->create(); + Commit::factory()->for($tombstone, 'parent')->create(); + $previews = collect([$commit, $reply, $tombstone])->map(fn (Commit $linked): LinkPreview => LinkPreview::factory()->create([ + 'url' => route('commit.show', [$linked->user, $linked]), + 'description' => $linked->body, + ])); + $shouted = LinkPreview::factory()->create(['url' => str_replace($commit->id, mb_strtoupper($commit->id), route('commit.show', [$user, $commit]))]); + $linking = Commit::factory()->create(['link_preview_id' => $previews->first()->id]); + $other = LinkPreview::factory()->create(['url' => route('commit.show', [$linking->user, $linking])]); + + resolve(DeleteUser::class)->handle($user); + + $previews->push($shouted)->each(fn (LinkPreview $preview) => $this->assertModelMissing($preview)); + $this->assertModelExists($other); + expect($linking->fresh()->link_preview_id)->toBeNull(); +}); + it('keeps the quotes of others when erasing the quoted commits of a deleted user', function (): void { $user = User::factory()->create(); $quote = Commit::factory()->for(Commit::factory()->for($user), 'quotedCommit')->create(); From e0c733308f100df7067b242d571385bc0aeeaec7 Mon Sep 17 00:00:00 2001 From: sulimanbenhalim Date: Thu, 5 Nov 2026 00:52:30 +0200 Subject: [PATCH 2/4] fix: erase the link cards of replies to a deleted account's commits since their titles name it --- KNOWLEDGE_BASE.md | 2 +- app/Actions/DeleteUser.php | 10 ++++++---- tests/Unit/Actions/DeleteUserTest.php | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 0b489b6e2d..958f4cfd0e 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -658,7 +658,7 @@ Sources: [export settings](resources/js/pages/user-profile/edit.tsx), [export co ### Deleting your account -Settings → Profile → **Delete account** opens a confirmation for permanent deletion of your /dev/null account; an app can also delete it through the signed API. It does not delete your GitHub account. Your top-level commits and every reply under those threads are erased. Your replies are also removed, except that replies from other people beneath them survive under authorless `[deleted]` placeholders. Your devices, the messages and reactions you sent, and all your uploaded images are erased too; other people's messages in your conversations stay with them. Link cards elsewhere that point to the erased commits are removed as well, since they repeat their text. Account deletion is not covered by the 30-second commit undo. +Settings → Profile → **Delete account** opens a confirmation for permanent deletion of your /dev/null account; an app can also delete it through the signed API. It does not delete your GitHub account. Your top-level commits and every reply under those threads are erased. Your replies are also removed, except that replies from other people beneath them survive under authorless `[deleted]` placeholders. Your devices, the messages and reactions you sent, and all your uploaded images are erased too; other people's messages in your conversations stay with them. Link cards elsewhere that point to the erased commits are removed as well, since they repeat their text, and so are cards of replies to your commits, since their titles name you. Account deletion is not covered by the 30-second commit undo. You can sign in with GitHub again later, but start from a new account rather than restoring the deleted one. Export your data first if you want a copy. Deleting from /dev/null cannot retract copies of public content held elsewhere. diff --git a/app/Actions/DeleteUser.php b/app/Actions/DeleteUser.php index 67e65896a8..42cd385240 100644 --- a/app/Actions/DeleteUser.php +++ b/app/Actions/DeleteUser.php @@ -43,9 +43,9 @@ public function __construct(private UpdateCommitHotScores $updateCommitHotScores * What they posted for organizations stays, and only forgets who posted it. * The database cascades the image rows of erased commits and the user's scheduled commits, and the voice notes of their * messages, but the files are erased here. Orgs the user was the last one in go too, with everything sent in them, - * as they do when the last member leaves. So do the previews of links to the erased commits, which hold their bodies. - * Only their GitHub ID is kept, so looking their handle up never brings their page back as an unclaimed one, until they - * sign in again. + * as they do when the last member leaves. So do the previews of links to the erased commits, which hold their bodies, + * and to the replies to their commits, whose titles name them. Only their GitHub ID is kept, so looking their handle up + * never brings their page back as an unclaimed one, until they sign in again. */ public function handle(User $user): void { @@ -83,7 +83,9 @@ public function handle(User $user): void ->update(['summary' => null, 'summary_created_at' => null]); DB::table('commit_headline')->whereIn('commit_id', $this->touchedCommits($user)->select('id'))->delete(); LinkPreview::query() - ->whereIn(DB::raw("substring(lower(url) from '/commits/([0-9a-f-]{36})')"), $this->touchedCommits($user)->selectRaw('id::text')) + ->whereIn(DB::raw("substring(lower(url) from '/commits/([0-9a-f-]{36})')"), $this->touchedCommits($user) + ->orWhereIn('parent_id', $user->commits()->withTrashed()->select('id')) + ->selectRaw('id::text')) ->delete(); $user->commits()->withTrashed()->topLevel()->forceDelete(); CommitImage::query()->whereIn('commit_id', $this->replies($user)->select('id'))->delete(); diff --git a/tests/Unit/Actions/DeleteUserTest.php b/tests/Unit/Actions/DeleteUserTest.php index 4fa5e0bf19..deeaa578a9 100644 --- a/tests/Unit/Actions/DeleteUserTest.php +++ b/tests/Unit/Actions/DeleteUserTest.php @@ -91,6 +91,21 @@ expect($linking->fresh()->link_preview_id)->toBeNull(); }); +it('erases the previews of links to replies to its commits in other threads, whose titles name it', function (): void { + $user = User::factory()->create(); + $thread = Commit::factory()->create(); + $answer = Commit::factory()->for(Commit::factory()->for($user)->for($thread, 'parent'), 'parent')->create(); + $sibling = Commit::factory()->for($thread, 'parent')->create(); + $answered = LinkPreview::factory()->create(['url' => route('commit.show', [$answer->user, $answer])]); + $kept = LinkPreview::factory()->create(['url' => route('commit.show', [$sibling->user, $sibling])]); + + resolve(DeleteUser::class)->handle($user); + + $this->assertModelMissing($answered); + $this->assertModelExists($kept); + $this->assertModelExists($answer); +}); + it('keeps the quotes of others when erasing the quoted commits of a deleted user', function (): void { $user = User::factory()->create(); $quote = Commit::factory()->for(Commit::factory()->for($user), 'quotedCommit')->create(); From c231ae61a5b56243cabad1532876b4270e7f9355 Mon Sep 17 00:00:00 2001 From: sulimanbenhalim Date: Tue, 17 Nov 2026 13:59:14 +0200 Subject: [PATCH 3/4] fix: erase the link cards of commits linked with escaped characters too --- app/Actions/DeleteUser.php | 11 ++++++++--- tests/Unit/Actions/DeleteUserTest.php | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/Actions/DeleteUser.php b/app/Actions/DeleteUser.php index a2df504ae1..3c19c33672 100644 --- a/app/Actions/DeleteUser.php +++ b/app/Actions/DeleteUser.php @@ -30,6 +30,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Str; final readonly class DeleteUser { @@ -86,10 +87,14 @@ public function handle(User $user): void ->whereIn('commit_id', $this->touchedCommits($user)->select('id'))) ->update(['summary' => null, 'summary_created_at' => null]); DB::table('commit_headline')->whereIn('commit_id', $this->touchedCommits($user)->select('id'))->delete(); + $linked = $this->touchedCommits($user)->orWhereIn('parent_id', $user->commits()->withTrashed()->select('id')); + $linkedIds = $linked->clone()->pluck('id')->flip(); LinkPreview::query() - ->whereIn(DB::raw("substring(lower(url) from '/commits/([0-9a-f-]{36})')"), $this->touchedCommits($user) - ->orWhereIn('parent_id', $user->commits()->withTrashed()->select('id')) - ->selectRaw('id::text')) + ->whereIn(DB::raw("substring(lower(url) from '/commits/([0-9a-f-]{36})')"), $linked->selectRaw('id::text')) + // A link that escapes part of itself still opens the commit, as the router decodes it first, so it is read decoded too. + ->orWhereIn('id', LinkPreview::query()->where('url', 'like', '%\%%')->lazyById() + ->filter(fn (LinkPreview $preview): bool => $linkedIds->has(Str::match('#/commits/([0-9a-f-]{36})#', mb_strtolower(rawurldecode($preview->url))))) + ->pluck('id')->all()) ->delete(); $user->commits()->withTrashed()->topLevel()->forceDelete(); CommitImage::query()->whereIn('commit_id', $this->replies($user)->select('id'))->delete(); diff --git a/tests/Unit/Actions/DeleteUserTest.php b/tests/Unit/Actions/DeleteUserTest.php index af371a4733..3129d71cb4 100644 --- a/tests/Unit/Actions/DeleteUserTest.php +++ b/tests/Unit/Actions/DeleteUserTest.php @@ -99,6 +99,27 @@ expect($linking->fresh()->link_preview_id)->toBeNull(); }); +it('erases the previews of links to its commits that escape part of the link, which still open them', function (string $plain, string $escaped): void { + $user = User::factory()->create(); + $commit = Commit::factory()->for($user)->create(['id' => '01a16ffc-740e-7105-82dc-e3a7ed20aaaa']); + $other = Commit::factory()->create(['id' => '01a16ffc-740e-7105-82dc-e3a7ed20bbbb']); + $preview = LinkPreview::factory()->create(['url' => str_replace($plain, $escaped, route('commit.show', [$user, $commit]))]); + $kept = LinkPreview::factory()->create(['url' => str_replace($plain, $escaped, route('commit.show', [$other->user, $other]))]); + + expect($preview->url)->not->toBe(route('commit.show', [$user, $commit])); + + resolve(DeleteUser::class)->handle($user); + + $this->assertModelMissing($preview); + $this->assertModelExists($kept); +})->with([ + 'a dash' => ['-7105-', '%2D7105%2d'], + 'a digit' => ['01a16ffc', '%301a16ffc'], + 'a letter' => ['16ffc', '16%66fc'], + 'an uppercase letter' => ['e3a7', 'e3%41%37'], + 'the path' => ['/commits/', '%2F%63%6F%6d%6d%69%74%73%2f'], +]); + it('erases the previews of links to replies to its commits in other threads, whose titles name it', function (): void { $user = User::factory()->create(); $thread = Commit::factory()->create(); From 79426f238aa7b4fa198e1996fdb90e15a16ecc7d Mon Sep 17 00:00:00 2001 From: sulimanbenhalim Date: Tue, 17 Nov 2026 14:18:12 +0200 Subject: [PATCH 4/4] fix: also erase the link cards of commit links with dot segments or backslashes that the fetcher resolves --- app/Actions/DeleteUser.php | 8 +++++--- tests/Unit/Actions/DeleteUserTest.php | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Actions/DeleteUser.php b/app/Actions/DeleteUser.php index 3c19c33672..9db7f8f939 100644 --- a/app/Actions/DeleteUser.php +++ b/app/Actions/DeleteUser.php @@ -31,6 +31,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; +use Uri\WhatWg\Url; final readonly class DeleteUser { @@ -91,9 +92,10 @@ public function handle(User $user): void $linkedIds = $linked->clone()->pluck('id')->flip(); LinkPreview::query() ->whereIn(DB::raw("substring(lower(url) from '/commits/([0-9a-f-]{36})')"), $linked->selectRaw('id::text')) - // A link that escapes part of itself still opens the commit, as the router decodes it first, so it is read decoded too. - ->orWhereIn('id', LinkPreview::query()->where('url', 'like', '%\%%')->lazyById() - ->filter(fn (LinkPreview $preview): bool => $linkedIds->has(Str::match('#/commits/([0-9a-f-]{36})#', mb_strtolower(rawurldecode($preview->url))))) + // A link with escapes, dot segments or backslashes still opens the commit, since the preview fetcher resolves the + // path and the router decodes it, so those are read the same way. + ->orWhereIn('id', LinkPreview::query()->where('url', '~', '^[^?#]*([%\\\\]|/\.)')->select(['id', 'url'])->lazyById() + ->filter(fn (LinkPreview $preview): bool => $linkedIds->has(Str::match('#/commits/([0-9a-f-]{36})#', mb_strtolower(rawurldecode((string) Url::parse($preview->url)?->getPath()))))) ->pluck('id')->all()) ->delete(); $user->commits()->withTrashed()->topLevel()->forceDelete(); diff --git a/tests/Unit/Actions/DeleteUserTest.php b/tests/Unit/Actions/DeleteUserTest.php index 3129d71cb4..b0df7eb6dd 100644 --- a/tests/Unit/Actions/DeleteUserTest.php +++ b/tests/Unit/Actions/DeleteUserTest.php @@ -99,7 +99,7 @@ expect($linking->fresh()->link_preview_id)->toBeNull(); }); -it('erases the previews of links to its commits that escape part of the link, which still open them', function (string $plain, string $escaped): void { +it('erases the previews of links to its commits written another way that still opens them', function (string $plain, string $escaped): void { $user = User::factory()->create(); $commit = Commit::factory()->for($user)->create(['id' => '01a16ffc-740e-7105-82dc-e3a7ed20aaaa']); $other = Commit::factory()->create(['id' => '01a16ffc-740e-7105-82dc-e3a7ed20bbbb']); @@ -118,6 +118,9 @@ 'a letter' => ['16ffc', '16%66fc'], 'an uppercase letter' => ['e3a7', 'e3%41%37'], 'the path' => ['/commits/', '%2F%63%6F%6d%6d%69%74%73%2f'], + 'an escaped dot segment' => ['/commits/', '/commits/%2e/'], + 'a parent segment' => ['/commits/', '/commits/x/../'], + 'backslashes' => ['/commits/', '\\commits\\'], ]); it('erases the previews of links to replies to its commits in other threads, whose titles name it', function (): void {