Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 391dad4

Browse files
committed
Remove SerializableAttribute from list of safe attributes for deserializing Runtime Types
1 parent eb58322 commit 391dad4

File tree

3 files changed

+0
-50
lines changed

3 files changed

+0
-50
lines changed

src/ServiceStack.Text/Common/JsWriter.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,6 @@ public static void AssertAllowedRuntimeType(Type type)
161161
if (JsConfig.AllowRuntimeType?.Invoke(type) == true)
162162
return;
163163

164-
var denyTypesInNamespaces = JsConfig.DenyRuntimeTypeInNamespaces;
165-
if (denyTypesInNamespaces?.Count > 0)
166-
{
167-
foreach (var ns in denyTypesInNamespaces)
168-
{
169-
if (type.Namespace == ns)
170-
throw new NotSupportedException($"{type.Name} is not an allowed Runtime Type. Denied in JsConfig.DenyRuntimeTypeInNamespaces");
171-
}
172-
}
173-
174164
var allowAttributesNamed = JsConfig.AllowRuntimeTypeWithAttributesNamed;
175165
if (allowAttributesNamed?.Count > 0)
176166
{

src/ServiceStack.Text/JsConfig.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,6 @@ public static string[] IgnoreAttributesNamed
921921

922922
public static HashSet<string> AllowRuntimeTypeWithInterfacesNamed { get; set; }
923923

924-
public static HashSet<string> DenyRuntimeTypeInNamespaces { get; set; }
925-
926924
public static HashSet<string> AllowRuntimeTypeInTypesWithNamespaces { get; set; }
927925

928926
public static Func<Type, bool> AllowRuntimeType { get; set; }
@@ -986,7 +984,6 @@ public static void Reset()
986984
{
987985
nameof(DataContractAttribute),
988986
nameof(RuntimeSerializableAttribute),
989-
"SerializableAttribute",
990987
};
991988
AllowRuntimeTypeWithInterfacesNamed = new HashSet<string>
992989
{
@@ -1001,10 +998,6 @@ public static void Reset()
1001998
{
1002999
"ServiceStack.Messaging",
10031000
};
1004-
DenyRuntimeTypeInNamespaces = new HashSet<string>
1005-
{
1006-
"System.CodeDom.Compiler",
1007-
};
10081001
PlatformExtensions.ClearRuntimeAttributes();
10091002
ReflectionExtensions.Reset();
10101003
JsState.Reset();

tests/ServiceStack.Text.Tests/RuntimeSerializtionTests.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ public void Does_Serialize_Allowed_Types()
108108
typeof(UserAuth),
109109
typeof(UserAuthDetails),
110110
typeof(Message),
111-
#if NET45
112-
typeof(SerialiazableType),
113-
#endif
114111
};
115112

116113
foreach (var allowType in allowTypes)
@@ -176,9 +173,6 @@ public void Does_Serialize_Allowed_Types_in_Objects_Array()
176173
typeof(UserAuth),
177174
typeof(UserAuthDetails),
178175
typeof(Message),
179-
#if NET45
180-
typeof(SerialiazableType),
181-
#endif
182176
};
183177

184178
foreach (var allowType in allowTypes)
@@ -205,32 +199,5 @@ public void Does_allow_Unknown_Type_in_MQ_Messages()
205199
var fromJson = json.FromJson<Message>();
206200
Assert.That(fromJson.Body.GetType(), Is.EqualTo(typeof(AType)));
207201
}
208-
209-
[Test]
210-
public void Does_not_allow_Types_in_DenyRuntimeTypeInTypesWithNamespaces()
211-
{
212-
//Uses JsConfig.DenyRuntimeTypeInNamespaces
213-
214-
var types = new Type[]
215-
{
216-
#if NET45
217-
typeof(System.CodeDom.Compiler.TempFileCollection)
218-
#endif
219-
};
220-
221-
foreach (var type in types)
222-
{
223-
var json = CreateJson(type);
224-
try
225-
{
226-
var instance = json.FromJson<RuntimeObject>();
227-
Assert.Fail("Should throw " + type.Name);
228-
}
229-
catch (NotSupportedException ex)
230-
{
231-
ex.Message.Print();
232-
}
233-
}
234-
}
235202
}
236203
}

0 commit comments

Comments
 (0)