mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-17 14:00:01 +02:00
Sanitation fix from Gogs (#1461)
* Santiation fix from Gogs * Linting * Fix build-errors * still not working * Fix all the things! * gofmt * Add code-injection checks
This commit is contained in:
parent
21290d4e80
commit
d409d3ab57
7 changed files with 118 additions and 27 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue