CVE-2016-15012: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: ** UNSUPPORTED WHEN ASSIGNED ** A vulnerability was found in forcedotcom SalesforceMobileSDK-Windows up to 4.x. It has been rated as critical. This issue affects the function ComputeCountSql of the file SalesforceSDK/SmartStore/Store/QuerySpec.cs. The manipulation leads to sql injection. Upgrading to version 5.0.0 is able to address this issue. The patch is named 83b3e91e0c1e84873a6d3ca3c5887eb5b4f5a3d8. It is recommended to upgrade the affected component. The associated identifier of this vulnerability is VDB-217619. NOTE: This vulnerability only affects products that are no longer supported by the maintainer.
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-01-07T13:15Z
Repository: https://github.com/forcedotcom/SalesforceMobileSDK-Windows
Language: C#
Files changed: SalesforceSDK/SmartStore/Store/QuerySpec.cs
Commit date: 2016-06-17 13:30:08 -0700
Commit message: use statement to build sql query to avoid the possibility for SQLi security risk

Diff: diff --git a/SalesforceSDK/SmartStore/Store/QuerySpec.cs b/SalesforceSDK/SmartStore/Store/QuerySpec.cs
index 5fef823..69cc007 100644
--- a/SalesforceSDK/SmartStore/Store/QuerySpec.cs
+++ b/SalesforceSDK/SmartStore/Store/QuerySpec.cs
@@ -43,16 +43,19 @@ namespace Salesforce.SDK.SmartStore.Store
         {
             ASC,
             DESC
         };
 
-        private const string SelectCount = "SELECT count(*) ";
         private const string Select = "SELECT ";
         private const string From = "FROM ";
         private const string Where = "WHERE ";
         private const string OrderBy = "ORDER BY ";
 
+        private const string SelectCount = "SELECT count(*) ";
+        private const string SelectCountFrom = SelectCount + "FROM ({0})";
+
+
         public readonly string BeginKey;
         public readonly string CountSmartSql;
         public readonly string EndKey;
         public readonly string LikeKey;
         public readonly string MatchKey;
@@ -146,12 +149,11 @@ namespace Salesforce.SDK.SmartStore.Store
         /// </summary>
         /// <param name="smartSql"></param>
         /// <returns></returns>
         private string ComputeCountSql(string smartSql)
         {
-            int fromLocation = smartSql.ToLower().IndexOf(" from ", StringComparison.CurrentCultureIgnoreCase);
-            return SelectCount + smartSql.Substring(fromLocation);
+            return string.Format(SelectCountFrom, smartSql);
         }
 
         /// <summary>
         /// </summary>
         /// <returns>select clause for exact/like/range queries</returns>

Vulnerable code:         private const string SelectCount = "SELECT count(*) ";
            int fromLocation = smartSql.ToLower().IndexOf(" from ", StringComparison.CurrentCultureIgnoreCase);
            return SelectCount + smartSql.Substring(fromLocation);
Fixed code:         private const string SelectCount = "SELECT count(*) ";
        private const string SelectCountFrom = SelectCount + "FROM ({0})";


            return string.Format(SelectCountFrom, smartSql);