Repository navigation
Conversation
Image tags () in safe_mode do not validate the URL against _safe_href, unlike anchor tags which do. This allows javascript:, vbscript:, and other dangerous URL schemes through in <img src> attributes when safe_mode is enabled. Apply the same _safe_href check used for anchors to image src URLs, replacing the URL with an empty string when it fails validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| ''' | ||
| 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 = '' |
There was a problem hiding this comment.
For links URLs are set to "#" if replaced by safe mode. Should be consistent here
|
@Crozzers You think we should bail on this one? |
|
@nicholasserra I have mixed feelings. I did say it "can't hurt to have this" on the other PR. However, the issue this PR addresses isn't a real issue - that was debunked previously. Plus it adds complexity and slowdowns to an already complex safe mode implementation. I think as well, we should look at this in the context of what's going on at the moment. This repo, for whatever reason, has suddenly attracted the attention of tourist "vibe coders" and has seen a deluge of PRs. The pros and cons of this situation can be debated, and I think any debate on AI contributions should probably happen in its own issue/thread, but its alot of code to review. I know I'm not keeping up with it. I think given the volume of PRs at the moment, and that most of the code is mass produced by AI, I would err on the side of rejecting unnecessary changes. |
Summary
) insafe_modedo not validate the URL against_safe_href, unlike anchor tags which dojavascript:,vbscript:, and other dangerous URL schemes through in<img src>attributes_safe_hrefcheck to image src URLs, replacing the URL with empty string when validation failsReproduction
Test plan
tm-cases/img_safe_mode_xss) coveringjavascript:,JavaScript:,vbscript:(blocked) andhttps:, relative paths (allowed)