CVE-2023-28108: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: Pimcore is an open source data and experience management platform. Prior to version 10.5.19, quoting is not done properly in UUID DAO model. There is the theoretical possibility to inject custom SQL if the developer is using this methods with input data and not doing proper input validation in advance and so relies on the auto-quoting being done by the DAO class. Users should update to version 10.5.19 to receive a patch or, as a workaround, apply the patch manually.
CWE description: 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.
CVSS v3 base score: 7.8
Published: 2023-03-16T17:15Z
Repository: https://github.com/pimcore/pimcore
Language: PHP
Files changed: models/Tool/UUID/Dao.php
Commit date: 2023-03-15 16:24:56 +0100
Commit message: [Task] Optimized get by UUID (#14633)

* fix: unify uuid queries

* replaced query with queryBuilder

---------

Co-authored-by: ChristianFeldkirchne <christian.feldkirchner@pimcore.com>
Diff: diff --git a/models/Tool/UUID/Dao.php b/models/Tool/UUID/Dao.php
index a8b0305f26e3..c3bb0f067cde 100644
--- a/models/Tool/UUID/Dao.php
+++ b/models/Tool/UUID/Dao.php
@@ -13,10 +13,11 @@
  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  */
 
 namespace Pimcore\Model\Tool\UUID;
 
+use Doctrine\DBAL\Types\Types;
 use Pimcore\Db\Helper;
 use Pimcore\Model;
 
 /**
  * @internal
@@ -78,11 +79,21 @@ class Dao extends Model\Dao\AbstractDao
      *
      * @return Model\Tool\UUID
      */
     public function getByUuid($uuid)
     {
-        $data = $this->db->fetchAssociative('SELECT * FROM ' . self::TABLE_NAME ." where uuid='" . $uuid . "'");
+        $queryBuilder = $this->db->createQueryBuilder();
+        $queryBuilder
+            ->select('*')
+            ->from(self::TABLE_NAME)
+            ->where('uuid = :uuid')
+            ->setParameter('uuid', $uuid, Types::STRING);
+
+        $data = $queryBuilder
+            ->execute()
+            ->fetchAssociative();
+
         $model = new Model\Tool\UUID();
         $model->setValues($data);
 
         return $model;
     }
@@ -92,8 +103,20 @@ class Dao extends Model\Dao\AbstractDao
      *
      * @return bool
      */
     public function exists($uuid)
     {
-        return (bool) $this->db->fetchOne('SELECT uuid FROM ' . self::TABLE_NAME . ' where uuid = ?', [$uuid]);
+        $queryBuilder = $this->db->createQueryBuilder();
+        $queryBuilder
+            ->select('uuid')
+            ->from(self::TABLE_NAME)
+            ->where('uuid = :uuid')
+            ->setParameter('uuid', $uuid, Types::STRING);
+
+
+        $result = $queryBuilder
+            ->execute()
+            ->fetchOne();
+
+        return (bool) $result;
     }
 }

Vulnerable code:         $data = $this->db->fetchAssociative('SELECT * FROM ' . self::TABLE_NAME ." where uuid='" . $uuid . "'");
        return (bool) $this->db->fetchOne('SELECT uuid FROM ' . self::TABLE_NAME . ' where uuid = ?', [$uuid]);
Fixed code: use Doctrine\DBAL\Types\Types;
        $queryBuilder = $this->db->createQueryBuilder();
        $queryBuilder
            ->select('*')
            ->from(self::TABLE_NAME)
            ->where('uuid = :uuid')
            ->setParameter('uuid', $uuid, Types::STRING);

        $data = $queryBuilder
            ->execute()
            ->fetchAssociative();

        $queryBuilder = $this->db->createQueryBuilder();
        $queryBuilder
            ->select('uuid')
            ->from(self::TABLE_NAME)
            ->where('uuid = :uuid')
            ->setParameter('uuid', $uuid, Types::STRING);


        $result = $queryBuilder
            ->execute()
            ->fetchOne();

        return (bool) $result;