diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index d7b57bf47410fbea4b31ce183dc4410fd20d421e..c0522f0587c55581a3c170c9d4198c564c3d2e32 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -559,25 +559,10 @@ class SimpleSAML_Utilities { /** - * Normalizes a URL to an absolute URL and validate it. - * - * In addition to resolving the URL, this function makes sure that it is - * a link to a http or https site. - * - * @param string $url The relative URL. - * @return string An absolute URL for the given relative URL. + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::normalizeURL() instead. */ public static function normalizeURL($url) { - assert('is_string($url)'); - - $url = SimpleSAML_Utilities::resolveURL($url, SimpleSAML_Utilities::selfURL()); - - /* Verify that the URL is to a http or https site. */ - if (!preg_match('@^https?://@i', $url)) { - throw new SimpleSAML_Error_Exception('Invalid URL: ' . $url); - } - - return $url; + return \SimpleSAML\Utils\HTTP::normalizeURL($url); } diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php index d39e519516ef877605637cc03c55496a0b6012f9..ec3f9ce70998975f2f7a42c5523bfad692b18b24 100644 --- a/lib/SimpleSAML/Utils/HTTP.php +++ b/lib/SimpleSAML/Utils/HTTP.php @@ -428,6 +428,35 @@ class HTTP } + /** + * Normalizes a URL to an absolute URL and validate it. In addition to resolving the URL, this function makes sure + * that it is a link to an http or https site. + * + * @param string $url The relative URL. + * + * @return string An absolute URL for the given relative URL. + * @throws \SimpleSAML_Error_Exception If $url is not a string or a valid URL. + * + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + * @author Jaime Perez, UNINETT AS <jaime.perez@uninett.no> + */ + public static function normalizeURL($url) + { + if (!is_string($url)) { + throw new \SimpleSAML_Error_Exception('Invalid input parameters.'); + } + + $url = self::resolveURL($url, self::getSelfURL()); + + // verify that the URL is to a http or https site + if (!preg_match('@^https?://@i', $url)) { + throw new \SimpleSAML_Error_Exception('Invalid URL: '.$url); + } + + return $url; + } + + /** * Parse a query string into an array. * diff --git a/modules/core/www/no_cookie.php b/modules/core/www/no_cookie.php index a81055a8b77fc344fefbdd30ab8f98571be68afa..36aad7a1d292625f33eff1437bcfcc366182eaa8 100644 --- a/modules/core/www/no_cookie.php +++ b/modules/core/www/no_cookie.php @@ -2,7 +2,7 @@ if (isset($_REQUEST['retryURL'])) { $retryURL = (string)$_REQUEST['retryURL']; - $retryURL = SimpleSAML_Utilities::normalizeURL($retryURL); + $retryURL = \SimpleSAML\Utils\HTTP::normalizeURL($retryURL); } else { $retryURL = NULL; } diff --git a/www/logout.php b/www/logout.php index 53942535eab8b7d1aa4ee3b941cc65ba18bdcce2..c361b29ec25326721834fcdc47c81268201089ac 100644 --- a/www/logout.php +++ b/www/logout.php @@ -6,7 +6,7 @@ $config = SimpleSAML_Configuration::getInstance(); if(array_key_exists('link_href', $_REQUEST)) { $link = (string)$_REQUEST['link_href']; - $link = SimpleSAML_Utilities::normalizeURL($link); + $link = \SimpleSAML\Utils\HTTP::normalizeURL($link); } else { $link = 'index.php'; }