✨ add xss filter
This commit is contained in:
11
utils/xss_filter.go
Normal file
11
utils/xss_filter.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import "github.com/microcosm-cc/bluemonday"
|
||||
|
||||
// XssFilter Xss 过滤器
|
||||
func XssFilter(str string) string {
|
||||
p := bluemonday.NewPolicy()
|
||||
p.AllowElements("br", "img")
|
||||
p.AllowAttrs("style", "src", "alt", "width", "height", "loading").OnElements("img")
|
||||
return p.Sanitize(str)
|
||||
}
|
Reference in New Issue
Block a user