Skip to content

Commit 9183661

Browse files
authored
Security: prevent XSS attach on wiki page (#955)
Reported by Miguel Ángel Jimeno.
1 parent ab4eb0d commit 9183661

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

modules/templates/helper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strings"
1616
"time"
1717

18+
"github.com/microcosm-cc/bluemonday"
1819
"golang.org/x/net/html/charset"
1920
"golang.org/x/text/transform"
2021
"gopkg.in/editorconfig/editorconfig-core-go.v1"
@@ -61,6 +62,7 @@ func NewFuncMap() []template.FuncMap {
6162
},
6263
"AvatarLink": base.AvatarLink,
6364
"Safe": Safe,
65+
"Sanitize": bluemonday.UGCPolicy().Sanitize,
6466
"Str2html": Str2html,
6567
"TimeSince": base.TimeSince,
6668
"RawTimeSince": base.RawTimeSince,

templates/repo/wiki/view.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{template "base/head" .}}
22
<div class="repository wiki view">
33
{{template "repo/header" .}}
4+
{{ $title := .title | Sanitize}}
45
<div class="ui container">
56
<div class="ui grid">
67
<div class="ui ten wide column">
@@ -9,7 +10,7 @@
910
<div class="ui basic small button">
1011
<span class="text">
1112
{{.i18n.Tr "repo.wiki.page"}}:
12-
<strong>{{.title}}</strong>
13+
<strong>{{$title}}</strong>
1314
</span>
1415
<i class="dropdown icon"></i>
1516
</div>
@@ -20,7 +21,7 @@
2021
</div>
2122
<div class="scrolling menu">
2223
{{range .Pages}}
23-
<div class="item {{if eq $.Title .Name}}selected{{end}}" data-url="{{$.RepoLink}}/wiki/{{.URL}}">{{.Name}}</div>
24+
<div class="item {{if eq $.Title .Name}}selected{{end}}" data-url="{{$.RepoLink}}/wiki/{{.URL}}">{{.Name | Sanitize}}</div>
2425
{{end}}
2526
</div>
2627
</div>
@@ -51,7 +52,7 @@
5152
</div>
5253
</div>
5354
<div class="ui dividing header">
54-
{{.title}}
55+
{{$title}}
5556
{{if and .IsRepositoryWriter (not .Repository.IsMirror)}}
5657
<div class="ui right">
5758
<a class="ui small button" href="{{.RepoLink}}/wiki/{{EscapePound .PageURL}}/_edit">{{.i18n.Tr "repo.wiki.edit_page_button"}}</a>
@@ -76,7 +77,7 @@
7677
{{.i18n.Tr "repo.wiki.delete_page_button"}}
7778
</div>
7879
<div class="content">
79-
<p>{{.i18n.Tr "repo.wiki.delete_page_notice_1" .title | Safe}}</p>
80+
<p>{{.i18n.Tr "repo.wiki.delete_page_notice_1" $title | Safe}}</p>
8081
</div>
8182
{{template "base/delete_modal_actions" .}}
8283
</div>

0 commit comments

Comments
 (0)