Skip to content

Commit 839559d

Browse files
Update rule metadata (#5306)
Co-authored-by: tomasz-tylenda-sonarsource <tomasz-tylenda-sonarsource@users.noreply.github.com>
1 parent 90551df commit 839559d

7 files changed

Lines changed: 31 additions & 57 deletions

File tree

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2053.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ <h4>Compliant solution</h4>
5151

5252
public void hash() {
5353
SecureRandom random = new SecureRandom();
54-
byte[] salt = new byte[32];
54+
byte[] salt = new byte[16];
5555
random.nextBytes(salt);
5656

5757
PBEParameterSpec cipherSpec = new PBEParameterSpec(salt, 10000);
5858
}
5959
</pre>
6060
<h3>How does this work?</h3>
6161
<p>This code ensures that each user’s password has a unique salt value associated with it. It generates a salt randomly and with a length that
62-
provides the required security level. It uses a salt length of at least 32 bytes (256 bits), as recommended by industry standards.</p>
62+
provides the required security level. It uses a salt length of at least 16 bytes (128 bits), as recommended by industry standards.</p>
6363
<p>Here, the compliant code example ensures the salt is random and has a sufficient length by calling the <code>nextBytes</code> method from the
6464
<code>SecureRandom</code> class with a salt buffer of 16 bytes. This class implements a cryptographically secure pseudo-random number generator.</p>
6565
<h2>Resources</h2>

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2612.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ <h2>Ask Yourself Whether</h2>
1111
<h2>Recommended Secure Coding Practices</h2>
1212
<p>The most restrictive possible permissions should be assigned to files and directories.</p>
1313
<h2>Sensitive Code Example</h2>
14-
<pre>
15-
public void setPermissions(String filePath) {
14+
<pre data-diff-id="1" data-diff-type="noncompliant">
15+
public void setPermissions(String filePath) throws IOException {
1616
Set&lt;PosixFilePermission&gt; perms = new HashSet&lt;PosixFilePermission&gt;();
1717
// user permission
1818
perms.add(PosixFilePermission.OWNER_READ);
@@ -29,20 +29,15 @@ <h2>Sensitive Code Example</h2>
2929
Files.setPosixFilePermissions(Paths.get(filePath), perms);
3030
}
3131
</pre>
32-
<pre>
33-
public void setPermissionsUsingRuntimeExec(String filePath) {
34-
Runtime.getRuntime().exec("chmod 777 file.json"); // Sensitive
35-
}
36-
</pre>
37-
<pre>
32+
<pre data-diff-id="2" data-diff-type="noncompliant">
3833
public void setOthersPermissionsHardCoded(String filePath ) {
3934
Files.setPosixFilePermissions(Paths.get(filePath), PosixFilePermissions.fromString("rwxrwxrwx")); // Sensitive
4035
}
4136
</pre>
4237
<h2>Compliant Solution</h2>
4338
<p>On operating systems that implement POSIX standard. This will throw a <code>UnsupportedOperationException</code> on Windows.</p>
44-
<pre>
45-
public void setPermissionsSafe(String filePath) throws IOException {
39+
<pre data-diff-id="1" data-diff-type="compliant">
40+
public void setPermissions(String filePath) throws IOException {
4641
Set&lt;PosixFilePermission&gt; perms = new HashSet&lt;PosixFilePermission&gt;();
4742
// user permission
4843
perms.add(PosixFilePermission.OWNER_READ);
@@ -52,13 +47,18 @@ <h2>Compliant Solution</h2>
5247
perms.add(PosixFilePermission.GROUP_READ);
5348
perms.add(PosixFilePermission.GROUP_EXECUTE);
5449
// others permissions removed
55-
perms.remove(PosixFilePermission.OTHERS_READ); // Compliant
56-
perms.remove(PosixFilePermission.OTHERS_WRITE); // Compliant
57-
perms.remove(PosixFilePermission.OTHERS_EXECUTE); // Compliant
50+
perms.remove(PosixFilePermission.OTHERS_READ);
51+
perms.remove(PosixFilePermission.OTHERS_WRITE);
52+
perms.remove(PosixFilePermission.OTHERS_EXECUTE);
5853

5954
Files.setPosixFilePermissions(Paths.get(filePath), perms);
6055
}
6156
</pre>
57+
<pre data-diff-id="2" data-diff-type="compliant">
58+
public void setOthersPermissionsHardCoded(String filePath ) {
59+
Files.setPosixFilePermissions(Paths.get(filePath), PosixFilePermissions.fromString("rwxrwx---"));
60+
}
61+
</pre>
6262
<h2>See</h2>
6363
<ul>
6464
<li> OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a> </li>

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S4426.html

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ <h2>Why is this an issue?</h2>
1616
<p>Note that depending on the algorithm, the term <strong>key</strong> refers to a different mathematical property. For example:</p>
1717
<ul>
1818
<li> For RSA, the key is the product of two large prime numbers, also called the <strong>modulus</strong>. </li>
19-
<li> For AES and Elliptic Curve Cryptography (ECC), the key is only a sequence of randomly generated bytes.
19+
<li> For Elliptic Curve Cryptography (ECC), the key is only a sequence of randomly generated bytes.
2020
<ul>
21-
<li> In some cases, AES keys are derived from a master key or a passphrase using a Key Derivation Function (KDF) like PBKDF2 (Password-Based Key
21+
<li> In some cases, keys are derived from a master key or a passphrase using a Key Derivation Function (KDF) like PBKDF2 (Password-Based Key
2222
Derivation Function 2) </li>
2323
</ul> </li>
2424
</ul>
@@ -66,21 +66,6 @@ <h4>Noncompliant code example</h4>
6666
}
6767
}
6868
</pre>
69-
<p>Here is an example of a private key generation with AES:</p>
70-
<pre data-diff-id="2" data-diff-type="noncompliant">
71-
import java.security.KeyGenerator;
72-
import java.security.NoSuchAlgorithmException;
73-
74-
public static void main(String[] args) {
75-
try {
76-
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
77-
keyGenerator.initialize(64); // Noncompliant
78-
79-
} catch (NoSuchAlgorithmException e) {
80-
// ...
81-
}
82-
}
83-
</pre>
8469
<p>Here is an example of an Elliptic Curve (EC) initialization. It implicitly generates a private key whose size is indicated in the elliptic curve
8570
name:</p>
8671
<pre data-diff-id="3" data-diff-type="noncompliant">
@@ -115,20 +100,6 @@ <h4>Compliant solution</h4>
115100
}
116101
}
117102
</pre>
118-
<pre data-diff-id="2" data-diff-type="compliant">
119-
import java.security.KeyPairGenerator;
120-
import java.security.NoSuchAlgorithmException;
121-
122-
public static void main(String[] args) {
123-
try {
124-
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("AES");
125-
keyPairGenerator.initialize(128);
126-
127-
} catch (NoSuchAlgorithmException e) {
128-
// ...
129-
}
130-
}
131-
</pre>
132103
<pre data-diff-id="3" data-diff-type="compliant">
133104
import java.security.KeyPairGenerator;
134105
import java.security.NoSuchAlgorithmException;
@@ -153,11 +124,6 @@ <h4>RSA (Rivest-Shamir-Adleman) and DSA (Digital Signature Algorithm)</h4>
153124
<p>The security of these algorithms depends on the difficulty of attacks attempting to solve their underlying mathematical problem.</p>
154125
<p>In general, a minimum key size of <strong>2048</strong> bits is recommended for both. It provides 112 bits of security. A key length of
155126
<strong>3072</strong> or <strong>4096</strong> should be preferred when possible.</p>
156-
<h4>AES (Advanced Encryption Standard)</h4>
157-
<p>AES supports three key sizes: 128 bits, 192 bits and 256 bits. The security of the AES algorithm is based on the computational complexity of trying
158-
all possible keys.<br> A larger key size increases the number of possible keys and makes exhaustive search attacks computationally infeasible.
159-
Therefore, a 256-bit key provides a higher level of security than a 128-bit or 192-bit key.</p>
160-
<p>Currently, a minimum key size of <strong>128 bits</strong> is recommended for AES.</p>
161127
<h4>Elliptic Curve Cryptography (ECC)</h4>
162128
<p>Elliptic curve cryptography is also used in various algorithms, such as ECDSA, ECDH, or ECMQV. The length of keys generated with elliptic curve
163129
algorithms is mentioned directly in their names. For example, <code>secp256k1</code> generates a 256-bits long private key.</p>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
],
3434
"OWASP Top 10 2021": [
3535
"A5"
36+
],
37+
"ASVS 4.0": [
38+
"14.3.2"
3639
]
3740
},
3841
"quickfix": "unknown"

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S6246.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
<p>This rule reports an issue when a lambda invokes another lambda synchronously.</p>
12
<h2>Why is this an issue?</h2>
23
<p>Invoking other Lambdas synchronously from a Lambda is a scalability anti-pattern. Lambdas have a maximum execution time before they timeout (15
3-
minutes as of May 2021). Having to wait for another Lambda to finish its execution could lead to a timeout.</p>
4+
minutes as of June 2025). Having to wait for another Lambda to finish its execution could lead to a timeout.</p>
45
<p>A better solution is to generate&nbsp;events that can be consumed asynchronously by other Lambdas.</p>
56
<h3>Noncompliant code example</h3>
67
<p>With AWS SDKv1</p>

sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S6363.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
<p>Exposing the Android file system to WebViews is security-sensitive.</p>
21
<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
2+
The severity of this risk depends heavily on the specific settings configured for the WebView. Overly permissive settings can allow malicious scripts
43
to access a wide range of local files, potentially exposing sensitive data such as Personally Identifiable Information (PII) or private application
54
data, leading to data breaches and other security compromises.</p>
65
<h2>Ask Yourself Whether</h2>
@@ -11,8 +10,13 @@ <h2>Ask Yourself Whether</h2>
1110
<p>There is a risk if you answered yes to any of these questions.</p>
1211
<h2>Recommended Secure Coding Practices</h2>
1312
<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>
13+
sources, do not enable this functionality.</p>
14+
<p>On Android, it is recommended to use <code>androidx.webkit.WebViewAssetLoader</code> to access files, including assets and resources, via a custom,
15+
controllable scheme.</p>
16+
<p>On iOS, it is recommended to use Bundles to access local files, keeping access limited a controlled subset using the
17+
<code>allowingReadAccessTo</code> parameter of the <code>loadFileURL</code> method. If <code>allowFileAccessFromFileURLs</code> and
18+
<code>allowUniversalAccessFromFileURLs</code> are not enabled, it is not possible to access files outside the intended directory. It is also possible
19+
to create a custom scheme to access local files, but this is more complex and might lead to unintended security issues.</p>
1620
<p>For enhanced security, ensure that the options to load <code>file://</code> URLs are explicitly set to false.</p>
1721
<h2>Sensitive Code Example</h2>
1822
<pre>

sonarpedia.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"languages": [
44
"JAVA"
55
],
6-
"latest-update": "2025-08-04T14:06:07.748110868Z",
6+
"latest-update": "2025-09-29T08:08:50.655366545Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": false

0 commit comments

Comments
 (0)