Skip to content

Commit 578c02d

Browse files
authored
Improve some sanitizer rules (#32534)
This is a backport-only fix for 1.22 1.23 has a proper fix #32533
1 parent 6555cfc commit 578c02d

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: modules/markup/asciicast/asciicast.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const (
3939
// SanitizerRules implements markup.Renderer
4040
func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
4141
return []setting.MarkupSanitizerRule{
42-
{Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile(playerClassName)},
42+
{Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile("^" + playerClassName + "$")},
4343
{Element: "div", AllowAttr: playerSrcAttr},
4444
}
4545
}

Diff for: modules/markup/csv/csv.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func (Renderer) Extensions() []string {
3737
// SanitizerRules implements markup.Renderer
3838
func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
3939
return []setting.MarkupSanitizerRule{
40-
{Element: "table", AllowAttr: "class", Regexp: regexp.MustCompile(`data-table`)},
41-
{Element: "th", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
42-
{Element: "td", AllowAttr: "class", Regexp: regexp.MustCompile(`line-num`)},
40+
{Element: "table", AllowAttr: "class", Regexp: regexp.MustCompile(`^data-table$`)},
41+
{Element: "th", AllowAttr: "class", Regexp: regexp.MustCompile(`^line-num$`)},
42+
{Element: "td", AllowAttr: "class", Regexp: regexp.MustCompile(`^line-num$`)},
4343
}
4444
}
4545

Diff for: modules/markup/sanitizer_default.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
6767
}
6868

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

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

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

8181
// Allow classes for emojis
82-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`emoji`)).OnElements("img")
82+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^emoji$`)).OnElements("img")
8383

8484
// Allow icons, emojis, chroma syntax and keyword markup on span
8585
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")

0 commit comments

Comments
 (0)