Skip to content
Snippets Groups Projects
Commit f779db4a authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Move SimpleSAML_Utilities::normalizeURL() to...

Move SimpleSAML_Utilities::normalizeURL() to SimpleSAML\Utils\HTTP::normalizeURL() and deprecate the former.
parent 712c56b9
Branches
Tags
No related merge requests found
...@@ -559,25 +559,10 @@ class SimpleSAML_Utilities { ...@@ -559,25 +559,10 @@ class SimpleSAML_Utilities {
/** /**
* Normalizes a URL to an absolute URL and validate it. * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Utils\HTTP::normalizeURL() instead.
*
* 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.
*/ */
public static function normalizeURL($url) { public static function normalizeURL($url) {
assert('is_string($url)'); return \SimpleSAML\Utils\HTTP::normalizeURL($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;
} }
......
...@@ -428,6 +428,35 @@ class HTTP ...@@ -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. * Parse a query string into an array.
* *
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
if (isset($_REQUEST['retryURL'])) { if (isset($_REQUEST['retryURL'])) {
$retryURL = (string)$_REQUEST['retryURL']; $retryURL = (string)$_REQUEST['retryURL'];
$retryURL = SimpleSAML_Utilities::normalizeURL($retryURL); $retryURL = \SimpleSAML\Utils\HTTP::normalizeURL($retryURL);
} else { } else {
$retryURL = NULL; $retryURL = NULL;
} }
......
...@@ -6,7 +6,7 @@ $config = SimpleSAML_Configuration::getInstance(); ...@@ -6,7 +6,7 @@ $config = SimpleSAML_Configuration::getInstance();
if(array_key_exists('link_href', $_REQUEST)) { if(array_key_exists('link_href', $_REQUEST)) {
$link = (string)$_REQUEST['link_href']; $link = (string)$_REQUEST['link_href'];
$link = SimpleSAML_Utilities::normalizeURL($link); $link = \SimpleSAML\Utils\HTTP::normalizeURL($link);
} else { } else {
$link = 'index.php'; $link = 'index.php';
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment