C#

C#

Made by DeepSource
Audit required: Call to potentially dangerous method DangerousGetHandle CS-A1001
Security
Major

Handle returned by DangerousGetHandle can be invalidated, become stale, or be recycled when APIs such as SetHandleAsInvalid is invoked. This can lead to potential security vulnerabilities within your application. It is therefore recommended that you use this method only if you know what you're doing and absolutely require it.

Audit: Consider using System.URI instead of strings CS-A1000
Security
Major

Representing URIs as strings can prove to be a security risk as they are difficult to parse, validate and encode. It is therefore recommended that you use the more safer and reliable built-in alternative System.URI.

Audit required: Switch to a better crypto algorithm CS-A1002
Security
Critical

One or more crypto algorithms such as TripleDESCryptoServiceProvider, DESCryptoServiceProvider, and RC2CryptoServiceProvider are being used by your application. These algorithms are marked as obsolete and are no longer recommended. Please consider switching to a more modern and robust algorithm instead. Please check out the reference for some recommended algorithms.

Binary Formatter deserializes data in an insecure manner and should not be used CS-S1006
Security
Critical

According to Microsoft, BinaryFormatter deserializes data in an insecure manner and using it is "equivalent of interpreting the payload as a standalone executable and launching it". It is therefore recommended that you switch to preferred alternatives that can handle untrusted data safely such as XmlSerializer, DataContractSerializer, BinaryReader, BinaryWriter, or System.Text.Json.

Audit required: Insecurely generated random number CS-A1008
Security
Critical

Random is a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness. Because the number generated is not random enough for sensitive operations, consider using RandomNumberGenerator from System.Security.Cryptography namespace instead.

Audit required: Cookie is transmitted over an insecure connection CS-A1009
Security
Critical

Setting Secure to false means that the cookie is allowed to be transmitted over an insecure connection. It is always recommended that you send and receive information only via a secure line.

Audit required: Cookie is accessible through a client-side script CS-A1010
Security
Critical

Setting HttpOnly to true means that the cookie cannot be accessed through a client-side script and is limited to the ASP.NET engine. Because cookies can be used to preserve and store critical information that maybe potentially related to the user session, it is always recommended that you limit the scope as and where necessary to prevent any unintended access and cookie-theft. You can however ignore this warning if you're absolutely sure that the cookie does not contain any critical information.

Filesystem related permissions specified are too broad CS-S1000
Security
Critical

It is always recommended that you grant only the minimum required permissions to the necessary user accounts rather than providing complete control to everyone. Giving full control may lead to unintended access that may put your organization and any potentially sensitive information at risk. Consider limiting the scope of the permissions.

Insecure protocol specified in clear text CS-S1001
Security
Major

Protocols such as ftp, telnet, and http lack modern capabilities to transmit information securely and reliably. It is recommended that you switch to more secure and robust protocols such as https and ssh. Additionally, it is also recommended that endpoints and resources be not mentioned in clear text and that suitable alternative methods be used.

Consider specifying the full path to the executable file when spawning processes CS-S1002
Security
Critical

The Process class allows you to spawn and stop local system processes. However, it is recommended that you always specify the full path to the executable file. Failing to do so causes the program to search for the executable in its working directory and may pose a security risk by executing a similarly named executable should the attacker find a leverage.

Consider using SSL when dealing with SMTP CS-S1003
Security
Major

The SMTP class in System.Net.Mail lets you send email using the Simple Mail Transfer Protocol (SMTP). By default, it does not use Secure Sockets Layer (SSL) to encrypt the connection. It is therefore recommended that you enable SSL to secure your application and its data transmission.

Use Path.GetTempFileName() to generate unique filenames rather than relying on DateTime CS-S1004
Security
Major

One way to generate unique files is to rely on DateTime.Now.Ticks and then append this filename to the temp path. However, .NET provides APIs to generate reliable temp files. You can combine Path.GetTempPath() and Path.GetTempFileName() to get the full path to a uniquely generated file that is comparatively more secure and reliable.

Implementing custom crypto algorithms is not secure CS-S1005
Security
Critical

Certain classes in System.Security.Cryptography serve as the base for further implementation of crypto algorithms. However, it is recommended that you do not write your own implementation and use the standard and secure ones already available in .NET.

Anti-forgery token is ignored via IgnoreAntiforgeryTokenAttribute CS-A1011
Security
Critical

Antiforgery token is used in validation and establishing identity to an extent before serving the required data or resource. This potentially helps prevent security issues. The IgnoreAntiforgeryTokenAttribute, however, skips this token's validation. It is recommended that you not use this token to skip the validation.

Consider using Uri.EscapeDataString() instead of Uri.EscapeUriString() CS-S1009
Security
Critical
Autofix

The Uri.EscapeUriString() method converts a URI string into its escaped representation. However, this API is obsolete as it can corrupt URIs in some cases. The safer alternative is Uri.EscapeDataString().

Audit: Writing to a file that's in a publicly accessible directory CS-A1012
Security
Major

Writing to a log file is a perfectly normal behavior that most applications adopt. However, care must be taken that:

  1. The data that is being logged does not contain potentially sensitive information,
  2. Log files are cleared when no longer needed,
  3. Log files are placed in a directory with appropriate permissions.

However, in this case, the application is writing to a log file that is in a directory that can be publicly accessible. It is recommended that you verify that no sensitive data is being written to this log file and if possible, move the log file to a more appropriate and tightly controlled directory.

Audit required: Pointer arithmetic may point to incorrect memory location CS-A1013
Security
Major

C# allows you to use pointers via the unsafe construct. This also allows you to perform pointer arithmetic. While this may be useful to you, particularly if you're performing low-level operations, it is also possible that you may end up trying to access incorrect memory locations or regions that you aren't supposed to access. It is therefore recommended that you validate all the parameters and offsets that you're using when performing pointer arithmetic.

Audit required: Path used in archive extraction maybe unsanitized CS-A1014
Security
Major

The ExtractToFile() method takes in a parameter that specifies the destination to which the archive is to be extracted. However, it is possible that this parameter may be unsanitized, especially if it is manually constructed. In such cases, you may end up extracting the archive to a destination outside your control, especially if one or more parameters are obtained via user input. It is therefore recommended that you ensure that this destination is precisely what you need, meaning, the archive is being extracted to the destination that you intend to.

Insecure protocol specified for ServicePointManager CS-S1007
Security
Critical
Autofix

The SecurityProtocol property of ServicePointManager specifies the protocol used by the ServicePoint. The SecurityProtocolType.Tls protocol should ideally be avoided and a more comprehensive and robust protocol should be used in general. It is recommended that you review this configuration and choose a suitable alternative.

Security attribute is ineffective due to parent scope's attribute CS-S1008
Security
Critical

The SecurityCritical attribute specifies that code or an assembly performs security-critical operations whereas the SecuritySafeCritical attribute marks types or members as security-critical and safely accessible by transparent code. If SecuritySafeCritical is inside the scope of SecurityCritical or vice-versa, the inner security attribute becomes redundant and is no longer effective. Consider dropping such redundant attributes.