-
Notifications
You must be signed in to change notification settings - Fork 9
Add Security Rules for Weak Cryptographic Algorithms and Insecure SSL #115
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,20 @@ | ||
id: use-of-md5-java | ||
severity: warning | ||
language: java | ||
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 | ||
rule: | ||
any: | ||
- pattern: java.security.MessageDigest.getInstance($ALGO) | ||
- pattern: java.security.MessageDigest.getInstance($ALGO, $$$) | ||
- pattern: MessageDigest.getInstance($ALGO) | ||
- pattern: MessageDigest.getInstance($ALGO, $$$) | ||
constraints: | ||
ALGO: | ||
regex: 'MD5' | ||
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,23 @@ | ||
id: use-of-sha1-java | ||
language: java | ||
severity: warning | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message: >- | ||
Detected SHA1 hash algorithm which is considered insecure. SHA1 is not | ||
collision resistant and is therefore not suitable as a cryptographic | ||
signature. Instead, use PBKDF2 for password hashing or SHA256 or SHA512 | ||
for other hash function applications. | ||
note: >- | ||
[CWE-328] Use of Weak Hash. | ||
[REFERENCES] | ||
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures | ||
rule: | ||
any: | ||
- pattern: $DU.getSha1Digest().digest($$$) | ||
- pattern: MessageDigest.getInstance($ALGO) | ||
- pattern: MessageDigest.getInstance($ALGO,$$$) | ||
- pattern: java.security.MessageDigest.getInstance($ALGO,$$$) | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
constraints: | ||
ALGO: | ||
regex: 'SHA1|SHA-1' | ||
ESS-ENN 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,75 @@ | ||
id: weak-ssl-context-java | ||
language: java | ||
severity: warning | ||
message: >- | ||
'An insecure SSL context was detected. TLS versions 1.0, 1.1, and all | ||
SSL versions are considered weak encryption and are deprecated. Use | ||
SSLContext.getInstance("TLSv1.2") for the best security.' | ||
note: >- | ||
[CWE-326] Inadequate Encryption Strength | ||
[REFERENCES] | ||
- https://tools.ietf.org/html/rfc7568 | ||
- https://tools.ietf.org/id/draft-ietf-tls-oldversions-deprecate-02.html | ||
|
||
rule: | ||
all: | ||
- pattern: SSLContext.getInstance($CONTEXT) | ||
- not: | ||
pattern: SSLContext.getInstance("TLSv1.3") | ||
- not: | ||
pattern: SSLContext.getInstance("TLSv1.2") | ||
constraints: | ||
CONTEXT: | ||
any: | ||
- kind: string_literal | ||
pattern: $TLS | ||
not: | ||
regex: ^['"`](TLSv1.2|TLSv1.3)['"`]$ | ||
- kind: identifier | ||
inside: | ||
stopBy: end | ||
follows: | ||
stopBy: end | ||
any: | ||
- kind: local_variable_declaration | ||
- kind: field_declaration | ||
all: | ||
- has: | ||
kind: type_identifier | ||
regex: ^String$ | ||
- has: | ||
stopBy: end | ||
kind: variable_declarator | ||
all: | ||
- has: | ||
kind: identifier | ||
stopBy: end | ||
pattern: $CONTEXT | ||
- has: | ||
kind: string_literal | ||
pattern: $TLS | ||
not: | ||
regex: ^['"`](TLSv1.2|TLSv1.3)['"`]$ | ||
- kind: identifier | ||
follows: | ||
stopBy: end | ||
any: | ||
- kind: local_variable_declaration | ||
- kind: field_declaration | ||
all: | ||
- has: | ||
kind: type_identifier | ||
regex: ^String$ | ||
- has: | ||
stopBy: end | ||
kind: variable_declarator | ||
all: | ||
- has: | ||
kind: identifier | ||
stopBy: end | ||
pattern: $CONTEXT | ||
- has: | ||
kind: string_literal | ||
pattern: $TLS | ||
not: | ||
regex: ^['"`](TLSv1.2|TLSv1.3)['"`]$ |
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-java | ||
snapshots: | ||
? | | ||
MessageDigest md5Digest = MessageDigest.getInstance("MD5"); | ||
: labels: | ||
- source: MessageDigest.getInstance("MD5") | ||
style: primary | ||
start: 26 | ||
end: 58 |
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,31 @@ | ||
id: use-of-sha1-java | ||
snapshots: | ||
? | | ||
MessageDigest sha1Digest = MessageDigest.getInstance("SHA1"); | ||
: labels: | ||
- source: MessageDigest.getInstance("SHA1") | ||
style: primary | ||
start: 27 | ||
end: 60 | ||
? | | ||
MessageDigest sha1Digest = MessageDigest.getInstance("SHA1", "SUN"); | ||
: labels: | ||
- source: MessageDigest.getInstance("SHA1", "SUN") | ||
style: primary | ||
start: 27 | ||
end: 67 | ||
? | | ||
byte[] hashValue = DigestUtils.getSha1Digest().digest(password.getBytes()); | ||
: labels: | ||
- source: DigestUtils.getSha1Digest().digest(password.getBytes()) | ||
style: primary | ||
start: 19 | ||
end: 74 | ||
? | | ||
java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); | ||
DigestUtils.getSha1Digest().digest(password.getBytes()); | ||
: labels: | ||
- source: java.security.MessageDigest.getInstance("SHA1", "SUN") | ||
style: primary | ||
start: 33 | ||
end: 87 |
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,37 @@ | ||
id: weak-ssl-context-java | ||
snapshots: | ||
? | | ||
SSLContext ctx = SSLContext.getInstance("SSL"); | ||
: labels: | ||
- source: SSLContext.getInstance("SSL") | ||
style: primary | ||
start: 17 | ||
end: 46 | ||
? | | ||
SSLContext ctx = SSLContext.getInstance("SSLv3"); | ||
: labels: | ||
- source: SSLContext.getInstance("SSLv3") | ||
style: primary | ||
start: 17 | ||
end: 48 | ||
? | | ||
SSLContext ctx = SSLContext.getInstance("TLS"); | ||
: labels: | ||
- source: SSLContext.getInstance("TLS") | ||
style: primary | ||
start: 17 | ||
end: 46 | ||
? | | ||
SSLContext ctx = SSLContext.getInstance("TLSv1"); | ||
: labels: | ||
- source: SSLContext.getInstance("TLSv1") | ||
style: primary | ||
start: 17 | ||
end: 48 | ||
? | | ||
SSLContext ctx = SSLContext.getInstance("TLSv1.1"); | ||
: labels: | ||
- source: SSLContext.getInstance("TLSv1.1") | ||
style: primary | ||
start: 17 | ||
end: 50 |
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,7 @@ | ||
id: use-of-md5-java | ||
valid: | ||
- | | ||
MessageDigest md5Digest = MessageDigest.getInstance("SHA-512"); | ||
invalid: | ||
- | | ||
MessageDigest md5Digest = MessageDigest.getInstance("MD5"); |
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,18 @@ | ||
id: use-of-sha1-java | ||
valid: | ||
- | | ||
java.io.File fileTarget = new java.io.File( | ||
new java.io.File(org.owasp.benchmark.helpers.Utils.TESTFILES_DIR), | ||
"passwordFile.txt"); | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
invalid: | ||
- | | ||
java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA1", "SUN"); | ||
DigestUtils.getSha1Digest().digest(password.getBytes()); | ||
- | | ||
MessageDigest sha1Digest = MessageDigest.getInstance("SHA1", "SUN"); | ||
- | | ||
byte[] hashValue = DigestUtils.getSha1Digest().digest(password.getBytes()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove duplicate test case. The test case for - |
byte[] hashValue = DigestUtils.getSha1Digest().digest(password.getBytes());
- |
MessageDigest sha1Digest = MessageDigest.getInstance("SHA1");
- - |
- byte[] hashValue = DigestUtils.getSha1Digest().digest(password.getBytes()); Also applies to: 18-18 |
||
- | | ||
MessageDigest sha1Digest = MessageDigest.getInstance("SHA1"); | ||
- | | ||
byte[] hashValue = DigestUtils.getSha1Digest().digest(password.getBytes()); |
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,19 @@ | ||
id: weak-ssl-context-java | ||
valid: | ||
- | | ||
SSLContext ctx = SSLContext.getInstance("TLSv1.2"); | ||
- | | ||
SSLContext ctx = SSLContext.getInstance("TLSv1.3"); | ||
- | | ||
SSLContext ctx = SSLContext.getInstance(getSslContext()); | ||
invalid: | ||
- | | ||
SSLContext ctx = SSLContext.getInstance("SSL"); | ||
- | | ||
SSLContext ctx = SSLContext.getInstance("TLS"); | ||
- | | ||
SSLContext ctx = SSLContext.getInstance("TLSv1"); | ||
- | | ||
SSLContext ctx = SSLContext.getInstance("SSLv3"); | ||
- | | ||
SSLContext ctx = SSLContext.getInstance("TLSv1.1"); |
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.