Skip to content

Add security rules for weak encryption practices in Java and Kotlin #82

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
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rules/java/security/des-is-deprecated-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ note: >-
- https://www.nist.gov/news-events/news/2005/06/nist-withdraws-outdated-data-encryption-standard
rule:
pattern: $CIPHER.getInstance($SAS)
constraints:
constraints:
SAS:
regex: "DES"
regex: ^".*/DES/.*"|"DES"|"DES/.*"$
14 changes: 14 additions & 0 deletions rules/java/security/rsa-no-padding-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: rsa-no-padding-java
severity: warning
language: java
message: >-
Using RSA without OAEP mode weakens the encryption.
note: >-
[CWE-326] Inadequate Encryption Strength
[REFERENCES]
- https://rdist.root.org/2009/10/06/why-rsa-encryption-padding-is-critical/
rule:
pattern: $YST.getInstance($MODE)
constraints:
MODE:
regex: 'RSA/[Nn][Oo][Nn][Ee]/NoPadding'
16 changes: 16 additions & 0 deletions rules/kotlin/security/des-is-deprecated-kotlin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: des-is-deprecated-kotlin
severity: warning
language: kotlin
message: >-
DES is considered deprecated. AES is the recommended cipher. Upgrade to
use AES. See https://www.nist.gov/news-events/news/2005/06/nist-withdraws-outdated-data-encryption-standard
for more information.
note: >-
[CWE-326] Inadequate Encryption Strength.
[REFERENCES]
- https://www.nist.gov/news-events/news/2005/06/nist-withdraws-outdated-data-encryption-standard
rule:
pattern: $CIPHER.getInstance($SAS)
constraints:
SAS:
regex: ^"DES/.*"|"DES"$
9 changes: 9 additions & 0 deletions tests/__snapshots__/des-is-deprecated-kotlin-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id: des-is-deprecated-kotlin
snapshots:
? |
Cipher.getInstance("DES/ECB/PKCS5Padding");
: labels:
- source: Cipher.getInstance("DES/ECB/PKCS5Padding")
style: primary
start: 0
end: 42
16 changes: 16 additions & 0 deletions tests/__snapshots__/rsa-no-padding-java-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: rsa-no-padding-java
snapshots:
? |
Cipher.getInstance("RSA/NONE/NoPadding");
: labels:
- source: Cipher.getInstance("RSA/NONE/NoPadding")
style: primary
start: 0
end: 40
? |
Cipher.getInstance("RSA/None/NoPadding");
: labels:
- source: Cipher.getInstance("RSA/None/NoPadding")
style: primary
start: 0
end: 40
9 changes: 9 additions & 0 deletions tests/java/rsa-no-padding-java-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id: rsa-no-padding-java
valid:
- |
Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding");
invalid:
- |
Cipher.getInstance("RSA/None/NoPadding");
- |
Cipher.getInstance("RSA/NONE/NoPadding");
7 changes: 7 additions & 0 deletions tests/kotlin/des-is-deprecated-kotlin-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id: des-is-deprecated-kotlin
valid:
- |
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
invalid:
- |
Cipher.getInstance("DES/ECB/PKCS5Padding");