Wie kann man XSS-Angriffe verhindern, wenn Laravel {!!content!!} verwendet?
習慣沉默
習慣沉默 2017-05-16 16:48:38
0
1
702

Verwenden Sie im Allgemeinen {{$article->title}}
但是有时有格式,所以需要这种:
{!!$article->body!!},
Aber dies führt zu XSS-Angriffen. Wie kann man damit umgehen, um XSS-Angriffe zu verhindern?

習慣沉默
習慣沉默

Antworte allen(1)
黄舟

推荐使用Purifier进行过滤一下,可以配置过滤规则。

'encoding' => 'UTF-8',
'finalize' => true,
'preload'  => false,
'cachePath' => null,
'settings' => [
    'default' => [
        'HTML.Doctype'             => 'XHTML 1.0 Strict',
        'HTML.Allowed'             => 'p,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
        'CSS.AllowedProperties'    => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
        'AutoFormat.AutoParagraph' => true,
        'AutoFormat.RemoveEmpty'   => true
    ],
    'test' => [
        'Attr.EnableID' => true
    ],
    "youtube" => [
        "HTML.SafeIframe" => 'true',
        "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
    ],
],

使用方法

{!! clean($article->body) !!}
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage