Skip to content

Commit 9152cb7

Browse files
authored
SONARKT-625 Update rules metadata
1 parent ff81104 commit 9152cb7

File tree

11 files changed

+117
-79
lines changed

11 files changed

+117
-79
lines changed

sonar-kotlin-plugin/sonarpedia.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"languages": [
44
"KOTLIN"
55
],
6-
"latest-update": "2025-03-13T20:34:31.901277Z",
6+
"latest-update": "2025-04-03T13:07:10.743415Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": true

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S4507.html

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,7 @@ <h2>See</h2>
3232
<li> OWASP - <a href="https://owasp.org/Top10/A05_2021-Security_Misconfiguration/">Top 10 2021 Category A5 - Security Misconfiguration</a> </li>
3333
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">Top 10 2017 Category A3 - Sensitive Data
3434
Exposure</a> </li>
35-
<li> OWASP - <a href="https://owasp.org/www-project-mobile-top-10/2016-risks/m9-reverse-engineering">Mobile Top 10 2016 Category M9 - Reverse
36-
Engineering</a> </li>
37-
<li> OWASP - <a href="https://owasp.org/www-project-mobile-top-10/2016-risks/m10-extraneous-functionality">Mobile Top 10 2016 Category M10 -
38-
Extraneous Functionality</a> </li>
39-
<li> OWASP - <a href="https://owasp.org/www-project-mobile-top-10/2023-risks/m7-insufficient-binary-protection">Mobile Top 10 2024 Category M7 -
40-
Insufficient Binary Protection</a> </li>
41-
<li> OWASP - <a href="https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration">Mobile Top 10 2024 Category M8 - Security
42-
Misconfiguration</a> </li>
43-
<li> OWASP - <a href="https://mas.owasp.org/checklists/MASVS-CODE/">Mobile AppSec Verification Standard - Code Quality and Build Setting
44-
Requirements</a> </li>
4535
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/489">CWE-489 - Active Debug Code</a> </li>
4636
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/215">CWE-215 - Information Exposure Through Debug Information</a> </li>
47-
<li> <a href="https://developer.android.com/studio/publish/preparing">developer.android.com</a> - Prepare for release </li>
48-
<li> <a href="https://developer.android.com/privacy-and-security/risks/android-debuggable">developer.android.com</a> - android:debuggable </li>
4937
</ul>
5038

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S4507.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"cwe",
1717
"error-handling",
1818
"debug",
19-
"android",
2019
"user-experience"
2120
],
2221
"defaultSeverity": "Minor",
@@ -28,17 +27,6 @@
2827
489,
2928
215
3029
],
31-
"OWASP Mobile": [
32-
"M9",
33-
"M10"
34-
],
35-
"OWASP Mobile Top 10 2024": [
36-
"M7",
37-
"M8"
38-
],
39-
"MASVS": [
40-
"MSTG-CODE-2"
41-
],
4230
"OWASP": [
4331
"A3"
4432
],

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S4830.html

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,17 @@ <h3>Code examples</h3>
5858
<p>The certificate validation gets disabled by overriding the <code>onReceivedSslError</code> method of the <code>WebViewClient</code> class with an
5959
implementation that calls <code>SslErrorHandler.proceed()</code> unconditionally, and that never calls <code>SslErrorHandler.cancel()</code>.</p>
6060
<p>This means that a certificate initially rejected by the system will be accepted by the <code>WebViewClient</code>, regardless of its origin.</p>
61-
<h3>Noncompliant code example</h3>
62-
<pre>
61+
<h4>Noncompliant code example</h4>
62+
<pre data-diff-id="101" data-diff-type="noncompliant">
6363
class MyWebViewClient : WebViewClient() {
6464
override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) =
6565
handler.proceed() // Noncompliant
6666
}
6767
</pre>
68-
<h3>How does this work?</h3>
69-
<p>Addressing the vulnerability of disabled TLS certificate validation primarily involves re-enabling the default validation.</p>
70-
<p>To avoid running into problems with invalid certificates, consider the following sections.</p>
71-
<h4>Using trusted certificates</h4>
72-
<p>If possible, always use a certificate issued by a well-known, trusted CA for your server. Most programming environments come with a predefined list
73-
of trusted root CAs, and certificates issued by these authorities are validated automatically. This is the best practice, and it requires no
74-
additional code or configuration.</p>
75-
<h4>Working with self-signed certificates or non-standard CAs</h4>
76-
<p>In some cases, you might need to work with a server using a self-signed certificate, or a certificate issued by a CA not included in your trusted
77-
roots. Rather than disabling certificate validation in your code, you can add the necessary certificates to your trust store.</p>
78-
<h4>Implementing a server certificate validation</h4>
79-
<p>Alternatively, you need to implement a validation of the server certificate received in the <code>SslErrorHandler</code> object, calling
80-
<code>proceed</code> and <code>cancel</code> appropriately.</p>
81-
<pre>
68+
<h4>Compliant solution</h4>
69+
<p>You need to implement a validation of the server certificate received in the <code>SslErrorHandler</code> object, calling <code>proceed</code> and
70+
<code>cancel</code> appropriately.</p>
71+
<pre data-diff-id="101" data-diff-type="compliant">
8272
class MyWebViewClient : WebViewClient() {
8373
override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) {
8474
if (error.certificate.isServerCertificateValid()) {
@@ -93,6 +83,16 @@ <h4>Implementing a server certificate validation</h4>
9383
}
9484
}
9585
</pre>
86+
<h3>How does this work?</h3>
87+
<p>Addressing the vulnerability of disabled TLS certificate validation primarily involves re-enabling the default validation.</p>
88+
<p>To avoid running into problems with invalid certificates, consider the following sections.</p>
89+
<h4>Using trusted certificates</h4>
90+
<p>If possible, always use a certificate issued by a well-known, trusted CA for your server. Most programming environments come with a predefined list
91+
of trusted root CAs, and certificates issued by these authorities are validated automatically. This is the best practice, and it requires no
92+
additional code or configuration.</p>
93+
<h4>Working with self-signed certificates or non-standard CAs</h4>
94+
<p>In some cases, you might need to work with a server using a self-signed certificate, or a certificate issued by a CA not included in your trusted
95+
roots. Rather than disabling certificate validation in your code, you can add the necessary certificates to your trust store.</p>
9696
<h2>Resources</h2>
9797
<h3>Standards</h3>
9898
<ul>
@@ -115,6 +115,8 @@ <h3>Standards</h3>
115115
Development: V-222550</a> - The application must validate certificates by constructing a certification path to an accepted trust anchor. </li>
116116
<li> CERT - <a
117117
href="https://wiki.sei.cmu.edu/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms">https://wiki.sei.cmu.edu/confluence/display/java/MSC61-J.+Do+not+use+insecure+or+weak+cryptographic+algorithms</a> </li>
118+
<li> Google Support - <a href="https://support.google.com/faqs/answer/7071387?hl=en">How to address WebView SSL Error Handler alerts in your
119+
apps</a> </li>
118120
<li> Android Documentation - <a
119121
href="https://developer.android.com/reference/android/webkit/WebViewClient?hl=en#onReceivedSslError(android.webkit.WebView,%20android.webkit.SslErrorHandler,%20android.net.http.SslError)">WebViewClient.onReceivedSslError</a> method </li>
120122
</ul>

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S5542.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ <h3>Standards</h3>
141141
<li> OWASP - <a href="https://owasp.org/www-project-mobile-top-10/2023-risks/m10-insufficient-cryptography">Mobile Top 10 2024 Category M10 -
142142
Insufficient Cryptography</a> </li>
143143
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/327">CWE-327 - Use of a Broken or Risky Cryptographic Algorithm</a> </li>
144+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/780">CWE-780 - Use of RSA Algorithm without OAEP</a> </li>
144145
<li> <a href="https://wiki.sei.cmu.edu/confluence/x/hDdGBQ">CERT, MSC61-J.</a> - Do not use insecure or weak cryptographic algorithms </li>
145146
</ul>
146147

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S6362.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ <h2>See</h2>
3838
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/79">CWE-79 - Improper Neutralization of Input During Web Page Generation ('Cross-site
3939
Scripting')</a> </li>
4040
</ul>
41+
<h3>Related rules</h3>
42+
<ul>
43+
<li> {rule:kotlin:S7409} - Exposing Java objects through JavaScript interfaces is security-sensitive </li>
44+
</ul>
4145

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,88 @@
1-
<p>WebViews can be used to display web content as part of a mobile application. A browser engine is used to render and display the content. Like a web
2-
application, a mobile application that uses WebViews can be vulnerable to Cross-Site Scripting if untrusted code is rendered.</p>
3-
<p>If malicious JavaScript code in a WebView is executed this can leak the contents of sensitive files when access to local files is enabled.</p>
1+
<p>Exposing the Android file system to WebViews is security-sensitive.</p>
2+
<p>Granting file access to WebViews, particularly through the <code>file://</code> scheme, introduces a risk of local file inclusion vulnerabilities.
3+
The severity of this risk depends heavily on the specific <code>WebSettings</code> configured. Overly permissive settings can allow malicious scripts
4+
to access a wide range of local files, potentially exposing sensitive data such as Personally Identifiable Information (PII) or private application
5+
data, leading to data breaches and other security compromises.</p>
46
<h2>Ask Yourself Whether</h2>
57
<ul>
6-
<li> No local files have to be accessed by the Webview. </li>
7-
<li> The WebView contains untrusted data that could cause harm when rendered. </li>
8+
<li> You open files that may be created or altered by external sources. </li>
9+
<li> You open arbitrary URLs from external sources. </li>
810
</ul>
9-
<p>There is a risk if you answered yes to any of those questions.</p>
11+
<p>There is a risk if you answered yes to any of these questions.</p>
1012
<h2>Recommended Secure Coding Practices</h2>
11-
<p>It is recommended to disable access to local files for WebViews unless it is necessary. In the case of a successful attack through a Cross-Site
12-
Scripting vulnerability the attackers attack surface decreases drastically if no files can be read out.</p>
13+
<p>Avoid opening <code>file://</code> URLs from external sources in WebView components. If your application accepts arbitrary URLs from external
14+
sources, do not enable this functionality. Instead, utilize <code>androidx.webkit.WebViewAssetLoader</code> to access files, including assets and
15+
resources, via <code>http(s)://</code> schemes.</p>
16+
<p>For enhanced security, ensure that the options to load <code>file://</code> URLs are explicitly set to false.</p>
1317
<h2>Sensitive Code Example</h2>
1418
<pre>
15-
import android.webkit.WebView
16-
17-
val webView: WebView = findViewById(R.id.webview)
18-
webView.getSettings().setAllowContentAccess(true) // Sensitive
19-
webView.getSettings().setAllowFileAccess(true) // Sensitive
19+
AndroidView(
20+
factory = { context -&gt;
21+
WebView(context).apply {
22+
webViewClient = WebViewClient()
23+
settings.apply {
24+
allowFileAccess = true // Sensitive
25+
allowFileAccessFromFileURLs = true // Sensitive
26+
allowUniversalAccessFromFileURLs = true // Sensitive
27+
allowContentAccess = true // Sensitive
28+
}
29+
loadUrl("file:///android_asset/example.html")
30+
}
31+
}
32+
)
2033
</pre>
2134
<h2>Compliant Solution</h2>
2235
<pre>
23-
import android.webkit.WebView
36+
AndroidView(
37+
factory = { context -&gt;
38+
val webView = WebView(context)
39+
val assetLoader = WebViewAssetLoader.Builder()
40+
.addPathHandler("/assets/", WebViewAssetLoader.AssetsPathHandler(context))
41+
.build()
42+
43+
webView.webViewClient = object : WebViewClient() {
44+
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
45+
override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest): WebResourceResponse? {
46+
return assetLoader.shouldInterceptRequest(request.url)
47+
}
48+
49+
@Suppress("deprecation")
50+
override fun shouldInterceptRequest(view: WebView?, url: String?): WebResourceResponse? {
51+
return assetLoader.shouldInterceptRequest(Uri.parse(url))
52+
}
53+
}
54+
55+
webView.settings.apply {
56+
allowFileAccess = false
57+
allowFileAccessFromFileURLs = false
58+
allowUniversalAccessFromFileURLs = false
59+
allowContentAccess = false
60+
}
2461

25-
val webView: WebView = findViewById(R.id.webview)
26-
webView.getSettings().setAllowContentAccess(false)
27-
webView.getSettings().setAllowFileAccess(false)
62+
webView.loadUrl("https://appassets.androidplatform.net/assets/example.html")
63+
webView
64+
}
65+
)
2866
</pre>
67+
<p>The compliant solution uses <code>WebViewAssetLoader</code> to load local files instead of directly accessing them via <code>file://</code> URLs.
68+
This approach serves assets over a secure <code><a href="https://appassets.androidplatform.net">https://appassets.androidplatform.net</a></code> URL,
69+
effectively isolating the WebView from the local file system.</p>
70+
<p>The file access settings are disabled by default in modern Android versions. To prevent possible security issues in
71+
<code>Build.VERSION_CODES.Q</code> and earlier, it is still recommended to explicitly set those values to false.</p>
2972
<h2>See</h2>
3073
<ul>
31-
<li> OWASP - <a href="https://owasp.org/Top10/A03_2021-Injection/">Top 10 2021 Category A3 - Injection</a> </li>
74+
<li> OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a> </li>
75+
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">Top 10 2017 Category A3 - Sensitive Data
76+
Exposure</a> </li>
3277
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration">Top 10 2017 Category A6 - Security
3378
Misconfiguration</a> </li>
34-
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A7_2017-Cross-Site_Scripting_(XSS)">Top 10 2017 Category A7 - Cross-Site Scripting
35-
(XSS)</a> </li>
3679
<li> OWASP - <a href="https://owasp.org/www-project-mobile-top-10/2023-risks/m8-security-misconfiguration">Mobile Top 10 2024 Category M8 - Security
3780
Misconfiguration</a> </li>
81+
<li> OWASP - <a href="https://mas.owasp.org/checklists/MASVS-PLATFORM/">Mobile AppSec Verification Standard - Platform Interaction Requirements</a>
82+
</li>
3883
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/79">CWE-79 - Improper Neutralization of Input During Web Page Generation ('Cross-site
3984
Scripting')</a> </li>
85+
<li> Android Documentation - <a href="https://developer.android.com/privacy-and-security/risks/webview-unsafe-file-inclusion">WebViews - Unsafe File
86+
Inclusion</a> </li>
4087
</ul>
4188

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S6363.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
79
2626
],
2727
"OWASP": [
28-
"A6",
29-
"A7"
28+
"A3",
29+
"A6"
3030
],
3131
"MASVS": [
3232
"MSTG-PLATFORM-2"
@@ -35,7 +35,7 @@
3535
"M8"
3636
],
3737
"OWASP Top 10 2021": [
38-
"A3"
38+
"A1"
3939
],
4040
"PCI DSS 3.2": [
4141
"6.5.1",

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S7409.html

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
<p>Using Javascript interfaces in WebViews is unsafe as it allows JavaScript to invoke Java methods, potentially giving attackers access to data or
2-
sensitive app functionality. WebViews might include untrusted sources such as third-party iframes, making this functionality particularly risky. As
3-
Javascript interfaces are passed to every frame in the WebView, those iframes are also able to access the exposed Java methods.</p>
1+
<p>Using JavaScript interfaces in WebViews to expose Java objects is unsafe. Doing so allows JavaScript to invoke Java methods, potentially giving
2+
attackers access to data or sensitive app functionality. WebViews might include untrusted sources such as third-party iframes, making this
3+
functionality particularly risky. As JavaScript interfaces are passed to every frame in the WebView, those iframes are also able to access the exposed
4+
Java object.</p>
45
<h2>Ask Yourself Whether</h2>
56
<ul>
67
<li> The content in the WebView is fully trusted and secure. </li>
78
<li> Potentially untrusted iframes could be loaded in the WebView. </li>
8-
<li> The Javascript interface has to be exposed for the entire lifecycle of the WebView. </li>
9-
<li> The exposed Java methods will accept input from potentially untrusted sources. </li>
9+
<li> The JavaScript interface has to be exposed for the entire lifecycle of the WebView. </li>
10+
<li> The exposed Java object might be called by untrusted sources. </li>
1011
</ul>
1112
<p>There is a risk if you answered yes to any of these questions.</p>
1213
<h2>Recommended Secure Coding Practices</h2>
1314
<h3>Disable JavaScript</h3>
14-
<p>If it is possible to disable JavaScript in the WebView, this is the most secure option. By default, JavaScript is disabled in a WebView, so you do
15-
not need to explicitly call <code>webSettings.setJavaScriptEnabled(true)</code> in your <code>WebSettings</code> configuration. Of course, sometimes
16-
it is necessary to enable JavaScript, in which case the following recommendations should be considered.</p>
15+
<p>If it is possible to disable JavaScript in the WebView, this is the most secure option. By default, JavaScript is disabled in a WebView, so
16+
<code>webSettings.javaScriptEnabled = false</code> does not need to be explicitly called. Of course, sometimes it is necessary to enable JavaScript,
17+
in which case the following recommendations should be considered.</p>
1718
<h3>Remove JavaScript interface when loading untrusted content</h3>
1819
<p>JavaScript interfaces can be removed at a later point. It is recommended to remove the JavaScript interface when it is no longer needed. If it is
1920
needed for a longer time, consider removing it before loading untrusted content. This can be done by calling
@@ -45,7 +46,8 @@ <h2>Sensitive Code Example</h2>
4546
}
4647
</pre>
4748
<h2>Compliant Solution</h2>
48-
<p>The most secure option is to disable JavaScript entirely.</p>
49+
<p>The most secure option is to disable JavaScript entirely. {rule:kotlin:S6362} further explains why it should not be enabled unless absolutely
50+
necessary.</p>
4951
<pre>
5052
class ExampleActivity : AppCompatActivity() {
5153
override fun onCreate(savedInstanceState: Bundle?) {
@@ -85,7 +87,9 @@ <h2>Compliant Solution</h2>
8587
webView.settings.javaScriptEnabled = true
8688

8789
WebViewCompat.addWebMessageListener(
88-
webView, "androidBridge", ALLOWED_ORIGINS, // Only allow messages from these origins
90+
webView,
91+
"androidBridge",
92+
ALLOWED_ORIGINS, // Only allow messages from these origins
8993
object : WebViewCompat.WebMessageListener {
9094
override fun onPostMessage(
9195
view: WebView,
@@ -113,4 +117,8 @@ <h2>See</h2>
113117
Security Misconfiguration</a> </li>
114118
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/79">CWE-79 - Improper Neutralization of Input During Web Page Generation</a> </li>
115119
</ul>
120+
<h3>Related rules</h3>
121+
<ul>
122+
<li> {rule:kotlin:S6362} - Enabling JavaScript support for WebViews is security-sensitive </li>
123+
</ul>
116124

sonar-kotlin-plugin/src/main/resources/org/sonar/l10n/kotlin/rules/kotlin/S7409.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "Exposing Java interfaces in WebViews is security-sensitive",
2+
"title": "Exposing Java objects through JavaScript interfaces is security-sensitive",
33
"type": "SECURITY_HOTSPOT",
44
"status": "ready",
55
"remediation": {
@@ -29,7 +29,7 @@
2929
79
3030
]
3131
},
32-
"quickfix": "unknown",
32+
"quickfix": "partial",
3333
"code": {
3434
"impacts": {
3535
"SECURITY": "MEDIUM"

0 commit comments

Comments
 (0)