1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

refactor(sanitizer): make isValidAttribute() check O(1)

This commit is contained in:
Frédéric Guillot 2025-06-13 21:40:34 -07:00
parent 3538c4271b
commit b95c9023ee

View file

@ -18,71 +18,71 @@ import (
)
var (
allowedHTMLTagsAndAttributes = map[string][]string{
"a": {"href", "title", "id"},
"abbr": {"title"},
"acronym": {"title"},
allowedHTMLTagsAndAttributes = map[string]map[string]struct{}{
"a": {"href": {}, "title": {}, "id": {}},
"abbr": {"title": {}},
"acronym": {"title": {}},
"aside": {},
"audio": {"src"},
"audio": {"src": {}},
"blockquote": {},
"b": {},
"br": {},
"caption": {},
"cite": {},
"code": {},
"dd": {"id"},
"dd": {"id": {}},
"del": {},
"dfn": {},
"dl": {"id"},
"dt": {"id"},
"dl": {"id": {}},
"dt": {"id": {}},
"em": {},
"figcaption": {},
"figure": {},
"h1": {"id"},
"h2": {"id"},
"h3": {"id"},
"h4": {"id"},
"h5": {"id"},
"h6": {"id"},
"h1": {"id": {}},
"h2": {"id": {}},
"h3": {"id": {}},
"h4": {"id": {}},
"h5": {"id": {}},
"h6": {"id": {}},
"hr": {},
"iframe": {"width", "height", "frameborder", "src", "allowfullscreen"},
"img": {"alt", "title", "src", "srcset", "sizes", "width", "height", "fetchpriority", "decoding"},
"iframe": {"width": {}, "height": {}, "frameborder": {}, "src": {}, "allowfullscreen": {}},
"img": {"alt": {}, "title": {}, "src": {}, "srcset": {}, "sizes": {}, "width": {}, "height": {}, "fetchpriority": {}, "decoding": {}},
"ins": {},
"kbd": {},
"li": {"id"},
"ol": {"id"},
"li": {"id": {}},
"ol": {"id": {}},
"p": {},
"picture": {},
"pre": {},
"q": {"cite"},
"q": {"cite": {}},
"rp": {},
"rt": {},
"rtc": {},
"ruby": {},
"s": {},
"samp": {},
"source": {"src", "type", "srcset", "sizes", "media"},
"source": {"src": {}, "type": {}, "srcset": {}, "sizes": {}, "media": {}},
"strong": {},
"sub": {},
"sup": {"id"},
"sup": {"id": {}},
"table": {},
"td": {"rowspan", "colspan"},
"td": {"rowspan": {}, "colspan": {}},
"tfoot": {},
"th": {"rowspan", "colspan"},
"th": {"rowspan": {}, "colspan": {}},
"thead": {},
"time": {"datetime"},
"time": {"datetime": {}},
"tr": {},
"u": {},
"ul": {"id"},
"ul": {"id": {}},
"var": {},
"video": {"poster", "height", "width", "src"},
"video": {"poster": {}, "height": {}, "width": {}, "src": {}},
"wbr": {},
// MathML: https://w3c.github.io/mathml-core/ and https://developer.mozilla.org/en-US/docs/Web/MathML/Reference/Element
"annotation": {},
"annotation-xml": {},
"maction": {},
"math": {"xmlns"},
"math": {"xmlns": {}},
"merror": {},
"mfrac": {},
"mi": {},
@ -423,7 +423,8 @@ func isValidTag(tagName string) bool {
func isValidAttribute(tagName, attributeName string) bool {
if attributes, ok := allowedHTMLTagsAndAttributes[tagName]; ok {
return slices.Contains(attributes, attributeName)
_, allowed := attributes[attributeName]
return allowed
}
return false
}