1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-13 13:08:19 +00:00

[backport] fix sanitation (#1646)

* Santiation fix from Gogs

- Add code-injection checks

* Fix SSH-breakage
This commit is contained in:
Kim "BKC" Carlbäcker
2017-04-30 11:55:16 +02:00
committed by Lunny Xiao
parent 2482c67e2b
commit 473df53533
7 changed files with 115 additions and 27 deletions

View File

@@ -15,7 +15,6 @@ import (
"strings"
"github.com/Unknwon/com"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday"
"golang.org/x/net/html"
@@ -29,24 +28,6 @@ const (
IssueNameStyleAlphanumeric = "alphanumeric"
)
// Sanitizer markdown sanitizer
var Sanitizer = bluemonday.UGCPolicy()
// BuildSanitizer initializes sanitizer with allowed attributes based on settings.
// This function should only be called once during entire application lifecycle.
func BuildSanitizer() {
// Normal markdown-stuff
Sanitizer.AllowAttrs("class").Matching(regexp.MustCompile(`[\p{L}\p{N}\s\-_',:\[\]!\./\\\(\)&]*`)).OnElements("code", "div", "ul", "ol", "dl")
// Checkboxes
Sanitizer.AllowAttrs("type").Matching(regexp.MustCompile(`^checkbox$`)).OnElements("input")
Sanitizer.AllowAttrs("checked", "disabled").OnElements("input")
Sanitizer.AllowNoAttrs().OnElements("label")
// Custom URL-Schemes
Sanitizer.AllowURLSchemes(setting.Markdown.CustomURLSchemes...)
}
// IsMarkdownFile reports whether name looks like a Markdown file
// based on its extension.
func IsMarkdownFile(name string) bool {
@@ -708,7 +689,7 @@ func render(rawBytes []byte, urlPrefix string, metas map[string]string, isWikiMa
urlPrefix = strings.Replace(urlPrefix, " ", "+", -1)
result := RenderRaw(rawBytes, urlPrefix, isWikiMarkdown)
result = PostProcess(result, urlPrefix, metas, isWikiMarkdown)
result = Sanitizer.SanitizeBytes(result)
result = SanitizeBytes(result)
return result
}