Replies: 3 comments 2 replies
-
First of all, it floors me that issues are disabled on this repository. I feel it's at the very least disinformative to the users. |
Beta Was this translation helpful? Give feedback.
-
And yeah:
This is class is writing unescaped strings to the page, it's super scary 👻 A real-life security concern, and there's no mention of this in the documentation, so I can only assume this is accidental. Or am I supposed to escape every. string. myself? It's non-realistic to expect to do that without fault from human developers. It's why Blade escapes everything by default. Finally, if user really needs verbatim text, there's already a way with Laravel:
P.S. thanks God, at least the values of inputs are escaped |
Beta Was this translation helpful? Give feedback.
-
@raveren @decadence Disclaimer: I'm not a Spatie employee nor did I create this package. But I think it's working as intended. Take this example ( {{ html()->div()->class('p-9')->open() }}
{{ html()->div()->text("<script>alert('foo')</script>") }} // output: <script>alert('foo')</script> (plain text)
{{ html()->div("<script>alert('foo')</script>") }} // output: Alert dialog
{{ html()->div()->close() }} The reason for this behavior, is that the last one offers features like this: {{ html()->label('Username <strong>*</strong>') }} // I actually recommend doing this with `->child()` instead
// {{ html()->element('script')-> .. }} // I do not recommend this, but in theory one could write scripts with the html helper. laravel-html/src/BaseElement.php Line 402 in 95c58b7 text($text) works like {{ $foo }} .
It shouldn't lead to any issues when the code doesn't contain any user input: {{ html()->div()->class('p-9')->open() }}
{{ html()->label('About')->for('form.about')->class('label') }}
{{ html()->textarea()->wireModel('form.about')->class('textarea') }}
WARNING! Unsafe example when outputting `form.about`:
{{ html()->div($form->about)->class('p-3 w-full h-12') }}
Safer example:
{{ html()->div()->text($form->about)->class('p-3 w-full h-12') }}
Safer example with markdown/HTML (using something like stevebauman/purify or Laravel's markdown parser helper):
{{ html()->div($form->about_purified)->class('p-3 w-full h-12') }}
{{ html()->div()->close() }} @freekmurze @sebastiandedeyne I'll try to make a PR, because I've seen multiple things missing or not working in the docs (if you're agreeing with the given examples). But maybe you already have plans for it? :) |
Beta Was this translation helpful? Give feedback.
-
Today I discovered that elements you create with
html()
helper are not properly escaped.For example documentation says that second argument is
text
:But if you look at source code you see that method calls
html
method onA
:Therefore user may thinks (as I thought) that text he passes will be escaped but it will not and this can lead to bad things.
Is this by design? My thought that everything should be escaped by default. And if you want html you can call
html
method by hand.No warning in documentation is found.
Beta Was this translation helpful? Give feedback.
All reactions