From 8e384ce46c69b0e90168094f64e2ad6c787f4cbb Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 20 Jan 2015 13:08:49 +0800 Subject: [PATCH] fix #828, may cause unintentional break in other features, but security is no.1 --- .gopmfile | 2 +- gogs.go | 2 +- modules/base/template.go | 9 ++++++--- templates/.VERSION | 2 +- templates/repo/issue/milestone.tmpl | 2 +- templates/repo/issue/view.tmpl | 4 ++-- templates/repo/release/list.tmpl | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gopmfile b/.gopmfile index bb49c70475..b405e813d0 100644 --- a/.gopmfile +++ b/.gopmfile @@ -23,10 +23,10 @@ github.com/macaron-contrib/oauth2 = commit:8f394c3629 github.com/macaron-contrib/session = github.com/macaron-contrib/toolbox = commit:57127bcc89 github.com/mattn/go-sqlite3 = commit:a80c27ba33 +github.com/microcosm-cc/bluemonday = github.com/nfnt/resize = commit:8f44931448 github.com/russross/blackfriday = commit:05b8cefd6a github.com/shurcooL/go = commit:48293cbc7a -github.com/saintfish/chardet = commit:3af4cd4741 gopkg.in/ini.v1 = commit:28ad8c408b gopkg.in/redis.v2 = commit:e617904962 diff --git a/gogs.go b/gogs.go index 6b8978f2f7..5711452d7c 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.11.0103 Beta" +const APP_VER = "0.5.12.0120 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/base/template.go b/modules/base/template.go index d96617c05f..829999d1c9 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -13,15 +13,19 @@ import ( "strings" "time" + "github.com/microcosm-cc/bluemonday" "golang.org/x/net/html/charset" "golang.org/x/text/transform" - "github.com/gogits/gogs/modules/setting" "github.com/gogits/chardet" + "github.com/gogits/gogs/modules/setting" ) +// FIXME: use me to Markdown API renders +var p = bluemonday.UGCPolicy() + func Str2html(raw string) template.HTML { - return template.HTML(raw) + return template.HTML(p.Sanitize(raw)) } func Range(l int) []int { @@ -113,7 +117,6 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" }, "AvatarLink": AvatarLink, - "str2html": Str2html, // TODO: Legacy "Str2html": Str2html, "TimeSince": TimeSince, "FileSize": FileSize, diff --git a/templates/.VERSION b/templates/.VERSION index 3146279bd0..36f8bef5b7 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.11.0103 Beta \ No newline at end of file +0.5.12.0120 Beta \ No newline at end of file diff --git a/templates/repo/issue/milestone.tmpl b/templates/repo/issue/milestone.tmpl index 8a5751c19b..8fc3c25347 100644 --- a/templates/repo/issue/milestone.tmpl +++ b/templates/repo/issue/milestone.tmpl @@ -32,7 +32,7 @@ Issues


-

{{.RenderedContent | str2html}}

+

{{.RenderedContent | Str2html}}

{{end}} diff --git a/templates/repo/issue/view.tmpl b/templates/repo/issue/view.tmpl index 738e0c3450..31231515fc 100644 --- a/templates/repo/issue/view.tmpl +++ b/templates/repo/issue/view.tmpl @@ -25,7 +25,7 @@
- {{str2html .Issue.RenderedContent}} + {{Str2html .Issue.RenderedContent}}