-
Notifications
You must be signed in to change notification settings - Fork 7
Add security rules for C# cookie flags and Java MD5 usage #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ganeshpatro321
merged 14 commits into
coderabbitai:main
from
ESS-ENN:md5-digest-and-httponly-false-csharp
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN 46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN 3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN 7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN 2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN b072db7
Merge branch 'coderabbitai:main' into main
ESS-ENN 65dce29
Merge branch 'coderabbitai:main' into main
ESS-ENN 12bb3aa
httponly-false-csharp
ESS-ENN 2c5ea88
use-of-md5-digest-utils-java
ESS-ENN d3067f1
removing use-of-md5-digest-utils and httponly-false-csharp
ESS-ENN 45dccde
use-of-md5-digest-utils-java
ESS-ENN 9148ffa
httponly-false-csharp
ESS-ENN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,48 @@ | ||
id: httponly-false-csharp | ||
language: csharp | ||
severity: warning | ||
message: >- | ||
"Detected a cookie where the `HttpOnly` flag is either missing or | ||
disabled. The `HttpOnly` cookie flag instructs the browser to forbid | ||
client-side JavaScript to read the cookie. If JavaScript interaction is | ||
required, you can ignore this finding. However, set the `HttpOnly` flag to | ||
`true` in all other cases. If this wasn't intentional, it's recommended to | ||
set the HttpOnly flag to true so the cookie will not be accessible through | ||
client-side scripts or to use the Cookie Policy Middleware to globally set | ||
the HttpOnly flag. You can then use the CookieOptions class when | ||
instantiating the cookie, which inherits these settings and will require | ||
future developers to have to explicitly override them on a case-by-case | ||
basis if needed. This approach ensures cookies are secure by default." | ||
note: >- | ||
[CWE-1004] Sensitive Cookie Without 'HttpOnly' Flag" | ||
[REFERENCES] | ||
- https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-8.0#cookie-policy-middleware | ||
- https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.cookieoptions | ||
- https://owasp.org/Top10/A05_2021-Security_Misconfiguration | ||
|
||
ast-grep-essentials: true | ||
|
||
rule: | ||
kind: boolean_literal | ||
pattern: $LITERAL | ||
follows: | ||
regex: ^=$ | ||
follows: | ||
kind: member_access_expression | ||
inside: | ||
kind: assignment_expression | ||
all: | ||
- has: | ||
kind: member_access_expression | ||
nthChild: 1 | ||
regex: \.Cookie$ | ||
- has: | ||
kind: identifier | ||
nthChild: 2 | ||
regex: ^HttpOnly$ | ||
|
||
constraints: | ||
LITERAL: | ||
regex: ^false$ | ||
|
||
|
This file contains hidden or 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,42 @@ | ||
id: use-of-md5-digest-utils-java | ||
language: java | ||
severity: warning | ||
message: >- | ||
'Detected MD5 hash algorithm which is considered insecure. MD5 is not | ||
collision resistant and is therefore not suitable as a cryptographic | ||
signature. Use HMAC instead.' | ||
note: >- | ||
[CWE-328] Use of Weak Hash | ||
[REFERENCES] | ||
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures | ||
|
||
ast-grep-essentials: true | ||
|
||
rule: | ||
kind: identifier | ||
regex: ^getMd5Digest$ | ||
nthChild: 2 | ||
precedes: | ||
nthChild: 3 | ||
kind: argument_list | ||
not: | ||
has: | ||
nthChild: 1 | ||
inside: | ||
kind: method_invocation | ||
nthChild: 1 | ||
inside: | ||
kind: method_invocation | ||
all: | ||
- has: | ||
kind: identifier | ||
nthChild: 2 | ||
regex: ^digest$ | ||
- has: | ||
kind: argument_list | ||
nthChild: 3 | ||
- not: | ||
has: | ||
stopBy: end | ||
kind: ERROR | ||
ganeshpatro321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
This file contains hidden or 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,29 @@ | ||
id: httponly-false-csharp | ||
snapshots: | ||
? | | ||
options.Cookie.HttpOnly = false; | ||
: labels: | ||
- source: 'false' | ||
style: primary | ||
start: 26 | ||
end: 31 | ||
- source: options.Cookie | ||
style: secondary | ||
start: 0 | ||
end: 14 | ||
- source: HttpOnly | ||
style: secondary | ||
start: 15 | ||
end: 23 | ||
- source: options.Cookie.HttpOnly = false | ||
style: secondary | ||
start: 0 | ||
end: 31 | ||
- source: options.Cookie.HttpOnly | ||
style: secondary | ||
start: 0 | ||
end: 23 | ||
- source: = | ||
style: secondary | ||
start: 24 | ||
end: 25 |
29 changes: 29 additions & 0 deletions
29
tests/__snapshots__/use-of-md5-digest-utils-java-snapshot.yml
This file contains hidden or 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,29 @@ | ||
id: use-of-md5-digest-utils-java | ||
snapshots: | ||
? | | ||
byte[] hashValue = DigestUtils.getMd5Digest().digest(password.getBytes()); | ||
: labels: | ||
- source: getMd5Digest | ||
style: primary | ||
start: 31 | ||
end: 43 | ||
- source: digest | ||
style: secondary | ||
start: 46 | ||
end: 52 | ||
- source: (password.getBytes()) | ||
style: secondary | ||
start: 52 | ||
end: 73 | ||
- source: DigestUtils.getMd5Digest().digest(password.getBytes()) | ||
style: secondary | ||
start: 19 | ||
end: 73 | ||
- source: DigestUtils.getMd5Digest() | ||
style: secondary | ||
start: 19 | ||
end: 45 | ||
- source: () | ||
style: secondary | ||
start: 43 | ||
end: 45 |
This file contains hidden or 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,9 @@ | ||
id: httponly-false-csharp | ||
valid: | ||
- | | ||
myHttpOnlyCookie.HttpOnly = true; | ||
- | | ||
options.Cookie.HttpOnly = true; | ||
invalid: | ||
- | | ||
options.Cookie.HttpOnly = false; |
This file contains hidden or 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,9 @@ | ||
id: use-of-md5-digest-utils-java | ||
valid: | ||
- | | ||
MessageDigest md5Digest = MessageDigest.getInstance("MD5"); | ||
ganeshpatro321 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- | | ||
byte[] hashValue = DigestUtils.getSha512Digest().digest(password.getBytes()); | ||
invalid: | ||
- | | ||
byte[] hashValue = DigestUtils.getMd5Digest().digest(password.getBytes()); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.