-
Notifications
You must be signed in to change notification settings - Fork 31
SONARKT-656 Modify rule S6418: Add rspec for Kotlin #5124
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
2 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,34 @@ | ||
{ | ||
"tags": [ | ||
"cwe", | ||
"cert" | ||
], | ||
"securityStandards": { | ||
"CERT": [ | ||
"MSC03-J." | ||
], | ||
"CWE": [ | ||
798 | ||
], | ||
"OWASP": [ | ||
"A2" | ||
], | ||
"OWASP Top 10 2021": [ | ||
"A7" | ||
], | ||
"OWASP Mobile Top 10 2024": [ | ||
"M1" | ||
], | ||
"PCI DSS 3.2": [ | ||
"6.5.10" | ||
], | ||
"PCI DSS 4.0": [ | ||
"6.2.4" | ||
], | ||
"ASVS 4.0": [ | ||
"2.10.4", | ||
"3.5.2", | ||
"6.4.1" | ||
] | ||
} | ||
} |
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,96 @@ | ||
:detections: variables/fields | ||
:defaultsensibility: 5 | ||
|
||
include::../description.adoc[] | ||
|
||
include::../ask-yourself.adoc[] | ||
|
||
include::../recommended.adoc[] | ||
|
||
== Sensitive Code Example | ||
|
||
[source,kotlin] | ||
---- | ||
private val MY_SECRET = "47828a8dd77ee1eb9dde2d5e93cb221ce8c32b37" | ||
|
||
fun main() { | ||
MyClass.callMyService(MY_SECRET) | ||
} | ||
---- | ||
|
||
== Compliant Solution | ||
|
||
Using https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/secrets-manager[AWS Secrets Manager]: | ||
|
||
[source,kotlin] | ||
---- | ||
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest; | ||
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse; | ||
|
||
fun main() { | ||
SecretsManagerClient secretsClient = ... | ||
MyClass.doSomething(secretsClient, "MY_SERVICE_SECRET") | ||
} | ||
|
||
fun doSomething(secretsClient: SecretsManagerClient, secretName: String) { | ||
val valueRequest = GetSecretValueRequest.builder() | ||
.secretId(secretName) | ||
.build() | ||
|
||
val valueResponse = secretsClient.getSecretValue(valueRequest) | ||
val secret = valueResponse.secretString() | ||
// do something with the secret | ||
MyClass.callMyService(secret) | ||
} | ||
---- | ||
|
||
Using https://docs.microsoft.com/en-us/azure/key-vault/secrets/quick-create-java?tabs=azure-cli[Azure Key Vault Secret]: | ||
|
||
[source,kotlin] | ||
---- | ||
import com.azure.identity.DefaultAzureCredentialBuilder; | ||
|
||
import com.azure.security.keyvault.secrets.SecretClient; | ||
import com.azure.security.keyvault.secrets.SecretClientBuilder; | ||
import com.azure.security.keyvault.secrets.models.KeyVaultSecret; | ||
|
||
fun main() { | ||
val keyVaultName = System.getenv("KEY_VAULT_NAME") | ||
val keyVaultUri = "https://$keyVaultName.vault.azure.net" | ||
|
||
val secretClient = SecretClientBuilder() | ||
.vaultUrl(keyVaultUri) | ||
.credential(DefaultAzureCredentialBuilder().build()) | ||
.buildClient() | ||
|
||
MyClass.doSomething(secretClient, "MY_SERVICE_SECRET") | ||
} | ||
|
||
fun doSomething(secretClient: SecretClent, secretName: String) { | ||
val retrievedSecret = secretClient.getSecret(secretName) | ||
val secret = retrievedSecret.getValue() | ||
|
||
// do something with the secret | ||
MyClass.callMyService(secret) | ||
} | ||
---- | ||
|
||
|
||
include::../see.adoc[] | ||
|
||
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m1-improper-credential-usage.html[Mobile Top 10 2024 Category M1 - Improper Credential Usage] | ||
* MSC - https://wiki.sei.cmu.edu/confluence/x/OjdGBQ[MSC03-J - Never hard code sensitive information] | ||
leveretka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
ifdef::env-github,rspecator-view[] | ||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
include::../message.adoc[] | ||
|
||
|
||
include::../parameters.adoc[] | ||
|
||
''' | ||
endif::env-github,rspecator-view[] |
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.