Skip to content

Commit 0f7301c

Browse files
author
Clement Fauchere
committed
back port fix for CVE-2022-23535
1 parent 46a8387 commit 0f7301c

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

LiteDB/LiteDB.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
4-
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
55
</PropertyGroup>
66
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
7-
<TargetFrameworks>net35;net40;netstandard1.3;netstandard2.0</TargetFrameworks>
7+
<TargetFrameworks>net35;net40;netstandard2.0</TargetFrameworks>
88
</PropertyGroup>
99

1010
<PropertyGroup>

LiteDB/Mapper/BsonMapper.Deserialize.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Collections;
44
using System.Collections.Generic;
@@ -156,9 +156,25 @@ internal object Deserialize(Type type, BsonValue value)
156156
// test if value is object and has _type
157157
if (doc.RawValue.TryGetValue("_type", out typeField))
158158
{
159-
type = Type.GetType(typeField.AsString);
159+
var actualType = Type.GetType(typeField.AsString);
160160

161-
if (type == null) throw LiteException.InvalidTypedName(typeField.AsString);
161+
if (actualType == null) throw LiteException.InvalidTypedName(typeField.AsString);
162+
163+
// avoid initialize class that are not assignable
164+
if (!type.IsAssignableFrom(actualType))
165+
{
166+
throw LiteException.DataTypeNotAssignable(type.FullName, actualType.FullName);
167+
}
168+
169+
// avoid use of "System.Diagnostics.Process" in object type definition
170+
// using String test to work in .netstandard 1.3
171+
if (actualType.FullName.Equals("System.Diagnostics.Process", StringComparison.OrdinalIgnoreCase) &&
172+
actualType.Assembly.GetName().Name.Equals("System", StringComparison.OrdinalIgnoreCase))
173+
{
174+
throw LiteException.AvoidUseOfProcess();
175+
}
176+
177+
type = actualType;
162178
}
163179
// when complex type has no definition (== typeof(object)) use Dictionary<string, object> to better set values
164180
else if (type == typeof(object))

LiteDB/Utils/LiteException.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class LiteException : Exception
3838
public const int INVALID_TYPED_NAME = 207;
3939
public const int NEED_RECOVER = 208;
4040
public const int PROPERTY_READ_WRITE = 209;
41+
public const int DATA_TYPE_NOT_ASSIGNABLE = 214;
42+
public const int AVOID_USE_OF_PROCESS = 215;
4143

4244
#endregion
4345

@@ -207,6 +209,18 @@ internal static LiteException SyntaxError(StringScanner s, string message = "Une
207209
};
208210
}
209211

212+
internal static LiteException DataTypeNotAssignable(string type1, string type2)
213+
{
214+
{
215+
return new LiteException(DATA_TYPE_NOT_ASSIGNABLE, $"Data type {type1} is not assignable from data type {type2}"); return new LiteException(DATA_TYPE_NOT_ASSIGNABLE, $"Data type {type1} is not assignable from data type {type2}");
216+
}
217+
}
218+
219+
internal static LiteException AvoidUseOfProcess()
220+
{
221+
return new LiteException(AVOID_USE_OF_PROCESS, $"LiteDB do not accept System.Diagnostics.Process class in deserialize mapper");
222+
}
223+
210224
#endregion
211225
}
212226
}

0 commit comments

Comments
 (0)