From b6f0cd01d349805d5861498df09aa4fb8b9ec53f Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 30 Oct 2022 18:44:23 +0100 Subject: [PATCH] Less HTML restrictions for local content --- app/templates.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/templates.py b/app/templates.py index 8d4e016..07c4708 100644 --- a/app/templates.py +++ b/app/templates.py @@ -291,6 +291,10 @@ ALLOWED_ATTRIBUTES: dict[str, list[str] | Callable[[str, str, str], bool]] = { } +def _allow_all_attributes(tag: Any, name: Any, value: Any) -> bool: + return True + + @lru_cache(maxsize=256) def _update_inline_imgs(content): soup = BeautifulSoup(content, "html5lib") @@ -320,7 +324,11 @@ def _clean_html(html: str, note: Object) -> str: _update_inline_imgs(highlight(html)) ), tags=ALLOWED_TAGS, - attributes=ALLOWED_ATTRIBUTES, + attributes=( + _allow_all_attributes + if note.ap_id.startswith(config.ID) + else ALLOWED_ATTRIBUTES + ), strip=True, ), note,