-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: remove XSS cleaner and remove XSS vulnerabilities
We've been mostly relying on the 3rd party xss cleaner to make sure user submitted content is clean. This PR fixes up any leftover holes in the bbcode parser that allow xss vulnerabilities, and as a result, the 3rd party library isn't needed anymore. It cleans responsibly by first, running `htmlspecialchars()` over the content, followed by sanitizing the untrusted urls and whitelisting their protocol.
- Loading branch information
Showing
13 changed files
with
118 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
111 changes: 111 additions & 0 deletions
111
database/migrations/2024_07_03_085223_htmlspecialchars_decode_bbcode.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
return new class () extends Migration { | ||
public function up(): void | ||
{ | ||
DB::table('articles') | ||
->lazyById() | ||
->each(function (object $article): void { | ||
/** @var object{id: int, content: string} $article */ | ||
DB::table('articles') | ||
->where('id', '=', $article->id) | ||
->update([ | ||
'content' => htmlspecialchars_decode($article->content), | ||
]); | ||
}); | ||
|
||
DB::table('comments') | ||
->lazyById() | ||
->each(function (object $comment): void { | ||
/** @var object{id: int, content: string} $comment */ | ||
DB::table('comments') | ||
->where('id', '=', $comment->id) | ||
->update([ | ||
'content' => htmlspecialchars_decode($comment->content), | ||
]); | ||
}); | ||
|
||
DB::table('messages') | ||
->lazyById() | ||
->each(function (object $message): void { | ||
/** @var object{id: int, message: string} $message */ | ||
DB::table('messages') | ||
->where('id', '=', $message->id) | ||
->update([ | ||
'message' => htmlspecialchars_decode($message->message), | ||
]); | ||
}); | ||
|
||
DB::table('playlists') | ||
->lazyById() | ||
->each(function (object $playlist): void { | ||
/** @var object{id: int, description: string} $playlist */ | ||
DB::table('playlists') | ||
->where('id', '=', $playlist->id) | ||
->update([ | ||
'description' => htmlspecialchars_decode($playlist->description), | ||
]); | ||
}); | ||
|
||
DB::table('posts') | ||
->lazyById() | ||
->each(function (object $post): void { | ||
/** @var object{id: int, content: string} $post */ | ||
DB::table('posts') | ||
->where('id', '=', $post->id) | ||
->update([ | ||
'content' => htmlspecialchars_decode($post->content), | ||
]); | ||
}); | ||
|
||
DB::table('private_messages') | ||
->lazyById() | ||
->each(function (object $privateMessage): void { | ||
/** @var object{id: int, message: string} $privateMessage */ | ||
DB::table('private_messages') | ||
->where('id', '=', $privateMessage->id) | ||
->update([ | ||
'message' => htmlspecialchars_decode($privateMessage->message), | ||
]); | ||
}); | ||
|
||
DB::table('torrents') | ||
->lazyById() | ||
->each(function (object $torrent): void { | ||
/** @var object{id: int, description: string} $torrent */ | ||
DB::table('torrents') | ||
->where('id', '=', $torrent->id) | ||
->update([ | ||
'description' => htmlspecialchars_decode($torrent->description), | ||
]); | ||
}); | ||
|
||
DB::table('requests') | ||
->lazyById() | ||
->each(function (object $request): void { | ||
/** @var object{id: int, description: string} $request */ | ||
DB::table('requests') | ||
->where('id', '=', $request->id) | ||
->update([ | ||
'description' => htmlspecialchars_decode($request->description), | ||
]); | ||
}); | ||
|
||
DB::table('users') | ||
->lazyById() | ||
->each(function (object $user): void { | ||
/** @var object{id: int, about: string, signature: string} $user */ | ||
DB::table('users') | ||
->where('id', '=', $user->id) | ||
->update([ | ||
'about' => htmlspecialchars_decode($user->about), | ||
'signature' => htmlspecialchars_decode($user->signature), | ||
]); | ||
}); | ||
} | ||
}; |