Skip to content

Commit

Permalink
Merge pull request #323 from gitnik/master
Browse files Browse the repository at this point in the history
Add ability to change regex for protocol check
  • Loading branch information
pitbulk authored Jun 17, 2018
2 parents 55d8278 + ededcba commit 939f509
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/Saml2/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class OneLogin_Saml2_Utils
*/
private static $_baseurlpath;

/**
* @var string
*/
private static $_protocolRegex = '@^https?://@i';

/**
* Translates any string. Accepts args
Expand Down Expand Up @@ -296,8 +300,11 @@ public static function redirect($url, $parameters = array(), $stay = false)
$url = self::getSelfURLhost() . $url;
}

/* Verify that the URL is to a http or https site. */
$wrongProtocol = !preg_match('@^https?://@i', $url);
/**
* Verify that the URL matches the regex for the protocol.
* By default this will check for http and https
*/
$wrongProtocol = !preg_match(self::$_protocolRegex, $url);
$url = filter_var($url, FILTER_VALIDATE_URL);
if ($wrongProtocol || empty($url)) {
throw new OneLogin_Saml2_Error(
Expand Down Expand Up @@ -344,6 +351,16 @@ public static function redirect($url, $parameters = array(), $stay = false)
exit();
}

/**
* @var $protocolRegex string
*/
public static function setProtocolRegex($protocolRegex)
{
if (!empty($protocolRegex)) {
self::$_protocolRegex = $protocolRegex;
}
}

/**
* @param $baseurl string The base url to be used when constructing URLs
*/
Expand Down

0 comments on commit 939f509

Please sign in to comment.