Skip to content

Commit

Permalink
Merge pull request #1274 from bradjones1/uri
Browse files Browse the repository at this point in the history
Use league/uri for true URI validation
  • Loading branch information
Sephster authored Apr 6, 2022
2 parents 8c2fa79 + d56a5b3 commit 2795c48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"php": "^7.2 || ^8.0",
"ext-openssl": "*",
"league/event": "^2.2",
"league/uri": "^6",
"lcobucci/jwt": "^3.4.6 || ^4.0.4",
"psr/http-message": "^1.0.1",
"defuse/php-encryption": "^2.2.1",
Expand Down
13 changes: 7 additions & 6 deletions src/RedirectUriValidators/RedirectUriValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace League\OAuth2\Server\RedirectUriValidators;

use League\Uri\Uri;

class RedirectUriValidator implements RedirectUriValidatorInterface
{
/**
Expand Down Expand Up @@ -59,10 +61,10 @@ public function validateRedirectUri($redirectUri)
*/
private function isLoopbackUri($redirectUri)
{
$parsedUrl = \parse_url($redirectUri);
$uri = Uri::createFromString($redirectUri);

return $parsedUrl['scheme'] === 'http'
&& (\in_array($parsedUrl['host'], ['127.0.0.1', '[::1]'], true));
return $uri->getScheme() === 'http'
&& (\in_array($uri->getHost(), ['127.0.0.1', '[::1]'], true));
}

/**
Expand Down Expand Up @@ -106,9 +108,8 @@ private function matchUriExcludingPort($redirectUri)
*/
private function parseUrlAndRemovePort($url)
{
$parsedUrl = \parse_url($url);
unset($parsedUrl['port']);
$uri = Uri::createFromString($url);

return $parsedUrl;
return (string) $uri->withPort(null);
}
}

0 comments on commit 2795c48

Please sign in to comment.