Skip to content

Commit 9682d60

Browse files
SONARXML-198 Update rule metadata (#309)
1 parent 2cc57a6 commit 9682d60

29 files changed

+525
-226
lines changed
Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,67 @@
1+
<p>Indentation should be consistent to make the code easy to read, review and modify. To fix this issue, change the indentation so that the text
2+
starts at the expected column.</p>
13
<h2>Why is this an issue?</h2>
2-
<p>Proper indentation is a simple and effective way to improve the code’s readability. Consistent indentation among the developers within a team also
3-
reduces the differences that are committed to source control systems, making code reviews easier.</p>
4-
<p>By default this rule checks that each block of code is indented, although it does not check the size of the indent. Parameter "indentSize" allows
5-
the expected indent size to be defined. Only the first line of a badly indented section is reported.</p>
4+
<p>Consistent indentation is a simple and effective way to improve the code’s readability. It reduces the differences that are committed to source
5+
control systems, making code reviews easier.</p>
6+
<p>This rule raises an issue when the indentation does not match the configured value. Only the first line of a badly indented section is
7+
reported.</p>
8+
<h3>What is the potential impact?</h3>
9+
<p>The readability is decreased. It becomes more tedious to review and modify the code.</p>
10+
<h2>How to fix it</h2>
11+
<p>Change the indentation so that the text starts at the expected column. The expected column should be the configured indent size multiplied by the
12+
level at which the code block is nested.</p>
13+
<h3>Code examples</h3>
14+
<h4>Noncompliant code example</h4>
15+
<p>With an indent size of 2:</p>
16+
<pre data-diff-id="1" data-diff-type="noncompliant">
17+
&lt;?xml version="1.0"?&gt;
18+
&lt;catalog&gt;
19+
&lt;book id="bk101"&gt;
20+
&lt;author&gt;Gambardella, Matthew&lt;/author&gt;
21+
&lt;title&gt;XML Developer's Guide&lt;/title&gt; &lt;!-- Noncompliant, expected to start at column 4 --&gt;
22+
&lt;genre&gt;Computer&lt;/genre&gt;
23+
&lt;price&gt;44.95&lt;/price&gt;
24+
&lt;publish_date&gt;2000-10-01&lt;/publish_date&gt;
25+
&lt;description&gt;An in-depth look at creating applications
26+
with XML.&lt;/description&gt;
27+
&lt;/book&gt;
28+
&lt;book id="bk102"&gt; &lt;!-- Noncompliant, expected to start at column 2 --&gt;
29+
&lt;author&gt;Ralls, Kim&lt;/author&gt;
30+
&lt;title&gt;Midnight Rain&lt;/title&gt;
31+
&lt;genre&gt;Fantasy&lt;/genre&gt;
32+
&lt;price&gt;5.95&lt;/price&gt;
33+
&lt;publish_date&gt;2000-12-16&lt;/publish_date&gt;
34+
&lt;description&gt;A former architect battles corporate zombies,
35+
an evil sorceress, and her own childhood to become queen
36+
of the world.&lt;/description&gt;
37+
&lt;/book&gt;
38+
&lt;/catalog&gt;
39+
</pre>
40+
<h4>Compliant solution</h4>
41+
<pre data-diff-id="1" data-diff-type="compliant">
42+
&lt;?xml version="1.0"?&gt;
43+
&lt;catalog&gt;
44+
&lt;book id="bk101"&gt;
45+
&lt;author&gt;Gambardella, Matthew&lt;/author&gt;
46+
&lt;title&gt;XML Developer's Guide&lt;/title&gt;
47+
&lt;genre&gt;Computer&lt;/genre&gt;
48+
&lt;price&gt;44.95&lt;/price&gt;
49+
&lt;publish_date&gt;2000-10-01&lt;/publish_date&gt;
50+
&lt;description&gt;An in-depth look at creating applications
51+
with XML.&lt;/description&gt;
52+
&lt;/book&gt;
53+
&lt;book id="bk102"&gt;
54+
&lt;author&gt;Ralls, Kim&lt;/author&gt;
55+
&lt;title&gt;Midnight Rain&lt;/title&gt;
56+
&lt;genre&gt;Fantasy&lt;/genre&gt;
57+
&lt;price&gt;5.95&lt;/price&gt;
58+
&lt;publish_date&gt;2000-12-16&lt;/publish_date&gt;
59+
&lt;description&gt;A former architect battles corporate zombies,
60+
an evil sorceress, and her own childhood to become queen
61+
of the world.&lt;/description&gt;
62+
&lt;/book&gt;
63+
&lt;/catalog&gt;
64+
</pre>
65+
<h3>Going the extra mile</h3>
66+
<p>You can adopt a tool or configure your IDE to take care of code formatting automatically.</p>
667

sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S1134.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ <h2>Why is this an issue?</h2>
1313
<h2>Resources</h2>
1414
<h3>Documentation</h3>
1515
<ul>
16-
<li> <a href="https://cwe.mitre.org/data/definitions/546">MITRE, CWE-546 - Suspicious Comment</a> </li>
16+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
1717
</ul>
1818

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
<h2>Why is this an issue?</h2>
2-
<p><code>TODO</code> tags are commonly used to mark places where some more code is required, but which the developer wants to implement later.</p>
3-
<p>Sometimes the developer will not have the time or will simply forget to get back to that tag.</p>
4-
<p>This rule is meant to track those tags and to ensure that they do not go unnoticed.</p>
2+
<p>Developers often use <code>TODO</code> tags to mark areas in the code where additional work or improvements are needed but are not implemented
3+
immediately. However, these <code>TODO</code> tags sometimes get overlooked or forgotten, leading to incomplete or unfinished code. This rule aims to
4+
identify and address unattended <code>TODO</code> tags to ensure a clean and maintainable codebase. This description explores why this is a problem
5+
and how it can be fixed to improve the overall code quality.</p>
6+
<h3>What is the potential impact?</h3>
7+
<p>Unattended <code>TODO</code> tags in code can have significant implications for the development process and the overall codebase.</p>
8+
<p>Incomplete Functionality: When developers leave <code>TODO</code> tags without implementing the corresponding code, it results in incomplete
9+
functionality within the software. This can lead to unexpected behavior or missing features, adversely affecting the end-user experience.</p>
10+
<p>Missed Bug Fixes: If developers do not promptly address <code>TODO</code> tags, they might overlook critical bug fixes and security updates.
11+
Delayed bug fixes can result in more severe issues and increase the effort required to resolve them later.</p>
12+
<p>Impact on Collaboration: In team-based development environments, unattended <code>TODO</code> tags can hinder collaboration. Other team members
13+
might not be aware of the intended changes, leading to conflicts or redundant efforts in the codebase.</p>
14+
<p>Codebase Bloat: The accumulation of unattended <code>TODO</code> tags over time can clutter the codebase and make it difficult to distinguish
15+
between work in progress and completed code. This bloat can make it challenging to maintain an organized and efficient codebase.</p>
16+
<p>Addressing this code smell is essential to ensure a maintainable, readable, reliable codebase and promote effective collaboration among
17+
developers.</p>
518
<h3>Noncompliant code example</h3>
619
<pre>
720
&lt;!-- TODO Drop this dependency --&gt;
@@ -13,6 +26,6 @@ <h3>Noncompliant code example</h3>
1326
</pre>
1427
<h2>Resources</h2>
1528
<ul>
16-
<li> <a href="https://cwe.mitre.org/data/definitions/546">MITRE, CWE-546</a> - Suspicious Comment </li>
29+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
1730
</ul>
1831

sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S1135.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
546
2525
]
2626
},
27-
"quickfix": "unknown"
27+
"quickfix": "infeasible"
2828
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Programmers should not comment out code as it bloats programs and reduces readability.</p>
3-
<p>Unused code should be deleted and can be retrieved from source control history if required.</p>
2+
<p>Commented-out code distracts the focus from the actual executed code. It creates a noise that increases maintenance code. And because it is never
3+
executed, it quickly becomes out of date and invalid.</p>
4+
<p>Commented-out code should be deleted and can be retrieved from source control history if required.</p>
45

sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S2068.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ <h2>Compliant Solution</h2>
6262
</pre>
6363
<h2>See</h2>
6464
<ul>
65-
<li> <a href="https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/">OWASP Top 10 2021 Category A7</a> - Identification and
66-
Authentication Failures </li>
67-
<li> <a href="https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication">OWASP Top 10 2017 Category A2</a> - Broken Authentication
65+
<li> OWASP - <a href="https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/">Top 10 2021 Category A7 - Identification and
66+
Authentication Failures</a> </li>
67+
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication">Top 10 2017 Category A2 - Broken Authentication</a>
6868
</li>
69-
<li> <a href="https://cwe.mitre.org/data/definitions/798">MITRE, CWE-798</a> - Use of Hard-coded Credentials </li>
70-
<li> <a href="https://cwe.mitre.org/data/definitions/259">MITRE, CWE-259</a> - Use of Hard-coded Password </li>
71-
<li> <a href="https://www.sans.org/top25-software-errors/#cat3">SANS Top 25</a> - Porous Defenses </li>
69+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/798">CWE-798 - Use of Hard-coded Credentials</a> </li>
70+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/259">CWE-259 - Use of Hard-coded Password</a> </li>
7271
<li> Derived from FindSecBugs rule <a href="https://h3xstream.github.io/find-sec-bugs/bugs.htm#HARD_CODE_PASSWORD">Hard Coded Password</a> </li>
7372
</ul>
7473

sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S2260.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"ruleSpecification": "RSPEC-2260",
1414
"sqKey": "S2260",
1515
"scope": "All",
16-
"quickfix": "unknown"
16+
"quickfix": "infeasible"
1717
}
Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,92 @@
1+
<p>This rule is deprecated, and will eventually be removed.</p>
2+
<p>Basic authentication is a vulnerable method of user authentication that should be avoided. It functions by transmitting a Base64 encoded username
3+
and password. As Base64 is easy to recognize and reverse, sensitive data may be leaked this way.</p>
14
<h2>Why is this an issue?</h2>
2-
<p>Basic authentication’s only means of obfuscation is Base64 encoding. Since Base64 encoding is easily recognized and reversed, it offers only the
3-
thinnest veil of protection to your users, and should not be used.</p>
4-
<h3>Noncompliant code example</h3>
5-
<pre>
6-
// in web.xml
7-
&lt;web-app ...&gt;
8-
&lt;!-- ... --&gt;
5+
<p>Basic authentication is a simple and widely used method of user authentication for HTTP requests. When a client sends a request to a server that
6+
requires authentication, the client includes the username and password (concatenated together and Base64 encoded) in the "Authorization" header of the
7+
HTTP request. The server verifies the credentials and grants access if they are valid. Every request sent to the server to a protected endpoint must
8+
include these credentials.</p>
9+
<p>Basic authentication is considered insecure for several reasons:</p>
10+
<ul>
11+
<li> It transmits user credentials in plain text, making them susceptible to interception and eavesdropping. </li>
12+
<li> It relies solely on the server’s ability to verify the provided credentials. There is no mechanism for additional security measures like
13+
multi-factor authentication or account lockouts after multiple failed login attempts. </li>
14+
<li> It does not provide a way to manage user sessions securely. The client typically includes the credentials in every request, which creates more
15+
opportunities for an attacker to steal these credentials. </li>
16+
</ul>
17+
<p>These security limitations make basic authentication an insecure choice for authentication or authorization over HTTP.</p>
18+
<h3>What is the potential impact?</h3>
19+
<p>Basic authentication transmits passwords in plain text, which makes it vulnerable to interception by attackers.</p>
20+
<h4>Session hijacking and man-in-the-middle attack</h4>
21+
<p>If an attacker gains access to the network traffic, they can easily capture the username and password. Basic authentication does not provide any
22+
mechanism to protect against session hijacking attacks. Once a user is authenticated, the session identifier (the username and password) is sent in
23+
clear text with each subsequent request. If attackers can intercept one request, they can use it to impersonate the authenticated user, gaining
24+
unauthorized access to their account and potentially performing malicious actions.</p>
25+
<h4>Brute-force attacks</h4>
26+
<p>Basic authentication does not have any built-in protection against brute-force attacks. Attackers can repeatedly guess passwords until they find
27+
the correct one, especially if weak or commonly used passwords are used. This can lead to unauthorized access to user accounts and potential data
28+
breaches.</p>
29+
<h2>How to fix it in Java EE</h2>
30+
<h3>Code examples</h3>
31+
<p>The following code uses basic authentication to protect web server endpoints.</p>
32+
<h4>Noncompliant code example</h4>
33+
<pre data-diff-id="201" data-diff-type="noncompliant">
34+
&lt;!-- web.xml --&gt;
35+
&lt;web-app&gt;
936
&lt;login-config&gt;
1037
&lt;auth-method&gt;BASIC&lt;/auth-method&gt;
1138
&lt;/login-config&gt;
1239
&lt;/web-app&gt;
1340
</pre>
14-
<h3>Exceptions</h3>
15-
<p>The rule will not raise any issue if HTTPS is enabled, on any URL-pattern.</p>
16-
<pre>
17-
&lt;web-app ...&gt;
18-
&lt;!-- ... --&gt;
19-
&lt;security-constraint&gt;
20-
&lt;web-resource-collection&gt;
21-
&lt;web-resource-name&gt;HTTPS enabled&lt;/web-resource-name&gt;
22-
&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
23-
&lt;/web-resource-collection&gt;
24-
&lt;user-data-constraint&gt;
25-
&lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
26-
&lt;/user-data-constraint&gt;
27-
&lt;/security-constraint&gt;
41+
<h4>Compliant solution</h4>
42+
<pre data-diff-id="201" data-diff-type="compliant">
43+
&lt;!-- web.xml --&gt;
44+
&lt;web-app&gt;
45+
&lt;login-config&gt;
46+
&lt;auth-method&gt;FORM&lt;/auth-method&gt;
47+
&lt;form-login-config&gt;
48+
&lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt;
49+
&lt;form-error-page&gt;/login-error.jsp&lt;/form-error-page&gt;
50+
&lt;/form-login-config&gt;
51+
&lt;/login-config&gt;
2852
&lt;/web-app&gt;
2953
</pre>
54+
<h3>How does this work?</h3>
55+
<h4>Token-based authentication and OAuth</h4>
56+
<p>Token-based authentication is a safer alternative than basic authentication. A unique token is generated upon successful authentication and sent to
57+
the client, which is then included in subsequent requests. Therefore, it eliminates the need to transmit sensitive credentials with each request.
58+
OAuth also works by authenticating users via tokens. It gives even more flexibility on top of this by offering scopes, which limit an application’s
59+
access to a user’s account.</p>
60+
<p>Additionally, both token-based authentication and OAuth support mechanisms for token expiration, revocation, and refresh. This gives more
61+
flexibility than basic authentication, as compromised tokens carry much less risk than a compromised password.</p>
62+
<p>The Jakarta EE Security API offers robust and standardized methods to handle authentication and authorization in Jakarta EE applications. In the
63+
example, form-based authentication is applied to the <code>web.xml</code> configuration file. After a user successfully logs into the application, a
64+
session is created for the user. A session token is stored in a cookie and is used for subsequent requests.</p>
65+
<h4>Integrate with an Identity and Access Management (IAM) System</h4>
66+
<p>For more advanced authentication and authorization capabilities, consider integrating the backend with an IAM system. Doing so gives access to
67+
features like single sign-on (SSO), role-based access control, and centralized user management. As of Jakarta EE 10, support for OpenID Connect (OIDC)
68+
is included. Using this authentication method, several OIDC providers can be integrated easily, such as Auth0, Okta, and Azure Active Directory.</p>
69+
<h4>SSL encryption for HTTP requests</h4>
70+
<p>With basic authentication, user credentials are transmitted in plain text, which makes them vulnerable to interception and eavesdropping. However,
71+
when HTTPS is employed, the data is encrypted before transmission, making it significantly more difficult for attackers to intercept and decipher the
72+
credentials. If no other form of authentication is possible for this code, then every request must be sent over HTTPS to ensure credentials are kept
73+
safe.</p>
74+
<p>In Jakarta EE, HTTPS traffic can be enabled by setting the <code>transportGuarantee</code> attribute to <code>CONFIDENTIAL</code> in
75+
<code>web.xml</code>.</p>
3076
<h2>Resources</h2>
77+
<h3>Documentation</h3>
78+
<ul>
79+
<li> MDN web docs - <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a> </li>
80+
</ul>
81+
<h3>Standards</h3>
3182
<ul>
32-
<li> <a href="https://owasp.org/Top10/A04_2021-Insecure_Design/">OWASP Top 10 2021 Category A4</a> - Insecure Design </li>
33-
<li> <a href="https://www.owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">OWASP Top 10 2017 Category A3</a> - Sensitive Data
34-
Exposure </li>
83+
<li> OWASP - <a href="https://owasp.org/Top10/A04_2021-Insecure_Design/">Top 10 2021 Category A4 - Insecure Design</a> </li>
84+
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">Top 10 2017 Category A3 - Sensitive Data
85+
Exposure</a> </li>
3586
<li> <a href="https://cheatsheetseries.owasp.org/cheatsheets/Web_Service_Security_Cheat_Sheet.html#user-authentication">OWASP Web Service Security
3687
Cheat Sheet</a> </li>
37-
<li> <a href="https://cwe.mitre.org/data/definitions/522">MITRE, CWE-522</a> - Insufficiently Protected Credentials </li>
38-
<li> <a href="https://www.sans.org/top25-software-errors/#cat3">SANS Top 25</a> - Porous Defenses </li>
88+
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/522">CWE-522 - Insufficiently Protected Credentials</a> </li>
89+
<li> STIG Viewer - <a href="https://stigviewer.com/stig/application_security_and_development/2023-06-08/finding/V-222533">Application Security and
90+
Development: V-222533</a> - The application must authenticate all network connected endpoint devices before establishing any connection. </li>
3991
</ul>
4092

sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S2647.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
"impacts": {
66
"SECURITY": "HIGH"
77
},
8-
"attribute": "COMPLETE"
8+
"attribute": "TRUSTWORTHY"
99
},
10-
"status": "ready",
10+
"status": "deprecated",
1111
"remediation": {
1212
"func": "Constant\/Issue",
1313
"constantCost": "2h"
1414
},
15-
"tags": [
16-
"cwe"
17-
],
15+
"tags": [],
1816
"defaultSeverity": "Critical",
1917
"ruleSpecification": "RSPEC-2647",
2018
"sqKey": "S2647",
@@ -37,6 +35,9 @@
3735
],
3836
"ASVS 4.0": [
3937
"2.10.3"
38+
],
39+
"STIG ASD_V5R3": [
40+
"V-222533"
4041
]
4142
},
4243
"quickfix": "unknown"

0 commit comments

Comments
 (0)