diff --git a/lib/Entity/DataSet.php b/lib/Entity/DataSet.php index 482a57be35..e263eadb6a 100644 --- a/lib/Entity/DataSet.php +++ b/lib/Entity/DataSet.php @@ -1,8 +1,8 @@ blackList, '', htmlspecialchars_decode($column->formula, ENT_QUOTES)); + $count = 0; + $formula = str_ireplace( + $this->blackList, + '', + htmlspecialchars_decode($column->formula, ENT_QUOTES), + $count + ); + + if ($count > 0) { + $this->getLog()->error( + 'Formula contains disallowed keywords on DataSet ID ' . $this->dataSetId + ); + continue; + } + $formula = str_replace('[DisplayId]', $displayId, $formula); $heading = str_replace('[DisplayGeoLocation]', $displayGeoLocation, $formula) . ' AS `' . $column->heading . '`'; diff --git a/lib/Entity/DataSetColumn.php b/lib/Entity/DataSetColumn.php index d05c933b90..c95e9b7b0f 100644 --- a/lib/Entity/DataSetColumn.php +++ b/lib/Entity/DataSetColumn.php @@ -1,6 +1,6 @@ dataSetColumnTypeId == 2 && $this->formula != '' && substr($this->formula, 0, 1) !== '$') { try { - $formula = str_replace('[DisplayId]', 0, $this->formula); + $count = 0; + $formula = str_ireplace( + $this->blackList, + '', + htmlspecialchars_decode($this->formula, ENT_QUOTES), + $count + ); + + if ($count > 0) { + throw new InvalidArgumentException(__('Formula contains disallowed keywords.')); + } + + $formula = str_replace('[DisplayId]', 0, $formula); // replace DisplayGeoLocation with default CMS location, just to validate here. $formula = str_replace('[DisplayGeoLocation]', "GEOMFROMTEXT('POINT(51.504 -0.104)')", $formula); $this->getStore()->select('SELECT * FROM (SELECT `id`, ' . $formula . ' AS `' . $this->heading . '` FROM `dataset_' . $this->dataSetId . '`) dataset WHERE 1 = 1 ', [], 'isolated');