Pawooo's avatar
Level 5

The best way to sanitize RichEditor in Laravel/Filament?

Filament says it's up to you to sanitize your wysiwyg, so here I am. https://filamentphp.com/docs/3.x/forms/fields/rich-editor#security

I'm building a Laravel + React application, the dashboard uses Filament RichEditor. The input I'm trying to sanitize looks like this (this is the actual text inside of wysiwyg):

I tried using https://github.com/mewebstudio/Purifier both ways:

Filament/Resources/Resource/CreateResource.php

use Mews\Purifier\Facades\Purifier;
// ..
    protected function mutateFormDataBeforeSave(array $data): array
    {
		$data['description'] = Purifier::clean($data['description']);

		// .. 
        return $data;
	}

And model-level Model.php

use Mews\Purifier\Casts\CleanHtmlInput;
   
 protected $casts = [
        'description' => CleanHtmlInput::class,
    ];

Yet when I trigger saving it just, well, saves it as-is and I don't see even <script> removed, let alone other maliciousness. What am I doing wrong here? Any help would be much appreciated.

I have an option of just using https://github.com/cure53/DOMPurify, but I feel like sanitizing your inputs before they are saved is by far better than storing malicious wrappers.

UPD: On second thought, not sure if this is the intended behavior, but React's dangerouslySetInnerHTML outputs this code as simple text, alert() is not triggered, so maybe the way I input data in wysiwyg is wrong?

0 likes
0 replies

Please or to participate in this conversation.