fix(messages): allow data: protocol in bleach for base64 images + img width/height/style attrs
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Images pasted as base64 had their src stripped by bleach (only http/https allowed by default). Now data: protocol is whitelisted. Also allow width/height/style on img for resize support. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f793522ab4
commit
9e6af89ae4
@ -14,7 +14,8 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
# Allowed HTML tags and attributes for rich-text content (announcements, events, proceedings)
|
||||
_ALLOWED_TAGS = ['p', 'br', 'strong', 'em', 'b', 'i', 'a', 'ul', 'ol', 'li', 'h3', 'h4', 'blockquote', 'img']
|
||||
_ALLOWED_ATTRS = {'a': ['href', 'target', 'rel'], 'img': ['src', 'alt']}
|
||||
_ALLOWED_ATTRS = {'a': ['href', 'target', 'rel'], 'img': ['src', 'alt', 'width', 'height', 'style']}
|
||||
_ALLOWED_PROTOCOLS = ['http', 'https', 'data'] # data: for base64 inline images
|
||||
|
||||
|
||||
def sanitize_html(content):
|
||||
@ -30,7 +31,7 @@ def sanitize_html(content):
|
||||
"""
|
||||
if not content:
|
||||
return content
|
||||
return bleach.clean(content, tags=_ALLOWED_TAGS, attributes=_ALLOWED_ATTRS, strip=True)
|
||||
return bleach.clean(content, tags=_ALLOWED_TAGS, attributes=_ALLOWED_ATTRS, protocols=_ALLOWED_PROTOCOLS, strip=True)
|
||||
|
||||
|
||||
def linkify_urls(html):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user