Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Fix policy: add "tag" element from alexandrie syntax, organize file, add new elements

Smaug6739df85f711a6cf
diff --git a/backend/utils/escape-html.go b/backend/utils/escape-html.go
index 55544692..74110566 100644
--- a/backend/utils/escape-html.go
+++ b/backend/utils/escape-html.go
@@ -6,10 +6,41 @@ import (
var policy *bluemonday.Policy
+// InitBluemonday initializes the sanitization policy for user-generated content (UGC).
+// The policy allows safe HTML elements, attributes, and MathML/KaTeX elements while preventing XSS.
func InitBluemonday() {
policy = bluemonday.UGCPolicy()
+ policy.AllowDataAttributes()
+
+ // -------------------------------
+ // ALLOW HTML ELEMENTS
+ // -------------------------------
+ // Text formatting
+ policy.AllowElements("b", "i", "u", "strong", "em", "small", "mark")
+ policy.AllowElements("br", "hr")
+
+ // Lists
+ policy.AllowElements("ul", "ol", "li", "dl", "dt", "dd")
+
+ // Tables
+ policy.AllowElements("table", "thead", "tbody", "tfoot", "tr", "th", "td")
+
+ // Code / preformatted
+ policy.AllowElements("code", "pre")
+
+ // Blockquote
+ policy.AllowElements("blockquote")
+
+ // Forms (use with caution)
+ policy.AllowElements("input", "textarea", "button", "label", "select", "option", "fieldset", "legend")
+
+ // Multimedia
+ policy.AllowElements("audio", "video")
+
+ // Custom elements for frontend rendering
+ policy.AllowElements("tag")
- // Autoriser les éléments KaTeX / MathML
+ // KaTeX / MathML
policy.AllowElements(
"math", "maction", "annotation", "annotation-xml",
"menclose", "merror",
@@ -19,20 +50,42 @@ func InitBluemonday() {
"mspace", "msqrt", "mstyle", "msub", "msup",
"msubsup", "mtable", "mtd", "mtext", "mtr",
"mtimes", "munder", "munderover",
-
- "div", "span", "svg", "path", "g", "style", "line", "polygon", "polyline", "rect", "circle", "ellipse", "text",
- "input", "label", "form", "button", "select", "option", "textarea", "fieldset", "legend",
- "audio", "video",
)
- // Autoriser les attributs nécessaires
- policy.AllowAttrs("class", "id", "style", "tabindex", "aria-hidden", "display", "xmlns", "encoding", "accent", "width", "height", "type").Globally()
- policy.AllowAttrs("viewBox", "xmlns", "fill-rule", "d", "x", "y", "cx", "cy", "r", "rx", "ry", "points").OnElements("svg", "path", "line", "polygon", "polyline", "rect", "circle", "ellipse", "text")
- policy.AllowAttrs("href").OnElements("a")
+ // SVG elements for math/graphics
+ policy.AllowElements("svg", "path", "line", "polygon", "polyline", "rect", "circle", "ellipse", "text", "g", "style")
+
+ // -------------------------------
+ // ALLOW ATTRIBUTES
+ // -------------------------------
+ // Global attributes
+ policy.AllowAttrs(
+ "class", "id", "style", "tabindex", "aria-hidden", "display",
+ "xmlns", "encoding", "accent", "width", "height", "type", "title",
+ ).Globally()
+
+ // Custom color attributes (safe, never interpreted as HTML/JS)
+ policy.AllowAttrs(
+ "grey", "blue", "red", "green", "yellow", "purple", "orange", "teal", "pink", "primary",
+ ).Globally()
+
+ // SVG-specific attributes
+ policy.AllowAttrs(
+ "viewBox", "fill-rule", "d", "x", "y", "cx", "cy", "r", "rx", "ry", "points",
+ ).OnElements("svg", "path", "line", "polygon", "polyline", "rect", "circle", "ellipse", "text")
+
+ // Links
+ policy.AllowAttrs("href", "rel").OnElements("a")
+
+ // Form attributes
policy.AllowAttrs("checked").OnElements("input")
- policy.AllowDataAttributes()
+
+ // Disable automatic rel="nofollow"
policy.RequireNoFollowOnLinks(false)
+ // -------------------------------
+ // ELEMENTS THAT MUST HAVE NO ATTRIBUTES
+ // -------------------------------
policy.AllowNoAttrs().OnElements(
"math", "maction", "annotation", "annotation-xml",
"menclose", "merror",
@@ -45,7 +98,7 @@ func InitBluemonday() {
)
}
-// Utilisation
+// EscapeHTML sanitizes user input to prevent XSS attacks
func EscapeHTML(input string) string {
return policy.Sanitize(input)
}