diff --git a/lib/markdown2.py b/lib/markdown2.py
index 66d49a69..6c18f3bb 100755
--- a/lib/markdown2.py
+++ b/lib/markdown2.py
@@ -3229,6 +3229,8 @@ 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")
+ if self.md.safe_mode and not self.md._safe_href.match(url):
+ url = ''
result = (
f'})
![xss]()
+
+![xss]()
+
+![xss]()
+
+
+
+
diff --git a/test/tm-cases/img_safe_mode_xss.opts b/test/tm-cases/img_safe_mode_xss.opts
new file mode 100644
index 00000000..ad487c04
--- /dev/null
+++ b/test/tm-cases/img_safe_mode_xss.opts
@@ -0,0 +1 @@
+{"safe_mode": "escape"}
diff --git a/test/tm-cases/img_safe_mode_xss.text b/test/tm-cases/img_safe_mode_xss.text
new file mode 100644
index 00000000..a13a1fa7
--- /dev/null
+++ b/test/tm-cases/img_safe_mode_xss.text
@@ -0,0 +1,9 @@
+)
+
+)
+
+)
+
+
+
+