Skip to content

Commit 939f509

Browse files
authored
Merge pull request SAML-Toolkits#323 from gitnik/master
Add ability to change regex for protocol check
2 parents 55d8278 + ededcba commit 939f509

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/Saml2/Utils.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class OneLogin_Saml2_Utils
3737
*/
3838
private static $_baseurlpath;
3939

40+
/**
41+
* @var string
42+
*/
43+
private static $_protocolRegex = '@^https?://@i';
4044

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

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

354+
/**
355+
* @var $protocolRegex string
356+
*/
357+
public static function setProtocolRegex($protocolRegex)
358+
{
359+
if (!empty($protocolRegex)) {
360+
self::$_protocolRegex = $protocolRegex;
361+
}
362+
}
363+
347364
/**
348365
* @param $baseurl string The base url to be used when constructing URLs
349366
*/

0 commit comments

Comments
 (0)