Skip to content

Commit 61f8b24

Browse files
committed
Add HTML sanitization of the filename for the "file not found" page
This fixes an XSS issue, ref https://security.snyk.io/vuln/SNYK-GOLANG-GITHUBCOMXYPROTOALGERNONTHEMES-3312112
1 parent 216a73e commit 61f8b24

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

themes/html.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"bytes"
77
"fmt"
88
"strings"
9+
10+
"github.com/microcosm-cc/bluemonday"
911
)
1012

1113
const (
@@ -148,7 +150,11 @@ func InsertDoctype(htmldata []byte) []byte {
148150
return htmldata
149151
}
150152

151-
// NoPage provides the same functionality as NoPage, but returns []byte
153+
// NoPage generates a HTML page for when a file is not found
152154
func NoPage(filename, theme string) []byte {
153-
return MessagePageBytes("Not found", []byte("File not found: "+filename), theme)
155+
// Sanitize the filename
156+
policy := bluemonday.UGCPolicy()
157+
sanitizedFilename := policy.Sanitize(filename)
158+
// Return a HTML page
159+
return MessagePageBytes("Not found", []byte("File not found: "+sanitizedFilename), theme)
154160
}

0 commit comments

Comments
 (0)