Skip to content

Check image URL schemes in safe mode - #766

Closed
aliassar wants to merge 1 commit into
trentm:masterfrom
aliassar:fix-safe-mode-image-src-764
Closed

aliassar wants to merge 1 commit into
trentm:masterfrom
aliassar:fix-safe-mode-image-src-764

Conversation

@aliassar

@aliassar aliassar commented Nov 4, 2026

Copy link
Copy Markdown

In safe mode, links whose URL fails _safe_href get href="#", but image sources were never checked, so ![x](javascript:alert(1)) rendered <img src="javascript:alert(1)">. process_image now runs the same check and falls back to #, like links do. Base64 data:image/... URLs still work since data_urls_in_safe_mode relies on them, but only when the payload is plain base64: before, a code span in one could break out of src (![](data:image/png;base64,x" onerror="alert(1)//)). Anything links already reject now gives src="#" too, including other data: URLs, URLs with spaces or ', and an empty ![alt](), so I updated the src values in four existing XSS fixtures and added image_safe_urls.

Fixes #764

safe_mode replaces unsafe link hrefs with '#', but image src values
were passed through unchecked, so ![x](javascript:...) produced an
img tag with a javascript: src. Apply the same _safe_href check in
LinkProcessor.process_image. Base64 image data URLs stay allowed, but
only with a plain base64 payload, so a code span can't break out of
the src attribute.

Fixes trentm#764

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aliassar
aliassar force-pushed the fix-safe-mode-image-src-764 branch from 8dea2da to 6fcf20b Compare November 4, 2026 19:31
@Crozzers

Crozzers commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Here we go again.

Mentioned in #744, duplicate of #714 and discussed in #712.

Please ask your AI agent to check for existing closed issues/PRs before raising a new one

@aliassar aliassar closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] safe_mode bypass: javascript: scheme allowed in image src

2 participants