CVE-2015-10077: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: A vulnerability was found in webbuilders-group silverstripe-kapost-bridge 0.3.3. It has been declared as critical. Affected by this vulnerability is the function index/getPreview of the file code/control/KapostService.php. The manipulation leads to sql injection. The attack can be launched remotely. Upgrading to version 0.4.0 is able to address this issue. The patch is named 2e14b0fd0ea35034f90890f364b130fb4645ff35. It is recommended to upgrade the affected component. The associated identifier of this vulnerability is VDB-220471.
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: 9.8
Published: 2023-02-10T15:15Z
Repository: https://github.com/webbuilders-group/silverstripe-kapost-bridge
Language: PHP
Files changed: code/control/KapostService.php
Commit date: 2015-10-13 16:24:35 -0300
Commit message: Fixed potential sql injection points
Diff: diff --git a/code/control/KapostService.php b/code/control/KapostService.php
index 5dd8905..3302e31 100644
--- a/code/control/KapostService.php
+++ b/code/control/KapostService.php
@@ -119,15 +119,15 @@ class KapostService extends Controller implements PermissionProvider {
      * Handles rendering of the preview for an object
      * @return {string} Response to send to the object
      */
     public function preview() {
         $auth=$this->request->getVar('auth');
-        $token=KapostPreviewToken::get()->filter('Code', Convert::raw2xml($auth))->first();
+        $token=KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
         
         //Verify the token exists and hasn't expired yet
         if(!empty($token) && $token!==false && $token->exists() && time()-strtotime($token->Created)<self::config()->preview_expiry*60 && $token->KapostRefID==$this->urlParams['ID']) {
-            $kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2xml($this->urlParams['ID']))->sort('"Created" DESC')->first();
+            $kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
             if(!empty($kapostObj) && $kapostObj!==false && $kapostObj->exists()) {
                 $previewController=$kapostObj->renderPreview();
                 
                 $this->extend('updatePreviewDisplay', $kapostObj, $previewController);
                 
@@ -732,20 +732,20 @@ class KapostService extends Controller implements PermissionProvider {
             }
         }
         
         
         //Detect if the record already exists or not so we can decide whether to create a new record or edit an existing
-        $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2xml($content_id))->first();
+        $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
         if(!empty($existing) && $existing!==false && $existing->exists()) {
             $resultID=$content_id;
             
             $this->editPost($content_id, $content, false, true);
         }else {
             $resultID=$this->newPost($blog_id, $content, false, true);
             
             //Find the object
-            $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2xml($resultID))->first();
+            $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($resultID))->first();
         }
         
         //Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
         if(is_object($resultID)) {
             return $resultID;

Vulnerable code:         $token=KapostPreviewToken::get()->filter('Code', Convert::raw2xml($auth))->first();
            $kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2xml($this->urlParams['ID']))->sort('"Created" DESC')->first();
        $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2xml($content_id))->first();
            $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2xml($resultID))->first();
Fixed code:         $token=KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
            $kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
        $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
            $existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($resultID))->first();