Skip to content
Prev Previous commit
Next Next commit
Semgrep rule ported - rsa-no-padding-java - Java by ESS ENN
  • Loading branch information
ESS-ENN committed Sep 2, 2024
commit eff5fec89c612097760a5beed303e877d7fd747c
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"
9 changes: 9 additions & 0 deletions tests/__snapshots__/rsa-no-padding-java-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id: rsa-no-padding-java
snapshots: {}
snapshots:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the duplicate key issue.

The snapshots key is duplicated at line 3, which is not allowed in YAML.

Remove the duplicate key:

 id: rsa-no-padding-java -snapshots: {} snapshots: Cipher.getInstance("RSA/ECB/NoPadding"): labels:
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
snapshots:
id: rsa-no-padding-java
snapshots:
Cipher.getInstance("RSA/ECB/NoPadding"):
labels:
Tools
yamllint

[error] 3-3: duplication of key "snapshots" in mapping

(key-duplicates)

Cipher.getInstance("RSA/ECB/NoPadding"):
labels:
- source: Cipher.getInstance("RSA/ECB/NoPadding")
style: primary
start: 0
end: 39
8 changes: 8 additions & 0 deletions tests/java/rsa-no-padding-java-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id: rsa-no-padding-java
valid:
- |
Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding");
invalid:
- |
Cipher.getInstance("RSA/None/NoPadding");
Cipher.getInstance("RSA/NONE/NoPadding");