From f779db4aa8af91977835d92868016ff669a89192 Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 21 Apr 2015 14:17:55 +0200 Subject: [PATCH] Move SimpleSAML_Utilities::normalizeURL() to SimpleSAML\Utils\HTTP::normalizeURL() and deprecate the former. --- lib/SimpleSAML/Utilities.php | 19 ++----------------- lib/SimpleSAML/Utils/HTTP.php | 29 +++++++++++++++++++++++++++++ modules/core/www/no_cookie.php | 2 +- www/logout.php | 2 +- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index d7b57bf47..c0522f058 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 d39e51951..ec3f9ce70 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 a81055a8b..36aad7a1d 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 53942535e..c361b29ec 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'; } -- GitLab