Skip to content

A collection of Semgrep rules which followed security guidelines for .NET and Java.

Notifications You must be signed in to change notification settings

tuannq2299/semgrep-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 

Repository files navigation

Semgrep Rule for .NET and Java

powered by semgrep

Semgrep is a fast, open-source, static analysis tool for finding bugs and enforcing code standards at editor, commit, and CI time. Get started →.

This project is a collection of Semgrep rules which followed security guidelines for .NET and Java. Many of these rules have just been tested in a few testcases (mostly provided by Microsoft or Oracle) so they may not work correctly every time. Contact us if you find any bugs in the rule.

References:

Rules for .NET

Rule Supported Note Link
CA2100: Review SQL queries for security vulnerabilities ✔️ CA2100.yaml
CA2109: Review visible event handlers ✔️ CA2109.yaml
CA2119: Seal methods that satisfy private interfaces ✔️ May be not working properly because semgrep hasn't supported interface yet (?) CA2119.yaml
CA2153: Avoid Handling Corrupted State Exceptions ✔️ CA2153.yaml
CA2300: Do not use insecure deserializer BinaryFormatter ✔️ CA2300.yaml
CA2301: Do not call BinaryFormatter.Deserialize without first setting BinaryFormatter.Binder ✔️ CA2301_2302.yaml
CA2302: Ensure BinaryFormatter.Binder is set before calling BinaryFormatter.Deserialize ✔️ Merge with CA2301 CA2301_2302.yaml
CA2305: Do not use insecure deserializer LosFormatter ✔️ CA2305.yaml
CA2310: Do not use insecure deserializer NetDataContractSerializer ✔️ CA2310.yaml
CA2311: Do not deserialize without first setting NetDataContractSerializer.Binder ✔️ CA2311_2312.yaml
CA2312: Ensure NetDataContractSerializer.Binder is set before deserializing ✔️ Merge with CA2311 CA2311_2312.yaml
CA2315: Do not use insecure deserializer ObjectStateFormatter ✔️ CA2315.yaml
CA2321: Do not deserialize with JavaScriptSerializer using a SimpleTypeResolver ✔️ CA2321_2322.yaml
CA2322: Ensure JavaScriptSerializer is not initialized with SimpleTypeResolver before deserializing ✔️ Merge with CA2321 CA2321_2322.yaml
CA2326: Do not use TypeNameHandling values other than None ✔️ CA2326.yaml
CA2327: Do not use insecure JsonSerializerSettings ✔️ CA2327_2328.yaml
CA2328: Ensure that JsonSerializerSettings are secure ✔️ Merge with CA2327 CA2327_2328.yaml
CA2329: Do not deserialize with JsonSerializer using an insecure configuration ✔️ CA2329_2330.yaml
CA2330: Ensure that JsonSerializer has a secure configuration when deserializing ✔️ Merge with CA2329 CA2329_2330.yaml
CA2350: Ensure DataTable.ReadXml()'s input is trusted ✔️ CA2350.yaml
CA2351: Ensure DataSet.ReadXml()'s input is trusted ✔️ CA2351.yaml
CA2352: Unsafe DataSet or DataTable in serializable type can be vulnerable to remote code execution attacks Semgrep haven't supported class definitions for C#
CA2353: Unsafe DataSet or DataTable in serializable type Semgrep haven't supported class definitions for C#
CA2354: Unsafe DataSet or DataTable in deserialized object graph can be vulnerable to remote code execution attack Semgrep haven't supported class definitions for C#, but can combine rules about insecure deserialization above
CA2355: Unsafe DataSet or DataTable in deserialized object graph Semgrep haven't supported class definitions for C#, but can combine rules about insecure deserialization above
CA2356: Unsafe DataSet or DataTable in web deserialized object graph ✔️ CA2356.yaml
CA2361: Ensure autogenerated class containing DataSet.ReadXml() is not used with untrusted data ✔️ CA2361.yaml
CA2362: Unsafe DataSet or DataTable in autogenerated serializable type can be vulnerable to remote code execution attacks Semgrep haven't supported class definitions for C#
CA3001: Review code for SQL injection vulnerabilities ✔️ CA3001.yaml
CA3002: Review code for XSS vulnerabilities ✔️ CA3002.yaml
CA3003: Review code for file path injection vulnerabilities ✔️ CA3003.yaml
CA3004: Review code for information disclosure vulnerabilities ✔️ CA3004.yaml
CA3006: Review code for process command injection vulnerabilities ✔️ CA3006.yaml
CA3007: Review code for open redirect vulnerabilities ✔️ CA3007.yaml
CA3008: Review code for XPath injection vulnerabilities ✔️ CA3008.yaml
CA3009: Review code for XML injection vulnerabilities ✔️ CA3009.yaml
CA3010: Review code for XAML injection vulnerabilities ✔️ CA3010.yaml
CA3011: Review code for DLL injection vulnerabilities ✔️ CA3011.yaml
CA3012: Review code for regex injection vulnerabilities ✔️ CA3012.yaml
CA3061: Do not add schema by URL ✔️ CA3061.yaml
CA3075: Insecure DTD Processing ✔️ CA3075.yaml
CA3076: Insecure XSLT Script Execution ✔️ CA3076.yaml
CA3077: Insecure Processing in API Design, XML Document and XML Text Reader ✔️ CA3077.yaml
CA3147: Mark verb handlers with ValidateAntiForgeryToken ✔️ CA3147.yaml
CA5350: Do Not Use Weak Cryptographic Algorithms ✔️ CA5350.yaml
CA5351: Do Not Use Broken Cryptographic Algorithms ✔️ CA5351.yaml
CA5358: Do Not Use Unsafe Cipher Modes ✔️ CA5358.yaml
CA5359: Do not disable certificate validation ✔️ CA5359.yaml
CA5360: Do not call dangerous methods in deserialization ✔️ CA5360.yaml
CA5361: Do not disable SChannel use of strong crypto ✔️ CA5361.yaml
CA5362: Potential reference cycle in deserialized object graph Semgrep haven't supported class definitions for C#
CA5363: Do not disable request validation ✔️ CA5363.yaml
CA5364: Do not use deprecated security protocols ✔️ CA5364.yaml
CA5365: Do Not Disable HTTP Header Checking ✔️ CA5365.yaml
CA5366: Use XmlReader For DataSet Read XML ✔️ CA5366.yaml
CA5367: Do Not Serialize Types With Pointer Fields ✔️ CA5367.yaml
CA5368: Set ViewStateUserKey For Classes Derived From Page ✔️ CA5368.yaml
CA5369: Use XmlReader for Deserialize ✔️ CA5369.yaml
CA5370: Use XmlReader for validating reader ✔️ CA5370.yaml
CA5371: Use XmlReader for schema read ✔️ CA5371.yaml
CA5372: Use XmlReader for XPathDocument ✔️ CA5372.yaml
CA5373: Do not use obsolete key derivation function ✔️ CA5373.yaml
CA5374: Do Not Use XslTransform ✔️ CA5374.yaml
CA5375: Do not use account shared access signature ✔️ CA5375.yaml
CA5376: Use SharedAccessProtocol HttpsOnly ✔️ CA5376.yaml
CA5377: Use container level access policy ✔️ CA5377.yaml
CA5378: Do not disable ServicePointManagerSecurityProtocols ✔️ CA5378.yaml
CA5379: Ensure key derivation function algorithm is sufficiently strong ✔️ CA5379.yaml
CA5380: Do not add certificates to root store ✔️ CA5380.yaml
CA5381: Ensure certificates are not added to root store ✔️ CA5381.yaml
CA5382: Use secure cookies in ASP.NET Core ✔️ CA5382.yaml
CA5383: Ensure use secure cookies in ASP.NET Core ✔️ CA5383.yaml
CA5384: Do not use digital signature algorithm (DSA) ✔️ CA5384.yaml
CA5385: Use Rivest–Shamir–Adleman (RSA) algorithm with sufficient key size ✔️ Separate into 2 rule: CA5385_1 and CA5385_2 CA5385_1.yaml CA5385_2.yaml
CA5386: Avoid hardcoding SecurityProtocolType value ✔️ CA5386.yaml
CA5387: Do not use weak key derivation function with insufficient iteration count ✔️ CA5387.yaml
CA5388: Ensure sufficient iteration count when using weak key derivation function ✔️ CA5388.yaml
CA5389: Do not add archive item's path to the target file system path ✔️ CA5389.yaml
CA5390: Do not hard-code encryption key ✔️ Separate into 2 rule: CA5390_1 and CA5390_2 CA5390_1.yaml CA5390_2.yaml
CA5391: Use antiforgery tokens in ASP.NET Core MVC controllers ✔️ CA5391.yaml
CA5392: Use DefaultDllImportSearchPaths attribute for P/Invokes ✔️ CA5392.yaml
CA5393: Do not use unsafe DllImportSearchPath value ✔️ CA5393.yaml
CA5394: Do not use insecure randomness ✔️ CA5394.yaml
CA5395: Miss HttpVerb attribute for action methods ✔️ CA5395.yaml
CA5396: Set HttpOnly to true for HttpCookie ✔️ CA5396.yaml
CA5397: Do not use deprecated SslProtocols values ✔️ CA5397.yaml
CA5398: Avoid hardcoded SslProtocols values ✔️ CA5398.yaml
CA5399: Definitely disable HttpClient certificate revocation list check ✔️ CA5399.yaml
CA5400: Ensure HttpClient certificate revocation list check is not disabled ✔️ CA5400.yaml
CA5401: Do not use CreateEncryptor with non-default IV ✔️ CA5401.yaml
CA5402: Use CreateEncryptor with the default IV ✔️ CA5402.yaml
CA5403: Do not hard-code certificate ✔️ CA5403.yaml
CA5404: Do not disable token validation checks ✔️ CA5404.yaml
CA5405: Do not always skip token validation in delegates ✔️ CA5405.yaml

Rules for Java

Name Supported Note Link
DOS-1: Beware of activities that may use disproportionate resources
DOS-2: Release resources in all cases
DOS-3: Resource limit checks should not suffer from integer overflow
DOS-4: Implement Robust Error/Exceptions handling for services
CONFIDENTIAL-1: Purge sensitive information from exceptions
CONFIDENTIAL-2: Do not log highly sensitive information
CONFIDENTIAL-3: Consider purging highly sensitive from memory after use
INJECT-1: Generate valid formatting
INJECT-2: Avoid dynamic SQL
INJECT-3: XML and HTML generation requires care
INJECT-4: Avoid any untrusted data on the command line
INJECT-5: Restrict XML inclusion
INJECT-6: Care with BMP files
INJECT-7: Disable HTML display in Swing components
INJECT-8: Take care interpreting untrusted code
INJECT-9: Prevent injection of exceptional floating point values
EXTEND-1: Limit the accessibility of classes, interfaces, methods, and fields
EXTEND-2: Limit the accessibility of packages
EXTEND-3: Isolate unrelated code
EXTEND-4: Limit exposure of ClassLoader instances
EXTEND-5: Limit the extensibility of classes and methods
EXTEND-6: Understand how a superclass can affect subclass behavior
INPUT-1: Validate inputs
INPUT-2: Validate output from untrusted objects as input
INPUT-3: Define wrappers around native methods
MUTABLE-1: Prefer immutability for value types
MUTABLE-2: Create copies of mutable output values
MUTABLE-3: Create safe copies of mutable and subclassable input values
MUTABLE-4: Support copy functionality for a mutable class
MUTABLE-5: Do not trust identity equality when overridable on input reference objects
MUTABLE-6: Treat passing input to untrusted object as output
MUTABLE-7: Treat output from untrusted object as input
MUTABLE-8: Define wrapper methods around modifiable internal state
MUTABLE-9: Make public static fields final
MUTABLE-10: Ensure public static final field values are constants
MUTABLE-11: Do not expose mutable statics
MUTABLE-12: Do not expose modifiable collections
OBJECT-1: Avoid exposing constructors of sensitive classes
OBJECT-2: Prevent the unauthorized construction of sensitive classes
OBJECT-3: Defend against partially initialized instances of non-final classes
OBJECT-4: Prevent constructors from calling methods that can be overridden
OBJECT-5: Defend against cloning of non-final classes
SERIAL-1: Avoid serialization for security-sensitive classes
SERIAL-2: Guard sensitive data during serialization
SERIAL-3: View deserialization the same as object construction
SERIAL-4: Duplicate the SecurityManager checks enforced in a class during serialization and deserialization
SERIAL-5: Understand the security permissions given to serialization and deserialization
SERIAL-6: Filter untrusted serial data
ACCESS-1: Understand how permissions are checked
ACCESS-2: Beware of callback methods
ACCESS-3: Safely invoke java.security.AccessController.doPrivileged
ACCESS-4: Know how to restrict privileges through doPrivileged
ACCESS-5: Be careful caching results of potentially privileged operations
ACCESS-6: Understand how to transfer context
ACCESS-7: Understand how thread construction transfers context
ACCESS-8: Safely invoke standard APIs that bypass SecurityManager checks depending on the immediate caller's class loader
ACCESS-9: Safely invoke standard APIs that perform tasks using the immediate caller's class loader instance
ACCESS-10: Be aware of standard APIs that perform Java language access checks against the immediate caller
ACCESS-11: Be aware java.lang.reflect.Method.invoke is ignored for checking the immediate caller
ACCESS-12: Avoid using caller-sensitive method names in interface classes
ACCESS-13: Avoid returning the results of privileged operations
ACCESS-14: Safely invoke standard APIs that perform tasks using the immediate caller's module
ACCESS-15: Design and use InvocationHandlers conservatively
ACCESS-16: Plan module configuration carefully

About

A collection of Semgrep rules which followed security guidelines for .NET and Java.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published