Skip to content

Commit 254bded

Browse files
Gustedearl-warren
authored andcommitted
fix: strict matching of allowed content for sanitizer
- _Simply_ add `^$` to regexp that didn't had it yet, this avoids any content being allowed that simply had the allowed content as a substring. - Fix file-preview regex to have `$` instead of `*`. (cherry picked from commit 7067cc7) v9: added fix for ref-issue, this is already fixed in forgejo branch but not backported as it was part of a feature.
1 parent a88e3e6 commit 254bded

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

modules/markup/sanitizer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ func createDefaultPolicy() *bluemonday.Policy {
9494
}
9595

9696
// Allow classes for anchors
97-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue( ref-external-issue)?`)).OnElements("a")
97+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^ref-issue( ref-external-issue)?$`)).OnElements("a")
9898

9999
// Allow classes for task lists
100-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`task-list-item`)).OnElements("li")
100+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^task-list-item$`)).OnElements("li")
101101

102102
// Allow classes for org mode list item status.
103103
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^(unchecked|checked|indeterminate)$`)).OnElements("li")
@@ -106,7 +106,7 @@ func createDefaultPolicy() *bluemonday.Policy {
106106
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^icon(\s+[\p{L}\p{N}_-]+)+$`)).OnElements("i")
107107

108108
// Allow classes for emojis
109-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`emoji`)).OnElements("img")
109+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^emoji$`)).OnElements("img")
110110

111111
// Allow icons, emojis, chroma syntax and keyword markup on span
112112
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji)|(language-math display)|(language-math inline))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$`)).OnElements("span")
@@ -122,13 +122,13 @@ func createDefaultPolicy() *bluemonday.Policy {
122122
policy.AllowAttrs("class").Matching(regexp.MustCompile("^header$")).OnElements("div")
123123
policy.AllowAttrs("data-line-number").Matching(regexp.MustCompile("^[0-9]+$")).OnElements("span")
124124
policy.AllowAttrs("class").Matching(regexp.MustCompile("^text small grey$")).OnElements("span")
125-
policy.AllowAttrs("class").Matching(regexp.MustCompile("^file-preview*")).OnElements("table")
125+
policy.AllowAttrs("class").Matching(regexp.MustCompile("^file-preview$")).OnElements("table")
126126
policy.AllowAttrs("class").Matching(regexp.MustCompile("^lines-escape$")).OnElements("td")
127127
policy.AllowAttrs("class").Matching(regexp.MustCompile("^toggle-escape-button btn interact-bg$")).OnElements("button")
128128
policy.AllowAttrs("title").OnElements("button")
129129
policy.AllowAttrs("class").Matching(regexp.MustCompile("^ambiguous-code-point$")).OnElements("span")
130130
policy.AllowAttrs("data-tooltip-content").OnElements("span")
131-
policy.AllowAttrs("class").Matching(regexp.MustCompile("muted|(text black)")).OnElements("a")
131+
policy.AllowAttrs("class").Matching(regexp.MustCompile("^muted|(text black)$")).OnElements("a")
132132
policy.AllowAttrs("class").Matching(regexp.MustCompile("^ui warning message tw-text-left$")).OnElements("div")
133133

134134
// Allow generally safe attributes

0 commit comments

Comments
 (0)