Skip to content

Commit

Permalink
Better check for valid URLs (matomo-org#13572)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab authored and InfinityVoid committed Oct 11, 2018
1 parent 0b4656e commit 8c6e7cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public static function getLossyUrl($url)
public static function isLookLikeUrl($url)
{
return preg_match('~^(([[:alpha:]][[:alnum:]+.-]*)?:)?//(.*)$~D', $url, $matches) !== 0
&& strlen($matches[3]) > 0;
&& strlen($matches[3]) > 0
&& !in_array($matches[1], array('javascript:', 'vbscript:', 'data:'))
;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPUnit/Unit/UrlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function getUrls()
array('http://', false),
array(' http://', false),
array('2fer://', false),
array('javascript://test.com/test', false),
array('javascript://alert', false),
array('vbscript://alert', false),
array('vbscript://alert', false),
array('data://example.com/test', false),
);
}

Expand Down

0 comments on commit 8c6e7cb

Please sign in to comment.