Skip to content

Instantly share code, notes, and snippets.

@imadphp
Created March 11, 2019 13:36
Show Gist options
  • Save imadphp/688c7bd301117f820e3a091f3524f3ce to your computer and use it in GitHub Desktop.
Save imadphp/688c7bd301117f820e3a091f3524f3ce to your computer and use it in GitHub Desktop.
A patch to fix SQLi vulnerability in Magestore Store Locator module and Magento addExpressionFieldToSelect() method
diff --git a/vendor/magestore/storepickup/app/code/Magestore/Storepickup/Model/ResourceModel/Store/Collection.php b/vendor/magestore/storepickup/app/code/Magestore/Storepickup/Model/ResourceModel/Store/Collection.php
index 5a48b364a..87a855904 100644
--- a/vendor/magestore/storepickup/app/code/Magestore/Storepickup/Model/ResourceModel/Store/Collection.php
+++ b/vendor/magestore/storepickup/app/code/Magestore/Storepickup/Model/ResourceModel/Store/Collection.php
@@ -106,8 +106,8 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
*/
public function addLatLngToFilterDistance($lat, $lng, $distance = null)
{
- $expression = "(1609.34*((acos(sin(({{lat}}*pi()/180)) * sin((`{{latitude}}`*pi()/180))+cos(($lat *pi()/180)) * cos((`{{latitude}}`*pi()/180)) * cos((({{lng}} - `{{longitude}}`)*pi()/180))))*180/pi())*60*1.1515)";
- $this->addExpressionFieldToSelect('distance', $expression, ['latitude' => 'latitude', 'longitude' => 'longitude', 'lat' => $lat, 'lng' => $lng]);
+ $expression = "(1609.34*((acos(sin(({{lat}}*pi()/180)) * sin((`latitude`*pi()/180))+cos(({{lat}} *pi()/180)) * cos((`latitude`*pi()/180)) * cos((({{lng}} - `longitude`)*pi()/180))))*180/pi())*60*1.1515)";
+ $this->addExpressionFieldToSelect('distance', $expression, ['lat' => $lat, 'lng' => $lng]);
if ($distance) {
$this->getSelect()->having('distance <= ?', $distance);
diff --git a/vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.php b/vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.php
index b57755ed7..4cff648c9 100644
--- a/vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.php
+++ b/vendor/magento/framework/Model/ResourceModel/Db/Collection/AbstractCollection.php
@@ -343,7 +343,8 @@ abstract class AbstractCollection extends AbstractDb implements SourceProviderIn
$fullExpression = $expression;
foreach ($fields as $fieldKey => $fieldItem) {
- $fullExpression = str_replace('{{' . $fieldKey . '}}', $fieldItem, $fullExpression);
+ $quotedFieldItem = $this->getConnection()->quote($fieldItem);
+ $fullExpression = str_replace('{{' . $fieldKey . '}}', $quotedFieldItem, $fullExpression);
}
$this->getSelect()->columns([$alias => $fullExpression]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment