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