CVE-2015-10084 (PHP, published 2023-02-21T15:15Z)
Description: value: A vulnerability was found in irontec klear-library chloe and classified as critical. Affected by this issue is the function _prepareWhere of the file Controller/Rest/BaseController.php. The manipulation leads to sql injection. Upgrading to version marla is able to address this issue. The name of the patch is b25262de52fdaffde2a4434fc2a84408b304fbc5. It is recommended to upgrade the affected component. The identifier of this vulnerability is VDB-221504.
Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-89 \u2014 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
Repository: https://github.com/irontec/klear-library
Files changed:
Controller/Rest/BaseController.php
Commit message: Fix sql injection && Permitir la ejecución de sentencias sql complejas predefinidas en controladores REST vía Zend_Db_Expr


Vulnerable code:
            if (is_scalar($val)) {

        if (empty($itemsSearch)) {
            return '';
        }
        return implode(" AND ", $itemsSearch);
    }
                $values = $this->_cleanArray($val);

                $values = $this->_cleanArray($val);

                $values = $this->_cleanArray($val);

                $key = $dbAdapter->quoteIdentifier($key) . " like '%?%'";
                return $dbAdapter->quoteInto($key, $val);
                $key = $dbAdapter->quoteIdentifier($key) . " not like '%?%'";
                return $dbAdapter->quoteInto($key, $val);


Fixed code:
        return implode(" AND ", $this->_parseWhere($search));
    }
    protected function _parseWhere($search) 
    {
            if ($val instanceof \Zend_Db_Expr) {
                $itemsSearch[] = $val->__toString();
            } else if (is_scalar($val)) {
        return $itemsSearch;
    }   
            case 'notEqual':
                $key = $dbAdapter->quoteIdentifier($key) . " != ?";
                return $dbAdapter->quoteInto($key, current($val));
                break;

            case 'isnull':
                return $dbAdapter->quoteIdentifier($key) . " is null";
                break;

            case 'isnotnull':
                return $dbAdapter->quoteIdentifier($key) . " is null";
                break;

            case 'gt':
                $key = $dbAdapter->quoteIdentifier($key) . " > ?";
                return $dbAdapter->quoteInto($key, current($val));
                break;

            case 'gte':
                $key = $dbAdapter->quoteIdentifier($key) . " >= ?";
                return $dbAdapter->quoteInto($key, current($val));
                break;
                
            case 'lt':
                $key = $dbAdapter->quoteIdentifier($key) . " < ?";
                return $dbAdapter->quoteInto($key, current($val));
                break;

            case 'lte':
                $key = $dbAdapter->quoteIdentifier($key) . " <= ?";
                return $dbAdapter->quoteInto($key, current($val));
                break;
                
                $values = $this->_cleanArray(current($val));
                $values = $this->_cleanArray(current($val));
                $values = $this->_cleanArray(current($val));
                $key = $dbAdapter->quoteIdentifier($key) . " like ?";
                return $dbAdapter->quoteInto($key, current($val));
                $key = $dbAdapter->quoteIdentifier($key) . " not like ?";
                return $dbAdapter->quoteInto($key, current($val));
                break;
            case 'or':
                $conditions = array();
                foreach ($val as $subKey => $subVal) {
                    $conditions += $this->_parseWhere($subVal);
                }
                return '('. implode(' OR ', $conditions) .')';