Repository navigation
fix: erase the link cards of commits a deleted account takes with it #1230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: production
Are you sure you want to change the base?
Changes from all commits
b510783
58a00bb
657550e
e0c7333
807e383
c231ae6
79426f2
09f176b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| use App\Models\ConversationParticipant; | ||
| use App\Models\Guild; | ||
| use App\Models\Headline; | ||
| use App\Models\LinkPreview; | ||
| use App\Models\Message; | ||
| use App\Models\MessageImage; | ||
| use App\Models\MessageVoice; | ||
|
|
@@ -29,6 +30,8 @@ | |
| use Illuminate\Support\Collection; | ||
| use Illuminate\Support\Facades\Cache; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Str; | ||
| use Uri\WhatWg\Url; | ||
|
|
||
| final readonly class DeleteUser | ||
| { | ||
|
|
@@ -43,8 +46,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. 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,6 +87,16 @@ 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})')"), $linked->selectRaw('id::text')) | ||
| // 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()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Chunk the escaped-URL preview deletes. The escaped-URL cleanup collects every matching preview ID and binds them all in one Suggested fix
|
||
| ->delete(); | ||
|
Comment on lines
+92
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $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(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not let the raw match override the normalized destination.
Let
Abe an erased UUID andBa retained UUID. The same-host path/commits/{A}/../../@bob/commits/{B}resolves to Bob's commitB. The provider normalizes the path before fetching its preview. (url.spec.whatwg.org)Line 93 instead extracts
Afrom the stored URL. The normalized filter rejectsB, but theorWhereIncannot cancel the raw match. Account deletion therefore removes another commit's preview. PostgreSQL returns the first captured match here. (postgresql.org)Exclude normalization candidates from the raw SQL branch. Match those URLs only through their normalized paths. This retains this preview while preserving cleanup for paths that resolve to
A.Based on learnings, verify that similar-but-distinct deletion fixtures are preserved.
ast-grep (0.51.1)
[error] 93-93: Prevent raw SQL injections
Context: $linked->selectRaw('id::text')
Note: [CWE-89] Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
(laravel-raw-sql-injection)
Source: Learnings