Skip to content
Snippets Groups Projects
Commit d1ff132d authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo
Browse files

Use parse_url() instead of preg_match() to check URLs.

parent f0c5c824
No related branches found
No related tags found
No related merge requests found
......@@ -338,14 +338,15 @@ class HTTP
// validates the URL's host is among those allowed
if (is_array($trustedSites)) {
assert(is_array($trustedSites));
preg_match('@^http(s?)://([^/:]+)((?::\d+)?)@i', $url, $matches);
$hostname = $matches[2];
$components = parse_url($url);
$hostname = $components['host'];
// allow URLs with standard ports specified (non-standard ports must then be allowed explicitly)
if (!empty($matches[3]) &&
(($matches[1] === '' && $matches[3] !== ':80') || ($matches[1]) === 's' && $matches[3] !== ':443')
if (isset($components['port']) &&
(($components['scheme'] === 'http' && $components['port'] !== 80) ||
($components['scheme'] === 'https' && $components['port'] !== 443))
) {
$hostname = $hostname.$matches[3];
$hostname = $hostname.':'.$components['port'];
}
$self_host = self::getSelfHostWithNonStandardPort();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment