Skip to content

Commit c1d9856

Browse files
committed
Merging changes synced from https://github.com/MicrosoftDocs/visualstudio-docs-pr (branch live)
2 parents ad72538 + db30651 commit c1d9856

27 files changed

+918
-29
lines changed

docs/code-quality/ca2300-do-not-use-insecure-deserializer-binaryformatter.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ dev_langs:
1010
- VB
1111
ms.workload:
1212
- "multiple"
13+
f1_keywords:
14+
- "CA2300"
15+
- "DoNotUseInsecureDeserializerBinaryFormatter"
1316
---
1417
# CA2300: Do not use insecure deserializer BinaryFormatter
1518

@@ -37,10 +40,10 @@ This rule finds <xref:System.Runtime.Serialization.Formatters.Binary.BinaryForma
3740
- <xref:System.Runtime.Serialization.Json.DataContractJsonSerializer?displayProperty=nameWithType>
3841
- <xref:System.Web.Script.Serialization.JavaScriptSerializer?displayProperty=nameWithType> - Never use <xref:System.Web.Script.Serialization.SimpleTypeResolver?displayProperty=nameWithType>. If you must use a type resolver, restrict deserialized types to an expected list.
3942
- <xref:System.Xml.Serialization.XmlSerializer?displayProperty=nameWithType>
40-
- NewtonSoft Json.NET - Use TypeNameHandling.None. If you must use another value for TypeNameHandling, restrict deserialized types to an expected list with a custom ISerializationBinder.
43+
- Newtonsoft Json.NET - Use TypeNameHandling.None. If you must use another value for TypeNameHandling, restrict deserialized types to an expected list with a custom ISerializationBinder.
4144
- Protocol Buffers
42-
- Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed, and design for key rotations.
43-
- Restrict deserialized types. Implement a custom <xref:System.Runtime.Serialization.SerializationBinder?displayProperty=nameWithType>. Before deserializing with <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter>, set the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property to an instance of your custom <xref:System.Runtime.Serialization.SerializationBinder>. In the overridden <xref:System.Runtime.Serialization.SerializationBinder.BindToType%2A> method, if the type is unexpected then throw an exception.
45+
- Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed and design for key rotations.
46+
- Restrict deserialized types. Implement a custom <xref:System.Runtime.Serialization.SerializationBinder?displayProperty=nameWithType>. Before deserializing with <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter>, set the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property to an instance of your custom <xref:System.Runtime.Serialization.SerializationBinder>. In the overridden <xref:System.Runtime.Serialization.SerializationBinder.BindToType%2A> method, if the type is unexpected, throw an exception.
4447
- If you restrict deserialized types, you may want to disable this rule and enable rules [CA2301](ca2301-do-not-call-binaryformatter-deserialize-without-first-setting-binaryformatter-binder.md) and [CA2302](ca2302-ensure-binaryformatter-binder-is-set-before-calling-binaryformatter-deserialize.md). Rules [CA2301](ca2301-do-not-call-binaryformatter-deserialize-without-first-setting-binaryformatter-binder.md) and [CA2302](ca2302-ensure-binaryformatter-binder-is-set-before-calling-binaryformatter-deserialize.md) help to ensure that the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property is always set before deserializing.
4548

4649
## When to suppress warnings

docs/code-quality/ca2301-do-not-call-binaryformatter-deserialize-without-first-setting-binaryformatter-binder.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ dev_langs:
1010
- VB
1111
ms.workload:
1212
- "multiple"
13+
f1_keywords:
14+
- "CA2301"
15+
- "DoNotCallBinaryFormatterDeserializeWithoutFirstSettingBinaryFormatterBinder"
1316
---
1417
# CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder
1518

@@ -37,10 +40,10 @@ This rule finds <xref:System.Runtime.Serialization.Formatters.Binary.BinaryForma
3740
- <xref:System.Runtime.Serialization.Json.DataContractJsonSerializer?displayProperty=nameWithType>
3841
- <xref:System.Web.Script.Serialization.JavaScriptSerializer?displayProperty=nameWithType> - Never use <xref:System.Web.Script.Serialization.SimpleTypeResolver?displayProperty=nameWithType>. If you must use a type resolver, restrict deserialized types to an expected list.
3942
- <xref:System.Xml.Serialization.XmlSerializer?displayProperty=nameWithType>
40-
- NewtonSoft Json.NET - Use TypeNameHandling.None. If you must use another value for TypeNameHandling, restrict deserialized types to an expected list with a custom ISerializationBinder.
43+
- Newtonsoft Json.NET - Use TypeNameHandling.None. If you must use another value for TypeNameHandling, restrict deserialized types to an expected list with a custom ISerializationBinder.
4144
- Protocol Buffers
42-
- Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed, and design for key rotations.
43-
- Restrict deserialized types. Implement a custom <xref:System.Runtime.Serialization.SerializationBinder?displayProperty=nameWithType>. Before deserializing with <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter>, set the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property to an instance of your custom <xref:System.Runtime.Serialization.SerializationBinder>. In the overridden <xref:System.Runtime.Serialization.SerializationBinder.BindToType%2A> method, if the type is unexpected then throw an exception.
45+
- Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed and design for key rotations.
46+
- Restrict deserialized types. Implement a custom <xref:System.Runtime.Serialization.SerializationBinder?displayProperty=nameWithType>. Before deserializing with <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter>, set the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property to an instance of your custom <xref:System.Runtime.Serialization.SerializationBinder>. In the overridden <xref:System.Runtime.Serialization.SerializationBinder.BindToType%2A> method, if the type is unexpected, throw an exception.
4447

4548
## When to suppress warnings
4649

docs/code-quality/ca2302-ensure-binaryformatter-binder-is-set-before-calling-binaryformatter-deserialize.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ dev_langs:
1010
- VB
1111
ms.workload:
1212
- "multiple"
13+
f1_keywords:
14+
- "CA2302"
15+
- "EnsureBinaryFormatterBinderIsSetBeforeCallingBinaryFormatterDeserialize"
1316
---
1417
# CA2302: Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize
1518

@@ -37,10 +40,10 @@ This rule finds <xref:System.Runtime.Serialization.Formatters.Binary.BinaryForma
3740
- <xref:System.Runtime.Serialization.Json.DataContractJsonSerializer?displayProperty=nameWithType>
3841
- <xref:System.Web.Script.Serialization.JavaScriptSerializer?displayProperty=nameWithType> - Never use <xref:System.Web.Script.Serialization.SimpleTypeResolver?displayProperty=nameWithType>. If you must use a type resolver, restrict deserialized types to an expected list.
3942
- <xref:System.Xml.Serialization.XmlSerializer?displayProperty=nameWithType>
40-
- NewtonSoft Json.NET - Use TypeNameHandling.None. If you must use another value for TypeNameHandling, restrict deserialized types to an expected list with a custom ISerializationBinder.
43+
- Newtonsoft Json.NET - Use TypeNameHandling.None. If you must use another value for TypeNameHandling, restrict deserialized types to an expected list with a custom ISerializationBinder.
4144
- Protocol Buffers
42-
- Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed, and design for key rotations.
43-
- Restrict deserialized types. Implement a custom <xref:System.Runtime.Serialization.SerializationBinder?displayProperty=nameWithType>. Before deserializing with <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter>, set the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property to an instance of your custom <xref:System.Runtime.Serialization.SerializationBinder>. In the overridden <xref:System.Runtime.Serialization.SerializationBinder.BindToType%2A> method, if the type is unexpected then throw an exception.
45+
- Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed and design for key rotations.
46+
- Restrict deserialized types. Implement a custom <xref:System.Runtime.Serialization.SerializationBinder?displayProperty=nameWithType>. Before deserializing with <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter>, set the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property to an instance of your custom <xref:System.Runtime.Serialization.SerializationBinder>. In the overridden <xref:System.Runtime.Serialization.SerializationBinder.BindToType%2A> method, if the type is unexpected, throw an exception.
4447
- Ensure that all code paths have the <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder> property set.
4548

4649
## When to suppress warnings
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: "CA2305: Do not use insecure deserializer LosFormatter"
3+
ms.date: 05/01/2019
4+
ms.topic: reference
5+
author: dotpaul
6+
ms.author: paulming
7+
manager: jillfra
8+
dev_langs:
9+
- CSharp
10+
- VB
11+
ms.workload:
12+
- "multiple"
13+
f1_keywords:
14+
- "CA2305"
15+
- "DoNotUseInsecureDeserializerLosFormatter"
16+
---
17+
# CA2305: Do not use insecure deserializer LosFormatter
18+
19+
|||
20+
|-|-|
21+
|TypeName|DoNotUseInsecureDeserializerLosFormatter|
22+
|CheckId|CA2305|
23+
|Category|Microsoft.Security|
24+
|Breaking Change|Non Breaking|
25+
26+
## Cause
27+
28+
A <xref:System.Web.UI.LosFormatter?displayProperty=nameWithType> deserialization method was called or referenced.
29+
30+
## Rule description
31+
32+
[!INCLUDE[insecure-deserializers-description](includes/insecure-deserializers-description-md.md)]
33+
34+
This rule finds <xref:System.Web.UI.LosFormatter?displayProperty=nameWithType> deserialization method calls or references.
35+
36+
## How to fix violations
37+
38+
[!INCLUDE[insecure-deserializers-fixes-for-always-insecure-deserializers](includes/insecure-deserializers-fixes-for-always-insecure-deserializers-md.md)]
39+
40+
## When to suppress warnings
41+
42+
[!INCLUDE[insecure-deserializers-common-safe-to-suppress](includes/insecure-deserializers-common-safe-to-suppress-md.md)]
43+
44+
## Pseudo-code examples
45+
46+
### Violation
47+
48+
```csharp
49+
using System.IO;
50+
using System.Web.UI;
51+
52+
public class ExampleClass
53+
{
54+
public object MyDeserialize(byte[] bytes)
55+
{
56+
LosFormatter formatter = new LosFormatter();
57+
return formatter.Deserialize(new MemoryStream(bytes));
58+
}
59+
}
60+
```
61+
62+
```vb
63+
Imports System.IO
64+
Imports System.Web.UI
65+
66+
Public Class ExampleClass
67+
Public Function MyDeserialize(bytes As Byte()) As Object
68+
Dim formatter As LosFormatter = New LosFormatter()
69+
Return formatter.Deserialize(New MemoryStream(bytes))
70+
End Function
71+
End Class
72+
```
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: "CA2310: Do not use insecure deserializer NetDataContractSerializer"
3+
ms.date: 05/01/2019
4+
ms.topic: reference
5+
author: dotpaul
6+
ms.author: paulming
7+
manager: jillfra
8+
dev_langs:
9+
- CSharp
10+
- VB
11+
ms.workload:
12+
- "multiple"
13+
f1_keywords:
14+
- "CA2310"
15+
- "DoNotUseInsecureDeserializerNetDataContractSerializer"
16+
---
17+
# CA2310: Do not use insecure deserializer NetDataContractSerializer
18+
19+
|||
20+
|-|-|
21+
|TypeName|DoNotUseInsecureDeserializerNetDataContractSerializer|
22+
|CheckId|CA2310|
23+
|Category|Microsoft.Security|
24+
|Breaking Change|Non Breaking|
25+
26+
## Cause
27+
28+
A <xref:System.Runtime.Serialization.NetDataContractSerializer?displayProperty=nameWithType> deserialization method was called or referenced.
29+
30+
## Rule description
31+
32+
[!INCLUDE[insecure-deserializers-description](includes/insecure-deserializers-description-md.md)]
33+
34+
This rule finds <xref:System.Runtime.Serialization.NetDataContractSerializer?displayProperty=nameWithType> deserialization method calls or references. If you want to deserialize only when the <xref:System.Runtime.Serialization.NetDataContractSerializer.Binder> property is set to restrict types, disable this rule and enable rules [CA2311](ca2311-do-not-deserialize-without-first-setting-netdatacontractserializer-binder.md) and [CA2312](ca2312-ensure-netdatacontractserializer-binder-is-set-before-deserializing.md) instead.
35+
36+
## How to fix violations
37+
38+
- If possible, use a secure serializer instead, and **don't allow an attacker to specify an arbitrary type to deserialize**. Some safer serializers include:
39+
- <xref:System.Runtime.Serialization.DataContractSerializer?displayProperty=nameWithType>
40+
- <xref:System.Runtime.Serialization.Json.DataContractJsonSerializer?displayProperty=nameWithType>
41+
- <xref:System.Web.Script.Serialization.JavaScriptSerializer?displayProperty=nameWithType> - Never use <xref:System.Web.Script.Serialization.SimpleTypeResolver?displayProperty=nameWithType>. If you must use a type resolver, restrict deserialized types to an expected list.
42+
- <xref:System.Xml.Serialization.XmlSerializer?displayProperty=nameWithType>
43+
- Newtonsoft Json.NET - Use TypeNameHandling.None. If you must use another value for TypeNameHandling, restrict deserialized types to an expected list with a custom ISerializationBinder.
44+
- Protocol Buffers
45+
- Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed and design for key rotations.
46+
- Restrict deserialized types. Implement a custom <xref:System.Runtime.Serialization.SerializationBinder?displayProperty=nameWithType>. Before deserializing with <xref:System.Runtime.Serialization.NetDataContractSerializer>, set the <xref:System.Runtime.Serialization.NetDataContractSerializer.Binder> property to an instance of your custom <xref:System.Runtime.Serialization.SerializationBinder>. In the overridden <xref:System.Runtime.Serialization.SerializationBinder.BindToType%2A> method, if the type is unexpected, throw an exception.
47+
- If you restrict deserialized types, you may want to disable this rule and enable rules [CA2311](ca2311-do-not-deserialize-without-first-setting-netdatacontractserializer-binder.md) and [CA2312](ca2312-ensure-netdatacontractserializer-binder-is-set-before-deserializing.md). Rules [CA2311](ca2311-do-not-deserialize-without-first-setting-netdatacontractserializer-binder.md) and [CA2312](ca2312-ensure-netdatacontractserializer-binder-is-set-before-deserializing.md) help to ensure that the <xref:System.Runtime.Serialization.NetDataContractSerializer.Binder> property is always set before deserializing.
48+
49+
## When to suppress warnings
50+
51+
[!INCLUDE[insecure-deserializers-common-safe-to-suppress](includes/insecure-deserializers-common-safe-to-suppress-md.md)]
52+
53+
## Pseudo-code examples
54+
55+
### Violation
56+
57+
```csharp
58+
using System.IO;
59+
using System.Runtime.Serialization;
60+
61+
public class ExampleClass
62+
{
63+
public object MyDeserialize(byte[] bytes)
64+
{
65+
NetDataContractSerializer serializer = new NetDataContractSerializer();
66+
return serializer.Deserialize(new MemoryStream(bytes));
67+
}
68+
}
69+
```
70+
71+
```vb
72+
Imports System.IO
73+
Imports System.Runtime.Serialization
74+
75+
Public Class ExampleClass
76+
Public Function MyDeserialize(bytes As Byte()) As Object
77+
Dim serializer As NetDataContractSerializer = New NetDataContractSerializer()
78+
Return serializer.Deserialize(New MemoryStream(bytes))
79+
End Function
80+
End Class
81+
```
82+
83+
## Related rules
84+
85+
[CA2311: Do not deserialize without first setting NetDataContractSerializer.Binder](ca2311-do-not-deserialize-without-first-setting-netdatacontractserializer-binder.md)
86+
87+
[CA2312: Ensure NetDataContractSerializer.Binder is set before deserializing](ca2312-ensure-netdatacontractserializer-binder-is-set-before-deserializing.md)

0 commit comments

Comments
 (0)