From 8cff413c4deccc6f3476b5dec6ea55b551f13c5d Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 15 Apr 2026 23:30:49 +0200 Subject: [PATCH] Clean atributes as well in clean_string `` womp womp --- cps/clean_html.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cps/clean_html.py b/cps/clean_html.py index 3436f43a5..06c3ee8a6 100644 --- a/cps/clean_html.py +++ b/cps/clean_html.py @@ -36,7 +36,12 @@ def clean_string(unsafe_text, book_id=0): if bleach: allowed_tags = list(ALLOWED_TAGS) allowed_tags.extend(["p", "span", "div", "pre", "br", "h1", "h2", "h3", "h4", "h5", "h6", "img"]) - safe_text = clean_html(unsafe_text, tags=set(allowed_tags)) + allowed_attributes = { + "*": ["class", "style"], + "a": ["href", "title", "rel"], + "img": ["src", "alt", "title", "width", "height"], + } + safe_text = clean_html(unsafe_text, tags=set(allowed_tags), attributes=allowed_attributes) else: safe_text = clean_html(unsafe_text) except ParserError as e: