Skip to content

Commit abd1381

Browse files
authored
Fix dart-lang/markdown#586: encode image tag's src attribute (dart-archive/markdown#589)
1 parent 523cade commit abd1381

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pkgs/markdown/lib/src/inline_syntaxes/image_syntax.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class ImageSyntax extends LinkSyntax {
2424
}) {
2525
final element = Element.empty('img');
2626
final children = getChildren();
27-
element.attributes['src'] = destination;
27+
element.attributes['src'] = normalizeLinkDestination(
28+
escapePunctuation(destination),
29+
);
2830
element.attributes['alt'] = children.map((node) {
2931
// See https://spec.commonmark.org/0.30/#image-description.
3032
// An image description may contain links. Fetch text from the alt

pkgs/markdown/test/original/inline_images.unit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@
1818

1919
<<<
2020
<p><img src="http://foo.com/foo.png" alt="alt" /></p>
21+
>>> XSS
22+
![Uh oh...]("onerror="alert('XSS'))
23+
24+
<<<
25+
<p><img src="%22onerror=%22alert('XSS')" alt="Uh oh..." /></p>

0 commit comments

Comments
 (0)