Skip to content

Commit 134f3e6

Browse files
unknwonbkcsoft
authored andcommitted
Security: prevent XSS attach on wiki page
Reported by Miguel Ángel Jimeno.
1 parent 43c94d0 commit 134f3e6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
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: 6 additions & 5 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>
@@ -50,8 +51,8 @@
5051
</div>
5152
</div>
5253
</div>
53-
<div class="ui header">
54-
{{.title}}
54+
<div class="ui dividing header">
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>
@@ -95,7 +96,7 @@
9596
{{.i18n.Tr "repo.wiki.delete_page_button"}}
9697
</div>
9798
<div class="content">
98-
<p>{{.i18n.Tr "repo.wiki.delete_page_notice_1" .title | Safe}}</p>
99+
<p>{{.i18n.Tr "repo.wiki.delete_page_notice_1" $title | Safe}}</p>
99100
</div>
100101
{{template "base/delete_modal_actions" .}}
101102
</div>

0 commit comments

Comments
 (0)