mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Move tags & attributes lists to constants.py
This commit is contained in:
parent
de7d4ad957
commit
806d35bc68
@ -69,3 +69,27 @@ CSV_DELIMITERS = {
|
|||||||
'semicolon': ';',
|
'semicolon': ';',
|
||||||
'tab': '\t',
|
'tab': '\t',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# HTML allowed tags & attributes
|
||||||
|
#
|
||||||
|
|
||||||
|
HTML_ALLOWED_TAGS = {
|
||||||
|
"a", "b", "blockquote", "br", "code", "dd", "del", "div", "dl", "dt", "em", "h1", "h2", "h3", "h4", "h5", "h6",
|
||||||
|
"hr", "i", "img", "li", "ol", "p", "pre", "strong", "table", "tbody", "td", "th", "thead", "tr", "ul"
|
||||||
|
}
|
||||||
|
|
||||||
|
HTML_ALLOWED_ATTRIBUTES = {
|
||||||
|
"a": {"href", "title"},
|
||||||
|
"div": {"class"},
|
||||||
|
"h1": {"id"},
|
||||||
|
"h2": {"id"},
|
||||||
|
"h3": {"id"},
|
||||||
|
"h4": {"id"},
|
||||||
|
"h5": {"id"},
|
||||||
|
"h6": {"id"},
|
||||||
|
"img": {"alt", "src", "title"},
|
||||||
|
"td": {"align"},
|
||||||
|
"th": {"align"},
|
||||||
|
}
|
||||||
|
@ -24,6 +24,7 @@ from netbox.config import get_config
|
|||||||
from netbox.plugins import PluginConfig
|
from netbox.plugins import PluginConfig
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from utilities.constants import HTTP_REQUEST_META_SAFE_COPY
|
from utilities.constants import HTTP_REQUEST_META_SAFE_COPY
|
||||||
|
from .constants import HTML_ALLOWED_ATTRIBUTES, HTML_ALLOWED_TAGS
|
||||||
|
|
||||||
|
|
||||||
def title(value):
|
def title(value):
|
||||||
@ -511,29 +512,10 @@ def clean_html(html, schemes):
|
|||||||
Sanitizes HTML based on a whitelist of allowed tags and attributes.
|
Sanitizes HTML based on a whitelist of allowed tags and attributes.
|
||||||
Also takes a list of allowed URI schemes.
|
Also takes a list of allowed URI schemes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ALLOWED_TAGS = {
|
|
||||||
"div", "pre", "code", "blockquote", "del",
|
|
||||||
"hr", "h1", "h2", "h3", "h4", "h5", "h6",
|
|
||||||
"ul", "ol", "li", "p", "br",
|
|
||||||
"strong", "em", "a", "b", "i", "img",
|
|
||||||
"table", "thead", "tbody", "tr", "th", "td",
|
|
||||||
"dl", "dt", "dd",
|
|
||||||
}
|
|
||||||
|
|
||||||
ALLOWED_ATTRIBUTES = {
|
|
||||||
"div": {'class'},
|
|
||||||
"h1": {"id"}, "h2": {"id"}, "h3": {"id"}, "h4": {"id"}, "h5": {"id"}, "h6": {"id"},
|
|
||||||
"a": {"href", "title"},
|
|
||||||
"img": {"src", "title", "alt"},
|
|
||||||
"th": {"align"},
|
|
||||||
"td": {"align"},
|
|
||||||
}
|
|
||||||
|
|
||||||
return nh3.clean(
|
return nh3.clean(
|
||||||
html,
|
html,
|
||||||
tags=ALLOWED_TAGS,
|
tags=HTML_ALLOWED_TAGS,
|
||||||
attributes=ALLOWED_ATTRIBUTES,
|
attributes=HTML_ALLOWED_ATTRIBUTES,
|
||||||
url_schemes=set(schemes)
|
url_schemes=set(schemes)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user