Skip to content

Commit

Permalink
[SECURITY] Prevent possible SQL injection through IpAddress GET param…
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed May 28, 2023
1 parent 28c55ba commit d80eb99
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Classes/Domain/Service/IpToCountry/LocalDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ protected function getCountryCodeFromIpInDatabase(string $ipAddress): string
{
$connection = DatabaseUtility::getConnectionForTable(self::TABLE_NAME);
$sql = 'select countryCode from ' . self::TABLE_NAME
. ' where inet_aton("' . $ipAddress . '") >= inet_aton(ipRangeStart)' .
' and inet_aton("' . $ipAddress . '") <= inet_aton(ipRangeEnd) limit 1';
. ' where inet_aton("' . $this->sanitizeIpAddress($ipAddress) . '") >= inet_aton(ipRangeStart)' .
' and inet_aton("' . $this->sanitizeIpAddress($ipAddress) . '") <= inet_aton(ipRangeEnd) limit 1';
$result = (string)$connection->query($sql)->fetchColumn(0);
return strtolower($result);
}

protected function sanitizeIpAddress(string $ipAddress): string
{
return preg_replace('~[^0-9\.]~', '', $ipAddress);
}
}

0 comments on commit d80eb99

Please sign in to comment.