Skip to content

Commit

Permalink
修复 XSS 注入漏洞
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Mar 6, 2022
1 parent 31cdeeb commit 31cb5e3
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/Observers/TopicObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class TopicObserver
{
public function saving(Topic $topic)
{
$topic->body = clean($topic->body, 'user_topic_body');

$topic->excerpt = make_excerpt($topic->body);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"laravel/sanctum": "^2.14.1",
"laravel/tinker": "^2.7",
"mews/captcha": "~3.0",
"mews/purifier": "~3.3",
"overtrue/laravel-lang": "~6.0",
"summerblue/laravel-active": "9.*"
},
Expand Down
149 changes: 148 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions config/purifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return [
'encoding' => 'UTF-8',
'finalize' => true,
'ignoreNonStrings' => false,
'cachePath' => storage_path('app/purifier'),
'cacheFileMode' => 0755,
'settings' => [
'user_topic_body' => [
'HTML.Doctype' => 'XHTML 1.0 Transitional',
'HTML.Allowed' => 'div,b,strong,i,em,a[href|title],ul,ol,ol[start],li,p[style],br,span[style],img[width|height|alt|src],*[style|class],pre,hr,code,h2,h3,h4,h5,h6,blockquote,del,table,thead,tbody,tr,th,td',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,margin,width,height,font-family,text-decoration,padding-left,color,background-color,text-align',
'AutoFormat.AutoParagraph' => true,
'AutoFormat.RemoveEmpty' => true,
],
],
];

0 comments on commit 31cb5e3

Please sign in to comment.