diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml new file mode 100644 index 0000000..894b94c --- /dev/null +++ b/.github/workflows/build-test.yaml @@ -0,0 +1,44 @@ +name: Build and test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ '*' ] + + +env: + working-directory: Sources + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 + DOTNET_NOLOGO: true + dotnet-version: 8.0.x + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - run: git config --global core.autocrlf input + - uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ env.dotnet-version }} + + - name: Restore dependencies + run: dotnet restore + working-directory: ${{ env.working-directory }} + + - name: Build + run: dotnet build -c Release --no-restore --verbosity normal + working-directory: ${{ env.working-directory }} + + - name: Test + run: dotnet test -c Release --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + working-directory: ${{ env.working-directory }} + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..722da2c --- /dev/null +++ b/Readme.md @@ -0,0 +1,40 @@ +# Project Mesty + +Mesty is PoC of tooling that try to calculate all possible states of code that executes by multiple threads. + +For example, this code: + +```csharp +public class SampleClass1 +{ + private long _setCount; + private readonly AutoResetEvent _notEmptyEvent = new(false); + + public void Set() + { + long newValue; + newValue = Interlocked.Increment(ref _setCount); + long tempValue = 1; + if (newValue == tempValue) + { + _notEmptyEvent.Set(); + } + } +} +``` + +can be invoked this way: + +```csharp +for (int i = 0; i < 3; i++) + Task.Run(() => classInstance.Set()); +``` + +3 threads will try to execute `Increment` method and possible results of method class for different methods: +``` +1. 1th - 1; 2th - 2; 3th - 3 +2. 1th - 1; 2th - 3; 3th - 2 +3. ... +``` + +Generating all combinations allow us to proof that code has deadlocks or lead to unexpected results. diff --git a/Sources/.editorconfig b/Sources/.editorconfig index 5edde9e..2d639fa 100644 --- a/Sources/.editorconfig +++ b/Sources/.editorconfig @@ -1,8 +1,14 @@ -[*.{cs,vb}] +[*] tab_width = 4 indent_size = 4 -end_of_line = crlf +indent_style = space +insert_final_newline = false + +[*.{xml,csproj,props}] +tab_width = 2 +indent_size = 2 +[*.{cs,vb}] ## Simplify name (IDE0001) ## This rule concerns the use of simplified type names in declarations and executable code, when possible. You can remove unnecessary name qualification to simplify code and improve readability. ## using System.IO; @@ -214,7 +220,7 @@ csharp_prefer_braces = when_multiline ## Use throw expression (IDE0016) ## This style rule concerns the use of throw expressions instead of throw statements. Set the severity of rule IDE0016 to define how the rule should be enforced, for example, as a warning or an error. -dotnet_diagnostic.IDE0016.severity = suggestion +dotnet_diagnostic.IDE0016.severity = none ## Options: ## csharp_style_throw_expression @@ -471,7 +477,7 @@ dotnet_style_prefer_auto_properties = true ## Use explicitly provided tuple name (IDE0033) ## This style rule concerns the use of explicit tuple names versus implicit 'ItemX' properties when accessing tuple fields. -dotnet_diagnostic.IDE0033.severity = error +dotnet_diagnostic.IDE0033.severity = warning ## Options: ## dotnet_style_explicit_tuple_names @@ -517,7 +523,7 @@ csharp_prefer_simple_default_expression = true ## { ## throw new System.Exception(); ## } -dotnet_diagnostic.IDE0035.severity = error +dotnet_diagnostic.IDE0035.severity = warning ## Order modifiers (IDE0036) ## This rule lets you enforce a desired modifier sort order. @@ -2226,7 +2232,7 @@ csharp_style_prefer_null_check_over_type_check = true ## Use block-scoped namespace (IDE0160) ## Use file-scoped namespace (IDE0161) ## These rules apply to namespace declarations. For IDE0161 to report violations when block-scoped namespaces are used, you must set the associated option to file_scoped. -dotnet_diagnostic.IDE0160.severity = suggestion +dotnet_diagnostic.IDE0160.severity = none dotnet_diagnostic.IDE0161.severity = warning ## Options: @@ -2509,7 +2515,7 @@ csharp_style_conditional_delegate_call = true ## // Generic instance method that does not support inference. ## someObject.GenericMethod(); ## Generally, both of the prior declarations should be avoided so that the type argument does not have to be specified when the member is called. This results in a syntax for calling members in generics that is no different from the syntax for non-generics. -dotnet_diagnostic.CA1000.severity = suggestion +dotnet_diagnostic.CA1000.severity = none ## Types that own disposable fields should be disposable (CA1001) ## A class that declares an xref:System.IDisposable field indirectly owns an unmanaged resource. The class should implement the xref:System.IDisposable interface to dispose of the unmanaged resource that it owns once the resource is no longer in use. If the class does not directly own any unmanaged resources, it should not implement a finalizer. @@ -2531,7 +2537,7 @@ dotnet_diagnostic.CA1003.severity = warning ## Avoid excessive parameters on generic types (CA1005) ## The more type parameters a generic type contains, the more difficult it is to know and remember what each type parameter represents. It is usually obvious with one type parameter, as in List, and in certain cases with two type parameters, as in Dictionary. If more than two type parameters exist, the difficulty becomes too great for most users (for example, TooManyTypeParameters in C# or TooManyTypeParameters(Of T, K, V) in Visual Basic). -dotnet_diagnostic.CA1005.severity = suggestion +dotnet_diagnostic.CA1005.severity = none ## Enums should have zero value (CA1008) ## The default value of an uninitialized enumeration, just like other value types, is zero. A non-flags-attributed enumeration should define a member that has the value of zero so that the default value is a valid value of the enumeration. If appropriate, name the member 'None' (or one of the additional permitted names). Otherwise, assign zero to the most frequently used member. By default, if the value of the first enumeration member is not set in the declaration, its value is zero. @@ -2603,7 +2609,7 @@ dotnet_diagnostic.CA1028.severity = suggestion ## Use events where appropriate (CA1030) ## This rule detects methods that have names that ordinarily would be used for events. Events follow the Observer or Publish-Subscribe design pattern; they are used when a state change in one object must be communicated to other objects. If a method gets called in response to a clearly defined state change, the method should be invoked by an event handler. Objects that call the method should raise events instead of calling the method directly. ## Some common examples of events are found in user interface applications where a user action such as clicking a button causes a segment of code to execute. The .NET event model is not limited to user interfaces. It should be used anywhere you must communicate state changes to one or more objects. -dotnet_diagnostic.CA1030.severity = suggestion +dotnet_diagnostic.CA1030.severity = none ## Do not catch general exception types (CA1031) ## General exceptions should not be caught. @@ -2727,7 +2733,7 @@ dotnet_code_quality.CA1062.null_check_validation_methods = ThrowIfNull ## Implement IDisposable correctly (CA1063) ## All xref:System.IDisposable types should implement the Dispose pattern correctly. -dotnet_diagnostic.CA1063.severity = warning +dotnet_diagnostic.CA1063.severity = suggestion ## Exceptions should be public (CA1064) ## An internal exception is only visible inside its own internal scope. After the exception falls outside the internal scope, only the base exception can be used to catch the exception. If the internal exception is inherited from xref:System.Exception, xref:System.SystemException, or xref:System.ApplicationException, the external code will not have sufficient information to know what to do with the exception. @@ -2776,7 +2782,7 @@ dotnet_diagnostic.CA1068.severity = warning ## Accidental typing mistakes, where the user accidentally typed the same constant value for multiple members. ## Copy paste mistakes, where the user copied an existing member definition, then renamed the member but forgot to change the value. ## Merge resolution from multiple branches, where a new member was added with a different name but the same value in different branches. -dotnet_diagnostic.CA1069.severity = error +dotnet_diagnostic.CA1069.severity = warning ## Do not declare event fields as virtual (CA1070) ## Follow these .NET design guidelines to raise base class events in derived classes. Do not declare virtual events in a base class. Overridden events in a derived class have undefined behavior. The C# compiler does not handle this correctly and it is unpredictable whether a subscriber to the derived event will actually be subscribing to the base class event. @@ -2844,7 +2850,7 @@ dotnet_diagnostic.CA1311.severity = none ## P/Invokes should not be visible (CA1401) ## Methods that are marked with the xref:System.Runtime.InteropServices.DllImportAttribute attribute (or methods that are defined by using the Declare keyword in Visual Basic) use Platform Invocation Services to access unmanaged code. Such methods should not be exposed. By keeping these methods private or internal, you make sure that your library cannot be used to breach security by allowing callers access to unmanaged APIs that they could not call otherwise. -dotnet_diagnostic.CA1401.severity = suggestion +dotnet_diagnostic.CA1401.severity = none ## Validate platform compatibility (CA1416) ## .NET 5 added new attributes, xref:System.Runtime.Versioning.SupportedOSPlatformAttribute and xref:System.Runtime.Versioning.UnsupportedOSPlatformAttribute, to annotate platform-specific APIs. Both attributes can be instantiated with or without version numbers as part of the platform name. They can also be applied multiple times with different platforms. @@ -2902,18 +2908,18 @@ dotnet_diagnostic.CA1501.severity = none ## A node represents a logic branch point and an edge represents a line between nodes. ## The rule reports a violation when the cyclomatic complexity of a method is more than 25. However, you can configure the threshold and also specify other kinds of symbols that the rule should analyze. ## You can learn more about code metrics at Measure complexity of managed code. -dotnet_diagnostic.CA1502.severity = warning +dotnet_diagnostic.CA1502.severity = none ## Avoid unmaintainable code (CA1505) ## The rule reports a violation when the maintainability index of a type, method, field, property, or event is less than 10. However, you can configure the threshold. ## The maintainability index is calculated by using the following metrics: lines of code, program volume, and cyclomatic complexity. (Program volume is a measure of the difficulty of understanding of a type or method that's based on the number of operators and operands in the code. Cyclomatic complexity is a measure of the structural complexity of the type or method. You can learn more about code metrics at Measure complexity and maintainability of managed code. ## A low maintainability index indicates that a type or method is probably difficult to maintain and would be a good candidate to redesign. -dotnet_diagnostic.CA1505.severity = warning +dotnet_diagnostic.CA1505.severity = none ## Avoid excessive class coupling (CA1506) ## This rule measures class coupling by counting the number of unique type references that a type, method, field, property, or event contains. The default coupling threshold is 95 for types and 40 for other symbol kinds, and the thresholds are configurable. ## Types, methods, and other symbols that have a high degree of class coupling can be difficult to maintain. It's a good practice to have types, methods, and other symbols that exhibit low coupling and high cohesion. -dotnet_diagnostic.CA1506.severity = warning +dotnet_diagnostic.CA1506.severity = none ## Use nameof in place of string (CA1507) ## Rule CA1507 flags the use of a string literal as an argument to a method or constructor where a nameof (NameOf in Visual Basic) expression would add maintainability. The rule fires if all of the following conditions are met: @@ -2972,7 +2978,7 @@ dotnet_diagnostic.CA1508.severity = suggestion ## CA1502(Type): 4 ## CA1502(Method): 2 ## An invalid entry in this configuration file is flagged with the CA1509 diagnostic. -dotnet_diagnostic.CA1509.severity = warning +dotnet_diagnostic.CA1509.severity = none ## Do not name enum values 'Reserved' (CA1700) ## This rule assumes that an enumeration member that has a name that contains "reserved" is not currently used but is a placeholder to be renamed or removed in a future version. Renaming or removing a member is a breaking change. You should not expect users to ignore a member just because its name contains "reserved", nor can you rely on users to read or abide by documentation. Furthermore, because reserved members appear in object browsers and smart integrated development environments, they can cause confusion about which members are actually being used. @@ -3100,7 +3106,7 @@ dotnet_diagnostic.CA1717.severity = suggestion ## Double ## Decimal ## Guid -dotnet_diagnostic.CA1720.severity = warning +dotnet_diagnostic.CA1720.severity = suggestion ## Property names should not match get methods (CA1721) ## "Get" methods and properties should have names that clearly distinguish their function. @@ -3159,7 +3165,7 @@ dotnet_diagnostic.CA1810.severity = none ## Compiler-emitted array types ## Types that can't be instantiated and that only define static methods. ## If you apply xref:System.Runtime.CompilerServices.InternalsVisibleToAttribute?displayProperty=fullName to the assembly that's being analyzed, this rule doesn't flag types that are marked as internal (Friend in Visual Basic) by default, because a field may be used by a friend assembly. To analyze the assembly anyway, see Configure code to analyze. -dotnet_diagnostic.CA1812.severity = suggestion +dotnet_diagnostic.CA1812.severity = none ## Avoid unsealed attributes (CA1813) ## .NET provides methods for retrieving custom attributes. By default, these methods search the attribute inheritance hierarchy. For example, xref:System.Attribute.GetCustomAttribute%2A?displayProperty=fullName searches for the specified attribute type or any attribute type that extends the specified attribute type. Sealing the attribute eliminates the search through the inheritance hierarchy, and can improve performance. @@ -3176,7 +3182,7 @@ dotnet_diagnostic.CA1815.severity = warning ## Call GC.SuppressFinalize correctly (CA1816) ## The xref:System.IDisposable.Dispose%2A?displayProperty=nameWithType method lets users release resources at any time before the object becoming available for garbage collection. If the xref:System.IDisposable.Dispose%2A?displayProperty=nameWithType method is called, it frees resources of the object. This makes finalization unnecessary. xref:System.IDisposable.Dispose%2A?displayProperty=nameWithType should call xref:System.GC.SuppressFinalize%2A?displayProperty=nameWithType so the garbage collector doesn't call the finalizer of the object. ## To prevent derived types with finalizers from having to reimplement xref:System.IDisposable and to call it, unsealed types without finalizers should still call xref:System.GC.SuppressFinalize%2A?displayProperty=nameWithType. -dotnet_diagnostic.CA1816.severity = suggestion +dotnet_diagnostic.CA1816.severity = none ## Properties should not return arrays (CA1819) ## Arrays returned by properties are not write-protected, even if the property is read-only. To keep the array tamper-proof, the property must return a copy of the array. Typically, users won't understand the adverse performance implications of calling such a property. Specifically, they might use the property as an indexed property. @@ -3189,7 +3195,7 @@ dotnet_diagnostic.CA1820.severity = silent ## Remove empty finalizers (CA1821) ## Whenever you can, avoid finalizers because of the additional performance overhead that's involved in tracking object lifetime. The garbage collector runs the finalizer before it collects the object. This means that at least two collections are required to collect the object. An empty finalizer incurs this added overhead without any benefit. -dotnet_diagnostic.CA1821.severity = suggestion +dotnet_diagnostic.CA1821.severity = warning ## Mark members as static (CA1822) ## Members that do not access instance data or call instance methods can be marked as static (Shared in Visual Basic). After you mark the methods as static, the compiler will emit nonvirtual call sites to these members. Emitting nonvirtual call sites will prevent a check at run time for each call that makes sure that the current object pointer is non-null. This can achieve a measurable performance gain for performance-sensitive code. In some cases, the failure to access the current object instance represents a correctness issue. @@ -3444,6 +3450,7 @@ dotnet_diagnostic.CA1869.severity = suggestion ## Dispose objects before losing scope (CA2000) ## If a disposable object is not explicitly disposed before all references to it are out of scope, the object will be disposed at some indeterminate time when the garbage collector runs the finalizer of the object. Because an exceptional event might occur that will prevent the finalizer of the object from running, the object should be explicitly disposed instead. dotnet_diagnostic.CA2000.severity = warning +dotnet_code_quality.dispose_ownership_transfer_at_constructor = true ## Do not lock on objects with weak identity (CA2002) ## An object is said to have a weak identity when it can be directly accessed across application domain boundaries. A thread that tries to acquire a lock on an object that has a weak identity can be blocked by a second thread in a different application domain that has a lock on the same object. @@ -3472,7 +3479,7 @@ dotnet_diagnostic.CA2007.severity = suggestion ## For further information and detailed examples, see New TaskCreationOptions and TaskContinuationOptions in .NET Framework 4.5. ## [!NOTE] ## VSTHRD105 - Avoid method overloads that assume TaskScheduler.Current is a similar rule implemented in Microsoft.VisualStudio.Threading.Analyzers package. -dotnet_diagnostic.CA2008.severity = suggestion +dotnet_diagnostic.CA2008.severity = none ## Do not call ToImmutableCollection on an ImmutableCollection value (CA2009) ## xref:System.Collections.Immutable namespace contains types that define immutable collections. This rule analyzes the following immutable collection types: @@ -3504,7 +3511,7 @@ dotnet_diagnostic.CA2012.severity = warning ## Do not use ReferenceEquals with value types (CA2013) ## When comparing values using xref:System.Object.ReferenceEquals%2A, if objA and objB are value types, they are boxed before they are passed to the xref:System.Object.ReferenceEquals%2A method. This means that even if both objA and objB represent the same instance of a value type, the xref:System.Object.ReferenceEquals%2A method nevertheless returns false, as the following example shows. -dotnet_diagnostic.CA2013.severity = suggestion +dotnet_diagnostic.CA2013.severity = warning ## Do not use stackalloc in loops (CA2014) ## The C# stackalloc expression allocates memory from the current stack frame, and that memory may not be released until the current method call returns. If stackalloc is used in a loop, it can lead to stack overflows due to exhausting the stack memory. @@ -3678,7 +3685,7 @@ dotnet_diagnostic.CA2218.severity = warning ## When an exception is raised in an exception clause, it greatly increases the difficulty of debugging. ## When an exception is raised in a finally or fault clause, the new exception hides the active exception, if present. This makes the original error hard to detect and debug. ## When an exception is raised in a filter clause, the runtime silently catches the exception, and causes the filter to evaluate to false. There is no way to tell the difference between the filter evaluating to false and an exception being throw from a filter. This makes it hard to detect and debug errors in the filter's logic. -dotnet_diagnostic.CA2219.severity = suggestion +dotnet_diagnostic.CA2219.severity = warning ## Override Equals on overloading operator equals (CA2224) ## The equality operator is intended to be a syntactically convenient way to access the functionality of the xref:System.Object.Equals%2A method. If you implement the equality operator, its logic must be identical to that of xref:System.Object.Equals%2A. @@ -3740,7 +3747,7 @@ dotnet_diagnostic.CA2237.severity = none ## Provide correct arguments to formatting methods (CA2241) ## The arguments to methods such as xref:System.Console.WriteLine%2A, xref:System.Console.Write%2A, and xref:System.String.Format%2A consist of a format string followed by several xref:System.Object?displayProperty=fullName instances. The format string consists of text and embedded format items of the form {index[,alignment][:formatString]}. 'index' is a zero-based integer that indicates which of the objects to format. If an object does not have a corresponding index in the format string, the object is ignored. If the object specified by 'index' does not exist, a xref:System.FormatException?displayProperty=fullName is thrown at run time. -dotnet_diagnostic.CA2241.severity = suggestion +dotnet_diagnostic.CA2241.severity = none ## Test for NaN correctly (CA2242) ## xref:System.Double.NaN?displayProperty=fullName, which represents a value that's not a number, results when an arithmetic operation is undefined. Any expression that tests for equality between a value and xref:System.Double.NaN?displayProperty=fullName always returns false. Any expression that tests for inequality (!= in C#) between a value and xref:System.Double.NaN?displayProperty=fullName always returns true. @@ -3750,7 +3757,7 @@ dotnet_diagnostic.CA2242.severity = warning ## Since attributes are derived from xref:System.Attribute?displayProperty=fullName, and attributes are used at compile time, only constant values can be passed to their constructors. Attribute parameters that must represent URLs, GUIDs, and Versions cannot be typed as xref:System.Uri?displayProperty=fullName, xref:System.Guid?displayProperty=fullName, and xref:System.Version?displayProperty=fullName, because these types cannot be represented as constants. Instead, they must be represented by strings. ## Because the parameter is typed as a string, it is possible that an incorrectly formatted parameter could be passed at compile time. ## This rule uses a naming heuristic to find parameters that represent a uniform resource identifier (URI), a Globally Unique Identifier (GUID), or a Version, and verifies that the passed value is correct. -dotnet_diagnostic.CA2243.severity = suggestion +dotnet_diagnostic.CA2243.severity = none ## Do not duplicate indexed element initializations (CA2244) ## Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to invoke a constructor followed by lines of assignment statements. @@ -3802,7 +3809,7 @@ dotnet_diagnostic.CA2251.severity = warning ## The following image shows an example of the CA2252 diagnostic. ## Code editor with CA2252 warning. ## Here, Lib is a preview type that's constructed in the Main method. Main itself is not annotated as a preview method, so diagnostics are produced on the two constructors calls inside Main. -dotnet_diagnostic.CA2252.severity = suggestion +dotnet_diagnostic.CA2252.severity = none ## Named placeholders should not be numeric values (CA2253) ## Named placeholders in the logging message template should not be comprised of only numeric characters. @@ -3859,130 +3866,130 @@ dotnet_diagnostic.CA2260.severity = warning ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter?displayProperty=nameWithType deserialization method calls or references. If you want to deserialize only when the xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder property is set to restrict types, disable this rule and enable rules CA2301 and CA2302 instead. Limiting which types can be deserialized can help mitigate against known remote code execution attacks, but your deserialization will still be vulnerable to denial of service attacks. ## [!INCLUDEbinaryformatter] -dotnet_diagnostic.CA2300.severity = error +dotnet_diagnostic.CA2300.severity = none ## Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder (CA2301) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter?displayProperty=nameWithType deserialization method calls or references, when xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter doesn't have its xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder set. If you want to disallow any deserialization with xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter regardless of the xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder property, disable this rule and CA2302, and enable rule CA2300. -dotnet_diagnostic.CA2301.severity = error +dotnet_diagnostic.CA2301.severity = none ## Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize (CA2302) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter?displayProperty=nameWithType deserialization method calls or references when the xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder might be null. If you want to disallow any deserialization with xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter regardless of the xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Binder property, disable this rule and CA2301, and enable rule CA2300. -dotnet_diagnostic.CA2302.severity = error +dotnet_diagnostic.CA2302.severity = none ## Do not use insecure deserializer LosFormatter (CA2305) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Web.UI.LosFormatter?displayProperty=nameWithType deserialization method calls or references. ## LosFormatter is insecure and can't be made secure. For more information, see the BinaryFormatter security guide. -dotnet_diagnostic.CA2305.severity = error +dotnet_diagnostic.CA2305.severity = none ## Do not use insecure deserializer NetDataContractSerializer (CA2310) ## [!INCLUDEinsecure-deserializers-description] ## 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 and CA2312 instead. Limiting which types can be deserialized can help mitigate against known remote code execution attacks, but your deserialization will still be vulnerable to denial of service attacks. ## NetDataContractSerializer is insecure and can't be made secure. For more information, see the BinaryFormatter security guide. -dotnet_diagnostic.CA2310.severity = error +dotnet_diagnostic.CA2310.severity = none ## Do not deserialize without first setting NetDataContractSerializer.Binder (CA2311) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Runtime.Serialization.NetDataContractSerializer?displayProperty=nameWithType deserialization method calls or references, when xref:System.Runtime.Serialization.NetDataContractSerializer doesn't have its xref:System.Runtime.Serialization.NetDataContractSerializer.Binder set. If you want to disallow any deserialization with xref:System.Runtime.Serialization.NetDataContractSerializer regardless of the xref:System.Runtime.Serialization.NetDataContractSerializer.Binder property, disable this rule and CA2312, and enable rule CA2310. -dotnet_diagnostic.CA2311.severity = error +dotnet_diagnostic.CA2311.severity = none ## Ensure NetDataContractSerializer.Binder is set before deserializing (CA2312) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Runtime.Serialization.NetDataContractSerializer?displayProperty=nameWithType deserialization method calls or references when the xref:System.Runtime.Serialization.NetDataContractSerializer.Binder might be null. If you want to disallow any deserialization with xref:System.Runtime.Serialization.NetDataContractSerializer regardless of the xref:System.Runtime.Serialization.NetDataContractSerializer.Binder property, disable this rule and CA2311, and enable rule CA2310. ## NetDataContractSerializer is insecure and can't be made secure. For more information, see the BinaryFormatter security guide. -dotnet_diagnostic.CA2312.severity = error +dotnet_diagnostic.CA2312.severity = none ## Do not use insecure deserializer ObjectStateFormatter (CA2315) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Web.UI.ObjectStateFormatter?displayProperty=nameWithType deserialization method calls or references. -dotnet_diagnostic.CA2315.severity = error +dotnet_diagnostic.CA2315.severity = none ## Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver (CA2321) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Web.Script.Serialization.JavaScriptSerializer?displayProperty=nameWithType deserialization method calls or references, after initializing the xref:System.Web.Script.Serialization.JavaScriptSerializer with a xref:System.Web.Script.Serialization.SimpleTypeResolver?displayProperty=nameWithType. -dotnet_diagnostic.CA2321.severity = error +dotnet_diagnostic.CA2321.severity = none ## Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing (CA2322) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds xref:System.Web.Script.Serialization.JavaScriptSerializer?displayProperty=nameWithType deserialization method calls or references, when the xref:System.Web.Script.Serialization.JavaScriptSerializer may have been initialized with a xref:System.Web.Script.Serialization.SimpleTypeResolver?displayProperty=nameWithType. -dotnet_diagnostic.CA2322.severity = error +dotnet_diagnostic.CA2322.severity = none ## Do not use TypeNameHandling values other than None (CA2326) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds Newtonsoft.Json.TypeNameHandling values other than None. If you want to deserialize only when a Newtonsoft.Json.Serialization.ISerializationBinder is specified to restrict deserialized types, disable this rule and enable rules CA2327, CA2328, CA2329, and CA2330 instead. -dotnet_diagnostic.CA2326.severity = error +dotnet_diagnostic.CA2326.severity = none ## Do not use insecure JsonSerializerSettings (CA2327) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds Newtonsoft.Json.JsonSerializerSettings instances that are configured to deserialize types specified from input, but not configured to restrict deserialized types with a Newtonsoft.Json.Serialization.ISerializationBinder. If you want to disallow deserialization of types specified from input completely, disable rules CA2327, CA2328, CA2329, and CA2330, and enable rule CA2326 instead. -dotnet_diagnostic.CA2327.severity = error +dotnet_diagnostic.CA2327.severity = none ## Ensure that JsonSerializerSettings are secure (CA2328) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds Newtonsoft.Json.JsonSerializerSettings instances that might be configured to deserialize types specified from input, but may not be configured to restrict deserialized types with a Newtonsoft.Json.Serialization.ISerializationBinder. If you want to disallow deserialization of types specified from input completely, disable rules CA2327, CA2328, CA2329, and CA2330, and enable rule CA2326 instead. -dotnet_diagnostic.CA2328.severity = error +dotnet_diagnostic.CA2328.severity = none ## Do not deserialize with JsonSerializer using an insecure configuration (CA2329) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds Newtonsoft.Json.JsonSerializer instances that are configured to deserialize types specified from input, but not configured to restrict deserialized types with a Newtonsoft.Json.Serialization.ISerializationBinder. If you want to disallow deserialization of types specified from input completely, disable rules CA2327, CA2328, CA2329, and CA2330, and enable rule CA2326 instead. -dotnet_diagnostic.CA2329.severity = error +dotnet_diagnostic.CA2329.severity = none ## Ensure that JsonSerializer has a secure configuration when deserializing (CA2330) ## [!INCLUDEinsecure-deserializers-description] ## This rule finds Newtonsoft.Json.JsonSerializer instances that might be configured to deserialize types specified from input, but may not be configured to restrict deserialized types with a Newtonsoft.Json.Serialization.ISerializationBinder. If you want to disallow deserialization of types specified from input completely, disable rules CA2327, CA2328, CA2329, and CA2330, and enable rule CA2326 instead. -dotnet_diagnostic.CA2330.severity = error +dotnet_diagnostic.CA2330.severity = none ## Ensure DataTable.ReadXml()'s input is trusted (CA2350) ## When deserializing a xref:System.Data.DataTable with untrusted input, an attacker can craft malicious input to perform a denial of service attack. There may be unknown remote code execution vulnerabilities. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2350.severity = error +dotnet_diagnostic.CA2350.severity = none ## Ensure DataSet.ReadXml()'s input is trusted (CA2351) ## When deserializing a xref:System.Data.DataSet with untrusted input, an attacker can craft malicious input to perform a denial of service attack. There may be unknown remote code execution vulnerabilities. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2351.severity = error +dotnet_diagnostic.CA2351.severity = none ## Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks (CA2352) ## When deserializing untrusted input with xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter and the deserialized object graph contains a xref:System.Data.DataSet or xref:System.Data.DataTable, an attacker can craft a malicious payload to perform a remote code execution attack. ## This rule finds types which are insecure when deserialized. If your code doesn't deserialize the types found, then you don't have a deserialization vulnerability. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2352.severity = error +dotnet_diagnostic.CA2352.severity = none ## Unsafe DataSet or DataTable in serializable type (CA2353) ## When deserializing untrusted input and the deserialized object graph contains a xref:System.Data.DataSet or xref:System.Data.DataTable, an attacker can craft a malicious payload to perform a denial of service attack. There may be unknown remote code execution vulnerabilities. ## This rule finds types which are insecure when deserialized. If your code doesn't deserialize the types found, then you don't have a deserialization vulnerability. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2353.severity = error +dotnet_diagnostic.CA2353.severity = none ## Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attack (CA2354) ## When deserializing untrusted input with xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter and the deserialized object graph contains a xref:System.Data.DataSet or xref:System.Data.DataTable, an attacker can craft a malicious payload to perform a remote code execution attack. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2354.severity = error +dotnet_diagnostic.CA2354.severity = none ## Unsafe DataSet or DataTable in deserialized object graph (CA2355) ## When deserializing untrusted input with xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter and the deserialized object graph contains a xref:System.Data.DataSet or xref:System.Data.DataTable, an attacker can craft a malicious payload to perform a denial of service attack. There may be unknown remote code execution vulnerabilities. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2355.severity = error +dotnet_diagnostic.CA2355.severity = none ## Unsafe DataSet or DataTable type in web deserialized object graph (CA2356) ## When deserializing untrusted input and the deserialized object graph contains a xref:System.Data.DataSet or xref:System.Data.DataTable, an attacker can craft a malicious payload to perform a denial of service attack. There may be unknown remote code execution vulnerabilities. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2356.severity = error +dotnet_diagnostic.CA2356.severity = none ## Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data (CA2361) ## When deserializing a xref:System.Data.DataSet with untrusted input, an attacker can craft malicious input to perform a denial of service attack. There may be unknown remote code execution vulnerabilities. ## This rule is like CA2351, but for autogenerated code for an in-memory representation of data within a GUI application. Usually, these autogenerated classes aren't deserialized from untrusted input. Your application's usage may vary. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2361.severity = error +dotnet_diagnostic.CA2361.severity = none ## Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks (CA2362) ## When deserializing untrusted input with xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter and the deserialized object graph contains a xref:System.Data.DataSet or xref:System.Data.DataTable, an attacker can craft a malicious payload to perform a remote code execution attack. ## This rule is like CA2352, but for autogenerated code for an in-memory representation of data within a GUI application. Usually, these autogenerated classes aren't deserialized from untrusted input. Your application's usage may vary. ## This rule finds types which are insecure when deserialized. If your code doesn't deserialize the types found, then you don't have a deserialization vulnerability. ## For more information, see DataSet and DataTable security guidance. -dotnet_diagnostic.CA2362.severity = error +dotnet_diagnostic.CA2362.severity = none ## Review code for SQL injection vulnerabilities (CA3001) ## When working with untrusted input and SQL commands, be mindful of SQL injection attacks. An SQL injection attack can execute malicious SQL commands, compromising the security and integrity of your application. Typical techniques include using a single quotation mark or apostrophe for delimiting literal strings, two dashes for a comment, and a semicolon for the end of a statement. For more information, see SQL Injection. @@ -3991,7 +3998,7 @@ dotnet_diagnostic.CA2362.severity = error ## This rule can't track data across assemblies. For example, if one assembly reads the HTTP request input and then passes it to another assembly that executes the SQL command, this rule won't produce a warning. ## [!NOTE] ## There is a configurable limit to how deep this rule will analyze data flow across method calls. See Analyzer Configuration for how to configure the limit in an EditorConfig file. -dotnet_diagnostic.CA3001.severity = error +dotnet_diagnostic.CA3001.severity = none ## Review code for XSS vulnerabilities (CA3002) ## When working with untrusted input from web requests, be mindful of cross-site scripting (XSS) attacks. An XSS attack injects untrusted input into raw HTML output, allowing the attacker to execute malicious scripts or maliciously modify content in your web page. A typical technique is putting