|
|
|
@ -50,12 +50,44 @@ func ReplaceSanitizer() {
|
|
|
|
|
// Allow keyword markup
|
|
|
|
|
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^` + keywordClass + `$`)).OnElements("span")
|
|
|
|
|
|
|
|
|
|
// Allow <kbd> tags for keyboard shortcut styling
|
|
|
|
|
sanitizer.policy.AllowElements("kbd")
|
|
|
|
|
|
|
|
|
|
// Allow classes for anchors
|
|
|
|
|
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue`)).OnElements("a")
|
|
|
|
|
|
|
|
|
|
// Allow generally safe attributes
|
|
|
|
|
generalSafeAttrs := []string{"abbr", "accept", "accept-charset",
|
|
|
|
|
"accesskey", "action", "align", "alt",
|
|
|
|
|
"aria-describedby", "aria-hidden", "aria-label", "aria-labelledby",
|
|
|
|
|
"axis", "border", "cellpadding", "cellspacing", "char",
|
|
|
|
|
"charoff", "charset", "checked",
|
|
|
|
|
"clear", "cols", "colspan", "color",
|
|
|
|
|
"compact", "coords", "datetime", "dir",
|
|
|
|
|
"disabled", "enctype", "for", "frame",
|
|
|
|
|
"headers", "height", "hreflang",
|
|
|
|
|
"hspace", "ismap", "label", "lang",
|
|
|
|
|
"maxlength", "media", "method",
|
|
|
|
|
"multiple", "name", "nohref", "noshade",
|
|
|
|
|
"nowrap", "open", "prompt", "readonly", "rel", "rev",
|
|
|
|
|
"rows", "rowspan", "rules", "scope",
|
|
|
|
|
"selected", "shape", "size", "span",
|
|
|
|
|
"start", "summary", "tabindex", "target",
|
|
|
|
|
"title", "type", "usemap", "valign", "value",
|
|
|
|
|
"vspace", "width", "itemprop",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generalSafeElements := []string{
|
|
|
|
|
"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "br", "b", "i", "strong", "em", "a", "pre", "code", "img", "tt",
|
|
|
|
|
"div", "ins", "del", "sup", "sub", "p", "ol", "ul", "table", "thead", "tbody", "tfoot", "blockquote",
|
|
|
|
|
"dl", "dt", "dd", "kbd", "q", "samp", "var", "hr", "ruby", "rt", "rp", "li", "tr", "td", "th", "s", "strike", "summary",
|
|
|
|
|
"details", "caption", "figure", "figcaption",
|
|
|
|
|
"abbr", "bdo", "cite", "dfn", "mark", "small", "span", "time", "wbr",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sanitizer.policy.AllowAttrs(generalSafeAttrs...).OnElements(generalSafeElements...)
|
|
|
|
|
|
|
|
|
|
sanitizer.policy.AllowAttrs("itemscope", "itemtype").OnElements("div")
|
|
|
|
|
|
|
|
|
|
// FIXME: Need to handle longdesc in img but there is no easy way to do it
|
|
|
|
|
|
|
|
|
|
// Custom keyword markup
|
|
|
|
|
for _, rule := range setting.ExternalSanitizerRules {
|
|
|
|
|
if rule.Regexp != nil {
|
|
|
|
|