Skip to content

Commit 912ce72

Browse files
authored
security: Sanitize disabled RichEditor state (#20029)
1 parent 3ce6249 commit 912ce72

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

packages/forms/resources/views/components/rich-editor.blade.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
1010
@if ($isDisabled)
1111
<div
12-
x-data="{
13-
state: $wire.{{ $applyStateBindingModifiers("\$entangle('{$statePath}')") }},
14-
}"
15-
x-html="state"
1612
class="fi-fo-rich-editor fi-disabled prose block w-full max-w-none rounded-lg bg-gray-50 px-3 py-3 text-gray-500 shadow-sm ring-1 ring-gray-950/10 dark:prose-invert dark:bg-transparent dark:text-gray-400 dark:ring-white/10 sm:text-sm"
17-
></div>
13+
>
14+
{!! str($getState())->sanitizeHtml() !!}
15+
</div>
1816
@else
1917
<x-filament::input.wrapper
2018
:valid="! $errors->has($statePath)"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Filament\Forms\Components\RichEditor;
4+
use Filament\Forms\Form;
5+
use Filament\Tests\Forms\Fixtures\Livewire;
6+
use Filament\Tests\TestCase;
7+
use Illuminate\Contracts\View\View;
8+
9+
use function Filament\Tests\livewire;
10+
11+
uses(TestCase::class);
12+
13+
it('sanitizes stored HTML when rendering the disabled state to prevent stored XSS', function () {
14+
livewire(TestComponentWithDisabledRichEditor::class)
15+
->fillForm([
16+
'content' => '<p>Safe paragraph</p><img src=x onerror="window.__xss = true">',
17+
])
18+
->assertDontSeeHtml('onerror="window.__xss = true"');
19+
});
20+
21+
class TestComponentWithDisabledRichEditor extends Livewire
22+
{
23+
public function form(Form $form): Form
24+
{
25+
return $form
26+
->schema([
27+
RichEditor::make('content')
28+
->disabled(),
29+
])
30+
->statePath('data');
31+
}
32+
33+
public function render(): View
34+
{
35+
return view('forms.fixtures.form');
36+
}
37+
}

0 commit comments

Comments
 (0)