From 67c3efbea0d33c4433c6b18ed163b45c01395867 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 9 May 2017 19:37:13 +0100 Subject: [PATCH] according to https://tools.ietf.org/html/rfc3986#section-3 the colon is a required part of the syntax, other methods of achieving the colon character (as to browser interpretation) should be taken care of by htmlencoding that is done on all attribute content --- Parsedown.php | 9 +-------- test/data/xss_bad_url.html | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index c540d12..110d6e3 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -1554,14 +1554,7 @@ class Parsedown } } - $Element['attributes'][$attribute] = preg_replace_callback( - '/[^\/#?&=%]++/', - function (array $match) - { - return urlencode($match[0]); - }, - $Element['attributes'][$attribute] - ); + $Element['attributes'][$attribute] = str_replace(':', '%3A', $Element['attributes'][$attribute]); return $Element; } diff --git a/test/data/xss_bad_url.html b/test/data/xss_bad_url.html index 8e43877..0b216d1 100644 --- a/test/data/xss_bad_url.html +++ b/test/data/xss_bad_url.html @@ -1,16 +1,16 @@ -

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

-

xss

\ No newline at end of file +

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

+

xss

\ No newline at end of file