Customizable whitelist of schemas for safeLinks

This commit is contained in:
naNuke 2015-01-25 19:47:32 +01:00
parent 0670c0f2be
commit 674f40278f

View File

@ -84,6 +84,14 @@ class Parsedown
protected $safeLinksEnabled = true; protected $safeLinksEnabled = true;
protected $safeLinksWhitelist = array(
'http://',
'https://',
'/',
'ftp://',
'ftps://'
);
# #
# Lines # Lines
# #
@ -1244,10 +1252,23 @@ class Parsedown
$Element['attributes']['title'] = $Definition['title']; $Element['attributes']['title'] = $Definition['title'];
} }
if ( $this->safeLinksEnabled && preg_match("/^(\/|https?:\/\/|ftps?:\/\/)/ui", $Element['attributes']['href']) === 0 ) if ( $this->safeLinksEnabled )
{
$matched = false;
foreach ( $this->safeLinksWhitelist as $scheme )
{
if ( stripos($Element['attributes']['href'], $scheme) === 0 )
{
$matched = true;
break;
}
}
if ( ! $matched )
{ {
return; return;
} }
}
$Element['attributes']['href'] = htmlspecialchars($Element['attributes']['href'], ENT_QUOTES); $Element['attributes']['href'] = htmlspecialchars($Element['attributes']['href'], ENT_QUOTES);
$Element['text'] = htmlspecialchars($Element['text'], ENT_QUOTES); $Element['text'] = htmlspecialchars($Element['text'], ENT_QUOTES);