瀏覽代碼

Extract HTML sanitizer to its own file

master
Simon Ser 4 年之前
父節點
當前提交
8d248bc32f
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: FDE7BE0E88F5E48
共有 2 個文件被更改,包括 19 次插入7 次删除
  1. +1
    -7
      plugins/base/routes.go
  2. +18
    -0
      plugins/base/sanitize_html.go

+ 1
- 7
plugins/base/routes.go 查看文件

@@ -16,7 +16,6 @@ import (
"github.com/emersion/go-message"
"github.com/emersion/go-smtp"
"github.com/labstack/echo/v4"
"github.com/microcosm-cc/bluemonday"
)

func registerRoutes(p *koushin.GoPlugin) {
@@ -246,12 +245,7 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {

isHTML := false
if strings.EqualFold(mimeType, "text/html") {
p := bluemonday.UGCPolicy()
// TODO: be more strict
p.AllowElements("style")
p.AllowAttrs("style")
p.AddTargetBlankToFullyQualifiedLinks(true)
body = p.Sanitize(body)
body = sanitizeHTML(body)
isHTML = true
}



+ 18
- 0
plugins/base/sanitize_html.go 查看文件

@@ -0,0 +1,18 @@
package koushinbase

import (
"github.com/microcosm-cc/bluemonday"
)

func sanitizeHTML(b string) string {
p := bluemonday.UGCPolicy()

// TODO: be more strict
p.AllowElements("style")
p.AllowAttrs("style")

p.AddTargetBlankToFullyQualifiedLinks(true)
p.RequireNoFollowOnLinks(true)

return p.Sanitize(b)
}

Loading…
取消
儲存