-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to identify rules with missing or incomplete guidance (#613)
* Add tests to identify rules with missing or incomplete guidance * Also consider guidance with "TO DO" incomplete * Point DES rules at same guidance * Add guidance for .NET TLS config * Add guidance for .NET Framework 4.7.2 rule * Add guidance for .NET Core advisory 4021279 * Add guidance for Microsoft.IdentityModel.Tokens rule * Add guidance for unsafe keyword rule * Add guidance for JS setTimeout rule * Add guidance for weak/broken hash algo rule * Add guidance for disabling cert validation rule * Add guidance for avoid $_REQUEST rule * Add guidance for PHP XSS rule * Add guidance for strlen rule * Add guidance for Python datetime rule * Add changelog for guidance changes * Add debug info to guidance tests to troubleshoot CI * Fix finding guidance for DevSkim CLI in CI
- Loading branch information
1 parent
76125aa
commit 3e6a87e
Showing
30 changed files
with
358 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SSL/TLS Cryptographic Agility Guidance | ||
|
||
## Summary | ||
|
||
* .NET Framework applications should target .NET Framework 4.8 or later for TLS 1.3 support. | ||
* Do not specify the TLS version explicitly. Configure your code to let the OS decide on the TLS version. | ||
* Do not disable the use of strong cryptography for TLS via configuration. | ||
|
||
## Details | ||
|
||
### Defer Choice of TLS Version to OS | ||
|
||
The Transport Layer Security (TLS) protocol is a cryptographic standard designed to help protect the privacy of information communicated over the Internet. Cryptographic algorithms once considered secure may become insecure due to advances in computing power or discovery of subtle flaws in the algorithms. | ||
|
||
Software with hardcoded cryptographic algorithms may require code changes in the future if those algorithms become insecure. A better alternative is to defer control of the cryptographic algorithm to the operating system. | ||
|
||
### Implementation | ||
|
||
#### .NET | ||
|
||
* When `Switch.System.ServiceModel.DontEnableSystemDefaultTlsVersions` is `false`, the application will use TLS protocol chosen by the operating system. Do not set `DontEnableSystemDefaultTlsVersions` to `false`. | ||
* When `Switch.System.Net.DontEnableSchUseStrongCrypto` is `false`, the application will use more secure network protocols. Do not set `DontEnableSchUseStrongCrypto` to `true`. | ||
* When application code sets a value for `System.Net.ServicePointManager.SecurityProtocol`, the application will override the TLS protocol chosen by the operating system. This makes the application less crypto-agile and may make the application less secure. Do not set a value for `System.Net.ServicePointManager.SecurityProtocol` in application code. | ||
|
||
## References | ||
|
||
* [TLS Best Practices with .NET Framework](https://learn.microsoft.com/en-us/dotnet/framework/network-programming/tls) | ||
* [Security Briefs - Cryptographic Agility](https://learn.microsoft.com/en-us/archive/msdn-magazine/2009/august/cryptographic-agility) | ||
* [Microsoft SDL Cryptographic Recommendations](http://download.microsoft.com/download/6/3/A/63AFA3DF-BB84-4B38-8704-B27605B99DA7/Microsoft%20SDL%20Cryptographic%20Recommendations.pdf) | ||
* [SSL Labs: SSL and TLS Deployment Best Practices](https://github.com/ssllabs/research/wiki/SSL-and-TLS-Deployment-Best-Practices) | ||
* [OWASP: Transport Layer Protection Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
## Weak/Broken Hash Algorithm | ||
# Weak/Broken Hash Algorithm | ||
|
||
## Summary | ||
|
||
### Summary | ||
A weak or broken hash algorithm was detected. | ||
Any usage of MD2, MD4, MD5 or SHA-1 is considered insecure. | ||
Replace the use of insecure hashing algorithms with more secure alternatives such as an algorithm from the SHA-2 family (SHA256, SHA384, and SHA512). | ||
|
||
## Details | ||
|
||
Hash collisions are computationally feasible for older, weak hash algorithms such as MD2, MD4, MD5, and SHA-1. | ||
A hash collision allows an attacker to substitute an alternative input that results in the same hash value. | ||
Collision attacks allow attackers to undermine the security of systems using an insecure hash algorithm (e.g., by forging digital signatures, concealing data tampering, or cracking passwords). | ||
|
||
## Solution | ||
|
||
### Details | ||
The use of signers like `MD5WithRSAEncryption` in cryptography providers like BouncyCastle | ||
is susceptible to colission attacks. Anything that uses MD2, MD4, MD5 or SHA-1 is considered | ||
insecure. | ||
### .NET | ||
|
||
Replace the use of insecure hashing algorithms with more secure alternatives, from SHA256 onward. | ||
See the list of available BouncyCastle signers here: | ||
https://github.com/neoeinstein/bouncycastle/blob/master/crypto/src/security/SignerUtilities.cs. | ||
Replace usages of insecure hash algorithms with `System.Security.Cryptography.SHA512Cng`, `System.Security.Cryptography.SHA384Cng`, or `System.Security.Cryptography.SHA256Cng`. | ||
|
||
For more information, see https://codeql.github.com/codeql-query-help/python/py-weak-sensitive-data-hashing/. | ||
### Python | ||
|
||
### Severity Considerations | ||
Data signed using broken hash algorithms like MD2, MD4, MD5 and SHA1 can be broken using specially designed hardware/software. | ||
The use of signers like `MD5WithRSAEncryption` in cryptography providers like BouncyCastle is susceptible to collision attacks. See the list of available [BouncyCastle signers](https://github.com/neoeinstein/bouncycastle/blob/master/crypto/src/security/SignerUtilities.cs). | ||
|
||
For more information, see [CodeQL Python Hash Algorithm Guidance](https://codeql.github.com/codeql-query-help/python/py-weak-sensitive-data-hashing/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Banned C function detected (strlen) | ||
|
||
## Summary | ||
|
||
* Use of the `strlen` function to determine the length of a string can lead to a buffer overrun vulnerability. | ||
* Use secure versions such as `strlen_s` or `strnlen` to help prevent buffer overruns. | ||
|
||
## Details | ||
|
||
The `strlen` function counts characters until the null terminator is encountered. | ||
When a string is missing the null terminator, the resulting value returned is larger than the string. | ||
Code that relies on the result of `strlen` can suffer from a buffer overrun vulnerability. | ||
|
||
## Severity Considerations | ||
|
||
In the worst case, a buffer overrun vulnerability can provide an attacker the ability to execute arbitrary code leading to complete system compromise. | ||
|
||
## Solution | ||
|
||
Use secure versions such as `strlen_s` or `strnlen` to help prevent buffer overruns. See [Microsoft C Runtime Reference: strnlen](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strnlen-strnlen-s) for more information. | ||
|
||
## References | ||
|
||
* [Avoiding Buffer Overruns](https://learn.microsoft.com/en-us/windows/win32/SecBP/avoiding-buffer-overruns) | ||
* [Microsoft C Runtime Reference: strlen](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strlen-wcslen-mbslen-mbslen-l-mbstrlen-mbstrlen-l) | ||
* [Microsoft C Runtime Reference: strnlen](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strnlen-strnlen-s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# $_REQUEST should be avoided | ||
|
||
## Description | ||
|
||
`$_REQUEST` combines POST, GET, and cookie values in one array, making it easy for an attacker to modify a POST or cookie value by instead putting it in a querystring parameter and sending the URL to the victim. | ||
|
||
## Solution | ||
|
||
Use $_POST, $_GET, $_COOKIE to scope to the expected delivery method for a value. | ||
|
||
## References | ||
|
||
* [OWASP PHP Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/PHP_Configuration_Cheat_Sheet.html#Use_of_.24_REQUEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Do not echo unencoded GET/POST/COOKIE values | ||
|
||
## Description | ||
|
||
When using $_GET/POST/COOKIE values via echo, failure to encode the values will lead to Cross Site Scripting (XSS), where a malicious party can inject script into the webpage. | ||
|
||
## Solution | ||
|
||
HTML Entity Encode (for content going into HTML) or URL Encode (for content going into JavaScript variables) the data. | ||
|
||
## References | ||
|
||
- [OWASP XSS Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Review setTimeout for untrusted data | ||
|
||
## Summary | ||
|
||
* Avoid use of untrusted data within `setTimeout` | ||
|
||
## Description | ||
|
||
Several DOM functions such as `setTimeout` and `eval` will execute a string parameter as code. If untrusted data (data from HTTP requests, user submitted files, etc.) is included in a `setTimeout` call it can allow an attacker to inject and execute their own code. | ||
|
||
## Recommendation | ||
|
||
Edit the `setTimeout` call so that untrusted data is NOT included. If untrusted data is absolutely necessary a great deal of care should be taken to ensure it is properly escaped so that it cannot be executed. This is not as simple as just escaping quotes. | ||
|
||
## References | ||
|
||
* [CWE-676: Use of Potentially Dangerous Function](https://cwe.mitre.org/data/definitions/676.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Unsafe Keyword | ||
|
||
The `unsafe` keyword denotes an unsafe context, which is required for any operation involving pointers. Unsafe code in is not necessarily dangerous; it is just code whose safety cannot be verified by the CLR. | ||
|
||
Using unsafe code introduces security and stability risks. Special attention should be paid to any user-controlled data that is used within unsafe code. | ||
|
||
## References | ||
|
||
* [unsafe C# Reference](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/unsafe) | ||
* [Unsafe code, pointer types, and function pointers](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/unsafe-code) |
Oops, something went wrong.