1
2
3
4
5
6
7
8
9
10
11
12
13
|
package html
import "github.com/microcosm-cc/bluemonday"
func PreventXSS(html string) string {
var policy = bluemonday.NewPolicy()
policy.AllowStandardURLs()
policy.AllowAttrs("href").OnElements("a")
policy.AllowElements("p")
policy.AllowElements("div")
policy.AllowAttrs("src").OnElements("img")
return policy.Sanitize(html)
}
|