-
Notifications
You must be signed in to change notification settings - Fork 12
Add security rules for RSA encryption and sensitive data management in Kotlin #80
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8f41491
use-of-weak-rsa-key-kotlin
ebd4a54
system-setproperty-hardcoded-secret-kotlin
bab6f71
rsa-no-padding-kotlin
144eb9b
modification in use-of-weak-rsa-key-kotlin
1420654
modification in system-setproperty-hardcoded-secret-kotlin
fbc9a7a
modification in system-setproperty-hardcoded-secret-kotlin
686f98b
modification in use-of-weak-rsa-key-kotlin
c8bf0f7
modification in use-of-weak-rsa-key-kotlin
a589e80
removed use-of-weak-rsa-key-kotlin
4dade80
Merge branch 'main' into rules_128-130
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,14 @@ | ||
| id: rsa-no-padding-kotlin | ||
| severity: warning | ||
| language: kotlin | ||
| 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' | ||
56 changes: 56 additions & 0 deletions
56
rules/kotlin/security/system-setproperty-hardcoded-secret-kotlin.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,56 @@ | ||
| id: system-setproperty-hardcoded-secret-kotlin | ||
| language: kotlin | ||
| severity: warning | ||
| message: >- | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| A secret is hard-coded in the application. Secrets stored in source | ||
| code, such as credentials, identifiers, and other types of sensitive data, | ||
| can be leaked and used by internal or external malicious actors. Use | ||
| environment variables to securely provide credentials and other secrets or | ||
| retrieve them from a secure vault or Hardware Security Module (HSM). | ||
| note: >- | ||
| [CWE-798]: Use of Hard-coded Credentials | ||
| [OWASP A07:2021]: Identification and Authentication Failures | ||
| [REFERENCES] | ||
| - https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html | ||
| utils: | ||
| match_string_literal: | ||
| kind: string_literal | ||
| not: | ||
| regex: ^""$ | ||
| inside: | ||
| kind: value_argument | ||
| nthChild: 2 | ||
| inside: | ||
| stopBy: end | ||
| kind: value_arguments | ||
| has: | ||
| kind: value_argument | ||
| any: | ||
| - has: | ||
| kind: string_literal | ||
| regex: ^"javax.net.ssl.keyStorePassword"$ | ||
| - has: | ||
| kind: string_literal | ||
| regex: ^"javax.net.ssl.trustStorePassword"$ | ||
|
|
||
| inside: | ||
| kind: call_suffix | ||
| inside: | ||
| kind: call_expression | ||
| has: | ||
| kind: navigation_expression | ||
| all: | ||
| - has: | ||
| kind: simple_identifier | ||
| regex: '^System$' | ||
| - has: | ||
| stopBy: end | ||
| kind: navigation_suffix | ||
| has: | ||
| stopBy: end | ||
| kind: simple_identifier | ||
| regex: '^setProperty$' | ||
|
|
||
| rule: | ||
| any: | ||
| - matches: match_string_literal | ||
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,24 @@ | ||
| id: rsa-no-padding-kotlin | ||
| 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 | ||
| ? | | ||
| Cipher.getInstance("RSA/None/NoPadding"); | ||
| Cipher.getInstance("RSA/NONE/NoPadding"); | ||
| : labels: | ||
| - source: Cipher.getInstance("RSA/None/NoPadding") | ||
| style: primary | ||
| start: 0 | ||
| end: 40 | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
50 changes: 50 additions & 0 deletions
50
tests/__snapshots__/system-setproperty-hardcoded-secret-kotlin-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,50 @@ | ||
| id: system-setproperty-hardcoded-secret-kotlin | ||
| snapshots: | ||
| ? | | ||
| System.setProperty("javax.net.ssl.keyStorePassword", "password"); | ||
| System.setProperty("javax.net.ssl.trustStorePassword", "password"); | ||
| : labels: | ||
| - source: '"password"' | ||
| style: primary | ||
| start: 53 | ||
| end: 63 | ||
| - source: System | ||
| style: secondary | ||
| start: 0 | ||
| end: 6 | ||
| - source: setProperty | ||
| style: secondary | ||
| start: 7 | ||
| end: 18 | ||
| - source: .setProperty | ||
| style: secondary | ||
| start: 6 | ||
| end: 18 | ||
| - source: System.setProperty | ||
| style: secondary | ||
| start: 0 | ||
| end: 18 | ||
| - source: System.setProperty("javax.net.ssl.keyStorePassword", "password") | ||
| style: secondary | ||
| start: 0 | ||
| end: 64 | ||
| - source: ("javax.net.ssl.keyStorePassword", "password") | ||
| style: secondary | ||
| start: 18 | ||
| end: 64 | ||
| - source: '"javax.net.ssl.keyStorePassword"' | ||
| style: secondary | ||
| start: 19 | ||
| end: 51 | ||
| - source: '"javax.net.ssl.keyStorePassword"' | ||
| style: secondary | ||
| start: 19 | ||
| end: 51 | ||
| - source: ("javax.net.ssl.keyStorePassword", "password") | ||
| style: secondary | ||
| start: 18 | ||
| end: 64 | ||
| - source: '"password"' | ||
| style: secondary | ||
| start: 53 | ||
| end: 63 |
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: rsa-no-padding-kotlin | ||
| valid: | ||
| - | | ||
| Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding"); | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| invalid: | ||
| - | | ||
| Cipher.getInstance("RSA/None/NoPadding"); | ||
| - | | ||
| Cipher.getInstance("RSA/NONE/NoPadding"); | ||
9 changes: 9 additions & 0 deletions
9
tests/kotlin/system-setproperty-hardcoded-secret-kotlin-test.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,9 @@ | ||
| id: system-setproperty-hardcoded-secret-kotlin | ||
| valid: | ||
| - | | ||
| System.setProperty("javax.net.ssl.trustStorePassword", config); | ||
| System.setProperty("javax.net.ssl.keyStorePassword", config); | ||
| invalid: | ||
| - | | ||
| System.setProperty("javax.net.ssl.keyStorePassword", "password"); | ||
| System.setProperty("javax.net.ssl.trustStorePassword", "password"); | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.