Skip to content
Draft
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
23 changes: 23 additions & 0 deletions docs/codacy-rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ rules:
- javascript
impact: HIGH
confidence: MEDIUM
- id: codacy.kotlin.security.hard-coded-password
severity: ERROR
languages:
- kotlin
patterns:
- pattern-either:
- pattern: 'val $PASSWORD = "$VALUE"'
- pattern: 'var $PASSWORD = "$VALUE"'
- pattern: 'val $PASSWORD: String = "$VALUE"'
- pattern: 'var $PASSWORD: String = "$VALUE"'
Comment on lines +93 to +97

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

Suggestion: The current patterns do not detect secrets assigned using const val or those stored in triple-quoted string literals ("""..."""), both of which are common in Kotlin projects. It is recommended to update the rule to include these patterns for more robust detection.

- metavariable-regex:
metavariable: "$PASSWORD"
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd|(api|secret|private|access|aws|ssh|auth|session|encryption|decryption|gcp)[_-]?key).*"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ LOW RISK

Nitpick: The regular expression contains redundant entries. Specifically, the keyword 'clave' is duplicated, and 'secret' is potentially redundant within the current structure.

Suggested change
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd|(api|secret|private|access|aws|ssh|auth|session|encryption|decryption|gcp)[_-]?key).*"
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|parola|secret|pwd|(api|secret|private|access|aws|ssh|auth|session|encryption|decryption|gcp)[_-]?key).*"

message: Hardcoded passwords are a security risk. They can be easily found by attackers and used to gain unauthorized access to the system.
metadata:
owasp:
- A3:2017 Sensitive Data Exposure
description: Hardcoded passwords are a security risk.
category: security
technology:
- kotlin
impact: HIGH
confidence: MEDIUM
- id: codacy.generic.plsql.empty-strings
severity: WARNING
languages:
Expand Down
4 changes: 4 additions & 0 deletions docs/multiple-tests/codacy-rules-kotlin/patterns.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<module name="root">
<module name="codacy.kotlin.security.hard-coded-password" />
</module>
8 changes: 8 additions & 0 deletions docs/multiple-tests/codacy-rules-kotlin/results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<checkstyle version="1.5">
<file name="Program.kt">
<error source="codacy.kotlin.security.hard-coded-password" line="3" message="Hardcoded passwords are a security risk." severity="error" />
<error source="codacy.kotlin.security.hard-coded-password" line="4" message="Hardcoded passwords are a security risk." severity="error" />
<error source="codacy.kotlin.security.hard-coded-password" line="5" message="Hardcoded passwords are a security risk." severity="error" />
</file>
</checkstyle>
11 changes: 11 additions & 0 deletions docs/multiple-tests/codacy-rules-kotlin/src/Program.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Program {
fun main() {
val password = "password" // Issue: Hardcoded password
val apiKey = "api_key" // Issue: Hardcoded API key
val apiSecret: String = "api_secret" // Issue: Hardcoded API secret

println("This is a security risk: $password")
println("This is a security risk: $apiKey")
println("This is a security risk: $apiSecret")
}
}