CVE-2020-36620 (published 2022-12-21T19:15Z)

A vulnerability was found in Brondahl EnumStringValues up to 4.0.0. It has been declared as problematic. This vulnerability affects the function GetStringValuesWithPreferences_Uncache of the file EnumStringValues/EnumExtensions.cs. The manipulation leads to resource consumption. Upgrading to version 4.0.1 is able to address this issue. The name of the patch is c0fc7806beb24883cc2f9543ebc50c0820297307. It is recommended to upgrade the affected component. VDB-216466 is the identifier assigned to this vulnerability.

CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-400
cwe_name: Uncontrolled Resource Consumption
description: The product does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources.
extended_description: 
            Limited resources include memory, file system storage, database connection pool entries, and CPU. If an attacker can trigger the allocation of these limited resources, but the number or size of the resources is not controlled, then the attacker could cause a denial of service that consumes all available resources. This would prevent valid users from accessing the product, and it could potentially have an impact on the surrounding environment. For example, a memory exhaustion attack against an application could slow down the application as well as its host operating system.
            There are at least three distinct scenarios which can commonly lead to resource exhaustion:
               
                  Lack of throttling for the number of allocated resources
                  Losing all references to a resource before reaching the shutdown stage
                  Not closing/returning a resource after processing
               
            Resource exhaustion problems are often result due to an incorrect implementation of the following situations:
               
                  Error conditions and other exceptional circumstances.
                  Confusion over which part of the program is responsible for releasing the resource.
               
         
         

Fix information:
repo_url: https://github.com/Brondahl/EnumStringValues
commit_details: repo_url: https://github.com/Brondahl/EnumStringValues
author: Mike.McLean
author_date: 2020-01-01 21:36:28+00:00
msg: Protect against DOS attacks made possible by parsing random invalid enum strings
repository: repo_url: https://github.com/Brondahl/EnumStringValues
repo_name: Brondahl/EnumStringValues
description: Library for mapping between Strings and Enums elegantly
repo_language: C#
owner: Brondahl
file_changes: filename: EnumExtensions.cs
change_type: ModificationType.MODIFY
diff: @@ -269,15 +269,12 @@ namespace EnumStringValues
     {
       var enumTypeObject = typeof(TEnumType);
 
-      var typeAppropriateDictionary = parsedEnumStringsDictionaryByType.GetOrAdd(enumTypeObject, (x) => new ConcurrentDictionary<string, Enum>());
+      var typeAppropriateDictionary = parsedEnumStringsDictionaryByType.GetOrAdd(
+        enumTypeObject, 
+        (x) => BuildCacheDictionaryForParseStringValue<TEnumType>()
+      );
 
-      var cachedValue = typeAppropriateDictionary.GetOrAdd(lowerStringValue, (str) =>
-      {
-        var parseSucceededForDictionary = TryParseStringValueToEnum_Uncached<TEnumType>(lowerStringValue, out var parsedValueForDictionary);
-        return parseSucceededForDictionary ? (Enum) parsedValueForDictionary : null;
-      });
-
-      if (cachedValue != null)
+      if (typeAppropriateDictionary.TryGetValue(lowerStringValue, out var cachedValue))
       {
         parsedValue = (TEnumType)cachedValue;
         return true;
@@ -292,6 +289,25 @@ namespace EnumStringValues
     /// <summary> Cache for <see cref="TryParseStringValueToEnum{TEnumType}"/> </summary>
     private static ConcurrentDictionary<Type, ConcurrentDictionary<string, Enum>> parsedEnumStringsDictionaryByType;
 
+
+    private static ConcurrentDictionary<string, Enum> BuildCacheDictionaryForParseStringValue<TEnumType>() where TEnumType : System.Enum
+    {
+      var dict = new ConcurrentDictionary<string, Enum>();
+
+      foreach (var enumValue in EnumerateValues<TEnumType>())
+      {
+        foreach (var enumString in GetStringValues<TEnumType>(enumValue))
+        {
+            // Add to the dictionary, just overwriting if the string is already present.
+            // This overwrite is legitimate, because we've declared parsing a duplicate string definition to be `undefined behaviour`.
+            dict.AddOrUpdate(enumString.ToLower(), enumValue, ((repeatedString, previousEnumValue) => enumValue));
+        }
+      }
+
+      return dict;
+    }
+
+
     private static bool TryParseStringValueToEnum_Uncached<TEnumType>(this string lowerStringValue, out TEnumType parsedValue) where TEnumType : System.Enum
     {
       foreach (var enumValue in EnumerateValues<TEnumType>())

programming_language: C#