CVE-2015-10039: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: A vulnerability was found in dobos domino. It has been rated as critical. Affected by this issue is some unknown functionality in the library src/Complex.Domino.Lib/Lib/EntityFactory.cs. The manipulation leads to sql injection. Upgrading to version 0.1.5524.38553 is able to address this issue. The name of the patch is 16f039073709a21a76526110d773a6cce0ce753a. It is recommended to upgrade the affected component. The identifier of this vulnerability is VDB-218024.
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: 8
Published: 2023-01-11T19:15Z
Repository: https://github.com/dobos/domino
Language: C#
Files changed: src/Complex.Domino.Lib/Lib/EntityFactory.cs, src/Complex.Domino.Web/PageBase.cs
Commit date: 2015-02-15 18:16:37 +0100
Commit message: Validate order by to prevent SQL injection

Diff: diff --git a/src/Complex.Domino.Lib/Lib/EntityFactory.cs b/src/Complex.Domino.Lib/Lib/EntityFactory.cs
index bfcd15a..60c6a68 100644
--- a/src/Complex.Domino.Lib/Lib/EntityFactory.cs
+++ b/src/Complex.Domino.Lib/Lib/EntityFactory.cs
@@ -1,18 +1,21 @@
 ﻿using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Data;
 using System.Data.SqlClient;
 
 namespace Complex.Domino.Lib
 {
     public abstract class EntityFactory<T> : ContextObject
         where T : IDatabaseTableObject, new()
     {
+        private static readonly Regex OrderByRegex = new Regex(@"[a-z]+\s*(asc|desc){0,1}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
+
         private string name;
         private bool? readOnly;
         private bool? hidden;
 
         public string Name
@@ -68,10 +71,16 @@ SELECT COUNT(*) FROM {0} AS entities
             return Find(-1, -1, null);
         }
 
         public IEnumerable<T> Find(int max, int from, string orderBy)
         {
+            // Prevent any injection attacks
+            if (!OrderByRegex.Match(orderBy).Success)
+            {
+                Error.AccessDenied();
+            }
+
             using (var cmd = Context.CreateCommand())
             {
                 string sql = @"
 WITH q AS
 (
diff --git a/src/Complex.Domino.Web/PageBase.cs b/src/Complex.Domino.Web/PageBase.cs
index 9705cb5..a459447 100644
--- a/src/Complex.Domino.Web/PageBase.cs
+++ b/src/Complex.Domino.Web/PageBase.cs
@@ -95,11 +95,11 @@ namespace Complex.Domino.Web
                 OriginalReferer = Request.UrlReferrer.ToString();
             }
 
             if (!bypassAuthentication)
             {
-                // If the user hold a valid cookie but the session is new
+                // If the user holds a valid cookie but the session is new
                 // we need to look up user details from the database
                 if (this.User.Identity.IsAuthenticated && Session[Constants.SessionUser] == null)
                 {
                     var u = new User(DatabaseContext);
                     u.Load(this.User.Identity.Name);

Vulnerable code:                 // If the user hold a valid cookie but the session is new
Fixed code: using System.Text.RegularExpressions;
        private static readonly Regex OrderByRegex = new Regex(@"[a-z]+\s*(asc|desc){0,1}", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            // Prevent any injection attacks
            if (!OrderByRegex.Match(orderBy).Success)
            {
                Error.AccessDenied();
            }

                // If the user holds a valid cookie but the session is new