Skip to content

Commit

Permalink
Merge pull request #25446 from lemniscus/oauth-reduce-dns-queries
Browse files Browse the repository at this point in the history
Reduce unneeded DNS queries during OAuth flow
  • Loading branch information
totten authored Feb 21, 2023
2 parents 4d752e2 + eaf712b commit b07cd26
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,19 @@ protected function validate() {
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.");
}
}

Expand Down

0 comments on commit b07cd26

Please sign in to comment.