Skip to content

fix(utils): correctly escape image target in markdown#19259

Merged
nijel merged 1 commit into
WeblateOrg:mainfrom
nijel:md
Apr 27, 2026
Merged

fix(utils): correctly escape image target in markdown#19259
nijel merged 1 commit into
WeblateOrg:mainfrom
nijel:md

Conversation

@nijel

@nijel nijel commented Apr 27, 2026

Copy link
Copy Markdown
Member

Do not assume mistletoe doing sanitization, do it before calling it.

Do not assume mistletoe doing sanitization, do it before calling it.
@nijel nijel added this to the 5.17.1 milestone Apr 27, 2026
@nijel nijel self-assigned this Apr 27, 2026
@nijel nijel requested a review from Copilot April 27, 2026 13:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Weblate’s Markdown renderer by ensuring image src URLs are escaped before being interpolated into generated HTML, rather than relying on the Markdown library to do the right thing. This aligns with the existing “safer renderer” goal of preventing attribute injection via crafted Markdown.

Changes:

  • Escape image src URLs when rendering <img> tags to prevent attribute injection.
  • Add regression tests covering malicious link/image targets and correct escaping of image titles/alt text.
  • Document the behavior change in the 5.17.1 changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
weblate/utils/markdown.py Escapes image URLs before emitting <img src="..."> HTML.
weblate/utils/tests/test_markdown.py Adds test cases for URL attribute-injection attempts and escaping behavior; switches non-DB tests to SimpleTestCase.
docs/changes.rst Notes the security/escaping behavior change in the release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nijel nijel enabled auto-merge (rebase) April 27, 2026 13:47
@argos-ci

argos-ci Bot commented Apr 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 23 changed Apr 27, 2026, 2:33 PM

@nijel nijel merged commit 85abc9d into WeblateOrg:main Apr 27, 2026
56 of 58 checks passed
@nijel nijel deleted the md branch April 27, 2026 14:50
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.

2 participants