Skip to content
Snippets Groups Projects
Unverified Commit b07cd267 authored by totten's avatar totten Committed by GitHub
Browse files

Merge pull request #25446 from lemniscus/oauth-reduce-dns-queries

Reduce unneeded DNS queries during OAuth flow
parents 4d752e26 eaf712b4
No related branches found
No related tags found
No related merge requests found
......@@ -91,20 +91,19 @@ class AuthorizationCode extends AbstractGrantAction {
parent::validate();
if ($this->landingUrl) {
$landingUrlParsed = parse_url($this->landingUrl);
$landingUrlIp = gethostbyname($landingUrlParsed['host']);
$landingUrlIp = gethostbyname($landingUrlParsed['host'] . '.');
$allowedBases = [
\Civi::paths()->getVariable('cms.root', 'url'),
\Civi::paths()->getVariable('civicrm.root', 'url'),
];
$ok = max(array_map(function($allowed) use ($landingUrlParsed, $landingUrlIp) {
foreach ($allowedBases as $allowed) {
$allowedParsed = parse_url($allowed);
$allowedIp = gethostbyname($allowedParsed['host']);
$ok = $landingUrlIp === $allowedIp && $landingUrlParsed['scheme'] == $allowedParsed['scheme'];
return (int) $ok;
}, $allowedBases));
if (!$ok) {
throw new OAuthException("Cannot initiate OAuth. Unsupported landing URL.");
$allowedIp = gethostbyname($allowedParsed['host'] . '.');
if ($landingUrlIp === $allowedIp && $landingUrlParsed['scheme'] == $allowedParsed['scheme']) {
return;
}
}
throw new OAuthException("Cannot initiate OAuth. Unsupported landing URL.");
}
}
......
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