fix(web): img attributes sanitization - #742
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a web sanitization edge case where <img> dimension attributes were being stripped when a custom sanitizationConfig.linkRegex was supplied, ensures “broken image” styling also applies to images with missing/empty src, and adds regression tests to prevent reintroduction.
Changes:
- Treat
<img>width/heightas URI-safe attributes during DOMPurify sanitization so they survive customALLOWED_URI_REGEXPsettings. - Expand broken-image placeholder styling to cover
<img>elements with missing/emptysrc. - Add targeted sanitization regression tests and update the example web app’s sanitization regex.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/web/sanitization/htmlSanitizer.ts | Adds width/height to DOMPurify URI-safe attributes to avoid incorrect stripping under custom link regex. |
| src/web/EnrichedText.css | Applies broken-image placeholder styling when src is missing or empty. |
| src/web/tests/sanitization.test.ts | Adds regression tests for <img> sanitization behavior under default and custom linkRegex. |
| apps/example-web/src/components/TextRenderer.tsx | Updates example renderer’s sanitization regex to URL-only. |
| apps/example-web/src/App.tsx | Updates example app’s sanitization config link regex (but currently diverges from the editor’s linkRegex). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Is this correct behaviour that href attribute is stripped from a tag? Screen.Recording.2026-08-04.at.13.15.42.mov |
Good catch, now |
Summary
img'sheightandweightattributes whensanitizationConfig.linkRegexwas defined, as those attributes were tested as URIssrcis present in theimgelementsanitizationConfig.linkRegex[web] <img> tag attributes are ignored during HTML export #741Test Plan
add some images in the input and push them to the
EnrichedText- that will trigger sanitization. Everything should be at its placeCompatibility
Checklist