Heim > Fragen und Antworten > Hauptteil
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?
黄舟2017-05-16 16:50:38
推荐使用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) !!}