mirror of
https://github.com/nkanaev/yarr.git
synced 2025-11-07 18:09:36 +00:00
423 lines
5.6 KiB
Go
423 lines
5.6 KiB
Go
package sanitizer
|
|
|
|
type set struct {
|
|
m map[string]bool
|
|
}
|
|
|
|
func sset(vals []string) set {
|
|
m := make(map[string]bool)
|
|
for _, val := range vals {
|
|
m[val] = true
|
|
}
|
|
return set{m: m}
|
|
}
|
|
|
|
func (s *set) has(val string) bool {
|
|
_, ok := s.m[val]
|
|
return ok
|
|
}
|
|
|
|
// taken from: https://github.com/cure53/DOMPurify/blob/e1c19cf6/src/tags.js
|
|
var allowedTags = sset([]string{
|
|
"a",
|
|
"abbr",
|
|
"acronym",
|
|
"address",
|
|
"area",
|
|
"article",
|
|
"aside",
|
|
"audio",
|
|
"b",
|
|
"bdi",
|
|
"bdo",
|
|
"big",
|
|
"blink",
|
|
"blockquote",
|
|
"body",
|
|
"br",
|
|
"button",
|
|
"canvas",
|
|
"caption",
|
|
"center",
|
|
"cite",
|
|
"code",
|
|
"col",
|
|
"colgroup",
|
|
"content",
|
|
"data",
|
|
"datalist",
|
|
"dd",
|
|
"decorator",
|
|
"del",
|
|
"details",
|
|
"dfn",
|
|
"dialog",
|
|
"dir",
|
|
"div",
|
|
"dl",
|
|
"dt",
|
|
"element",
|
|
"em",
|
|
"fieldset",
|
|
"figcaption",
|
|
"figure",
|
|
"font",
|
|
"footer",
|
|
"form",
|
|
"h1",
|
|
"h2",
|
|
"h3",
|
|
"h4",
|
|
"h5",
|
|
"h6",
|
|
"head",
|
|
"header",
|
|
"hgroup",
|
|
"hr",
|
|
"html",
|
|
"i",
|
|
"iframe",
|
|
"img",
|
|
"input",
|
|
"ins",
|
|
"kbd",
|
|
"label",
|
|
"legend",
|
|
"li",
|
|
"main",
|
|
"map",
|
|
"mark",
|
|
"marquee",
|
|
"menu",
|
|
"menuitem",
|
|
"meter",
|
|
"nav",
|
|
"nobr",
|
|
"ol",
|
|
"optgroup",
|
|
"option",
|
|
"output",
|
|
"p",
|
|
"picture",
|
|
"pre",
|
|
"progress",
|
|
"q",
|
|
"rp",
|
|
"rt",
|
|
"ruby",
|
|
"s",
|
|
"samp",
|
|
"section",
|
|
"select",
|
|
"shadow",
|
|
"small",
|
|
"source",
|
|
"spacer",
|
|
"span",
|
|
"strike",
|
|
"strong",
|
|
"sub",
|
|
"summary",
|
|
"sup",
|
|
"table",
|
|
"tbody",
|
|
"td",
|
|
"template",
|
|
"textarea",
|
|
"tfoot",
|
|
"th",
|
|
"thead",
|
|
"time",
|
|
"tr",
|
|
"track",
|
|
"tt",
|
|
"u",
|
|
"ul",
|
|
"var",
|
|
"video",
|
|
"wbr",
|
|
})
|
|
|
|
var allowedSvgTags = sset([]string{
|
|
"svg",
|
|
"a",
|
|
"altglyph",
|
|
"altglyphdef",
|
|
"altglyphitem",
|
|
"animatecolor",
|
|
"animatemotion",
|
|
"animatetransform",
|
|
"circle",
|
|
"clippath",
|
|
"defs",
|
|
"desc",
|
|
"ellipse",
|
|
"filter",
|
|
"font",
|
|
"g",
|
|
"glyph",
|
|
"glyphref",
|
|
"hkern",
|
|
"image",
|
|
"line",
|
|
"lineargradient",
|
|
"marker",
|
|
"mask",
|
|
"metadata",
|
|
"mpath",
|
|
"path",
|
|
"pattern",
|
|
"polygon",
|
|
"polyline",
|
|
"radialgradient",
|
|
"rect",
|
|
"stop",
|
|
//"style",
|
|
"switch",
|
|
"symbol",
|
|
"text",
|
|
"textpath",
|
|
"title",
|
|
"tref",
|
|
"tspan",
|
|
"view",
|
|
"vkern",
|
|
})
|
|
|
|
var allowedSvgFilters = sset([]string{
|
|
"feBlend",
|
|
"feColorMatrix",
|
|
"feComponentTransfer",
|
|
"feComposite",
|
|
"feConvolveMatrix",
|
|
"feDiffuseLighting",
|
|
"feDisplacementMap",
|
|
"feDistantLight",
|
|
"feFlood",
|
|
"feFuncA",
|
|
"feFuncB",
|
|
"feFuncG",
|
|
"feFuncR",
|
|
"feGaussianBlur",
|
|
"feMerge",
|
|
"feMergeNode",
|
|
"feMorphology",
|
|
"feOffset",
|
|
"fePointLight",
|
|
"feSpecularLighting",
|
|
"feSpotLight",
|
|
"feTile",
|
|
"feTurbulence",
|
|
})
|
|
|
|
var allowedAttrs = map[string]set{
|
|
"img": sset([]string{"alt", "title", "src", "srcset", "sizes"}),
|
|
"audio": sset([]string{"src"}),
|
|
"video": sset([]string{"poster", "height", "width", "src"}),
|
|
"source": sset([]string{"src", "type", "srcset", "sizes", "media"}),
|
|
"td": sset([]string{"rowspan", "colspan"}),
|
|
"th": sset([]string{"rowspan", "colspan"}),
|
|
"q": sset([]string{"cite"}),
|
|
"a": sset([]string{"href", "title"}),
|
|
"time": sset([]string{"datetime"}),
|
|
"abbr": sset([]string{"title"}),
|
|
"acronym": sset([]string{"title"}),
|
|
"iframe": sset([]string{"width", "height", "frameborder", "src", "allowfullscreen"}),
|
|
}
|
|
|
|
var allowedSvgAttrs = sset([]string{
|
|
"accent-height",
|
|
"accumulate",
|
|
"additive",
|
|
"alignment-baseline",
|
|
"ascent",
|
|
"attributename",
|
|
"attributetype",
|
|
"azimuth",
|
|
"basefrequency",
|
|
"baseline-shift",
|
|
"begin",
|
|
"bias",
|
|
"by",
|
|
"class",
|
|
"clip",
|
|
"clippathunits",
|
|
"clip-path",
|
|
"clip-rule",
|
|
"color",
|
|
"color-interpolation",
|
|
"color-interpolation-filters",
|
|
"color-profile",
|
|
"color-rendering",
|
|
"cx",
|
|
"cy",
|
|
"d",
|
|
"dx",
|
|
"dy",
|
|
"diffuseconstant",
|
|
"direction",
|
|
"display",
|
|
"divisor",
|
|
"dur",
|
|
"edgemode",
|
|
"elevation",
|
|
"end",
|
|
"fill",
|
|
"fill-opacity",
|
|
"fill-rule",
|
|
"filter",
|
|
"filterunits",
|
|
"flood-color",
|
|
"flood-opacity",
|
|
"font-family",
|
|
"font-size",
|
|
"font-size-adjust",
|
|
"font-stretch",
|
|
"font-style",
|
|
"font-variant",
|
|
"font-weight",
|
|
"fx",
|
|
"fy",
|
|
"g1",
|
|
"g2",
|
|
"glyph-name",
|
|
"glyphref",
|
|
"gradientunits",
|
|
"gradienttransform",
|
|
"height",
|
|
"href",
|
|
"id",
|
|
"image-rendering",
|
|
"in",
|
|
"in2",
|
|
"k",
|
|
"k1",
|
|
"k2",
|
|
"k3",
|
|
"k4",
|
|
"kerning",
|
|
"keypoints",
|
|
"keysplines",
|
|
"keytimes",
|
|
"lang",
|
|
"lengthadjust",
|
|
"letter-spacing",
|
|
"kernelmatrix",
|
|
"kernelunitlength",
|
|
"lighting-color",
|
|
"local",
|
|
"marker-end",
|
|
"marker-mid",
|
|
"marker-start",
|
|
"markerheight",
|
|
"markerunits",
|
|
"markerwidth",
|
|
"maskcontentunits",
|
|
"maskunits",
|
|
"max",
|
|
"mask",
|
|
"media",
|
|
"method",
|
|
"mode",
|
|
"min",
|
|
"name",
|
|
"numoctaves",
|
|
"offset",
|
|
"operator",
|
|
"opacity",
|
|
"order",
|
|
"orient",
|
|
"orientation",
|
|
"origin",
|
|
"overflow",
|
|
"paint-order",
|
|
"path",
|
|
"pathlength",
|
|
"patterncontentunits",
|
|
"patterntransform",
|
|
"patternunits",
|
|
"points",
|
|
"preservealpha",
|
|
"preserveaspectratio",
|
|
"primitiveunits",
|
|
"r",
|
|
"rx",
|
|
"ry",
|
|
"radius",
|
|
"refx",
|
|
"refy",
|
|
"repeatcount",
|
|
"repeatdur",
|
|
"restart",
|
|
"result",
|
|
"rotate",
|
|
"scale",
|
|
"seed",
|
|
"shape-rendering",
|
|
"specularconstant",
|
|
"specularexponent",
|
|
"spreadmethod",
|
|
"startoffset",
|
|
"stddeviation",
|
|
"stitchtiles",
|
|
"stop-color",
|
|
"stop-opacity",
|
|
"stroke-dasharray",
|
|
"stroke-dashoffset",
|
|
"stroke-linecap",
|
|
"stroke-linejoin",
|
|
"stroke-miterlimit",
|
|
"stroke-opacity",
|
|
"stroke",
|
|
"stroke-width",
|
|
//"style",
|
|
"surfacescale",
|
|
"systemlanguage",
|
|
"tabindex",
|
|
"targetx",
|
|
"targety",
|
|
"transform",
|
|
"text-anchor",
|
|
"text-decoration",
|
|
"text-rendering",
|
|
"textlength",
|
|
"type",
|
|
"u1",
|
|
"u2",
|
|
"unicode",
|
|
"values",
|
|
"viewbox",
|
|
"visibility",
|
|
"version",
|
|
"vert-adv-y",
|
|
"vert-origin-x",
|
|
"vert-origin-y",
|
|
"width",
|
|
"word-spacing",
|
|
"wrap",
|
|
"writing-mode",
|
|
"xchannelselector",
|
|
"ychannelselector",
|
|
"x",
|
|
"x1",
|
|
"x2",
|
|
"xmlns",
|
|
"y",
|
|
"y1",
|
|
"y2",
|
|
"z",
|
|
"zoomandpan",
|
|
})
|
|
|
|
var allowedURISchemes = sset([]string{
|
|
"http",
|
|
"https",
|
|
"ftp",
|
|
"ftps",
|
|
"tel",
|
|
"mailto",
|
|
"callto",
|
|
"cid",
|
|
"xmpp",
|
|
})
|