diff --git a/lib/markdown2.py b/lib/markdown2.py index 8dd1c48e..ae2b9702 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -3111,8 +3111,17 @@ def process_image(self, url: str, title_attr: str, link_text: str) -> Tuple[str, This section will be skipped by the link processor ''' img_class_str = self.md._html_class_str_from_tag("img") + safe_src = self.md._protect_url(url) + if self.md.safe_mode: + # Defense-in-depth: strip schemes that are never valid for an image + # `src` and only serve as XSS vectors. `data:` images, http(s) and + # relative URLs are preserved (and quote-escaped by `_protect_url`), + # matching markdown2's existing image handling. + normalized = re.sub(r"[\s\x00-\x1f]+", "", url).lower() + if normalized.startswith(("javascript:", "vbscript:")): + safe_src = "" result = ( - f'