Skip to content

Commit 64cc4eb

Browse files
github-actions[bot]thomas-serre-sonarsource
authored andcommitted
Update rule metadata (#834)
Co-authored-by: thomas-serre-sonarsource <118730793+thomas-serre-sonarsource@users.noreply.github.com> GitOrigin-RevId: ab5d1e167c9e49b02df1df7cb512c9ebfa102bb8
1 parent df464a6 commit 64cc4eb

17 files changed

Lines changed: 95 additions & 112 deletions

File tree

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2068.html

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
1-
<p>Because it is easy to extract strings from an application source code or binary, credentials should not be hard-coded. This is particularly true
2-
for applications that are distributed or that are open-source.</p>
1+
<h2>Why is this an issue?</h2>
2+
<p>Hard-coding credentials in source code or binaries makes it easy for attackers to extract sensitive information, especially in distributed or
3+
open-source applications. This practice exposes your application to significant security risks.</p>
4+
<p>This rule flags instances of hard-coded credentials used in database and LDAP connections. It looks for hard-coded credentials in connection
5+
strings, and for variable names that match any of the patterns from the provided list.</p>
36
<p>In the past, it has led to the following vulnerabilities:</p>
47
<ul>
58
<li> <a href="https://www.cve.org/CVERecord?id=CVE-2019-13466">CVE-2019-13466</a> </li>
69
<li> <a href="https://www.cve.org/CVERecord?id=CVE-2018-15389">CVE-2018-15389</a> </li>
710
</ul>
8-
<p>Credentials should be stored outside of the code in a configuration file, a database, or a management service for secrets.</p>
9-
<p>This rule flags instances of hard-coded credentials used in database and LDAP connections. It looks for hard-coded credentials in connection
10-
strings, and for variable names that match any of the patterns from the provided list.</p>
11-
<h2>Ask Yourself Whether</h2>
12-
<ul>
13-
<li> Credentials allow access to a sensitive component like a database, a file storage, an API or a service. </li>
14-
<li> Credentials are used in production environments. </li>
15-
<li> Application re-distribution is required before updating the credentials. </li>
16-
</ul>
17-
<p>There is a risk if you answered yes to any of those questions.</p>
18-
<h2>Recommended Secure Coding Practices</h2>
19-
<ul>
20-
<li> Store the credentials in a configuration file that is not pushed to the code repository. </li>
21-
<li> Store the credentials in a database. </li>
22-
<li> Use your cloud provider’s service for managing secrets. </li>
23-
<li> If a password has been disclosed through the source code: change it. </li>
24-
</ul>
25-
<h2>Sensitive Code Example</h2>
26-
<pre>
11+
<h2>How to fix it</h2>
12+
<p>Credentials should be stored in a configuration file that is not committed to the code repository, in a database, or managed by your cloud
13+
provider’s secrets management service. If a password is exposed in the source code, it must be changed immediately.</p>
14+
<h3>Code Examples</h3>
15+
<h4>Noncompliant code example</h4>
16+
<pre data-diff-id="1" data-diff-type="noncompliant">
2717
username = 'admin'
28-
password = 'admin' # Sensitive
29-
usernamePassword = 'user=admin&amp;password=admin' # Sensitive
18+
password = 'admin' # Noncompliant
19+
usernamePassword = 'user=admin&amp;password=admin' # Noncompliant
3020
</pre>
31-
<h2>Compliant Solution</h2>
32-
<pre>
21+
<h4>Compliant solution</h4>
22+
<pre data-diff-id="1" data-diff-type="compliant">
3323
import os
3424

3525
username = os.getenv("username") # Compliant
3626
password = os.getenv("password") # Compliant
37-
usernamePassword = 'user=%s&amp;password=%s' % (username, password) # Compliant{code}
27+
usernamePassword = 'user=%s&amp;password=%s' % (username, password) # Compliant
3828
</pre>
39-
<h2>See</h2>
29+
<h2>Resources</h2>
4030
<ul>
4131
<li> OWASP - <a href="https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/">Top 10 2021 Category A7 - Identification and
4232
Authentication Failures</a> </li>

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2068.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"title": "Hard-coded passwords are security-sensitive",
3-
"type": "SECURITY_HOTSPOT",
2+
"title": "Credentials should not be hard-coded",
3+
"type": "VULNERABILITY",
44
"code": {
55
"impacts": {
66
"SECURITY": "BLOCKER"
@@ -12,6 +12,7 @@
1212
"func": "Constant\/Issue",
1313
"constantCost": "30min"
1414
},
15+
"quickfix": "infeasible",
1516
"tags": [
1617
"cwe"
1718
],
@@ -41,6 +42,5 @@
4142
"3.5.2",
4243
"6.4.1"
4344
]
44-
},
45-
"quickfix": "unknown"
45+
}
4646
}

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6418.html

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
<p>Because it is easy to extract strings from an application source code or binary, secrets should not be hard-coded. This is particularly true for
2-
applications that are distributed or that are open-source.</p>
3-
<p>In the past, it has led to the following vulnerabilities:</p>
4-
<ul>
5-
<li> <a href="https://www.cve.org/CVERecord?id=CVE-2022-25510">CVE-2022-25510</a> </li>
6-
<li> <a href="https://www.cve.org/CVERecord?id=CVE-2021-42635">CVE-2021-42635</a> </li>
7-
</ul>
8-
<p>Secrets should be stored outside of the source code in a configuration file or a management service for secrets.</p>
1+
<h2>Why is this an issue?</h2>
2+
<p>Hard-coding secrets in source code or binaries makes it easy for attackers to extract sensitive information, especially in distributed or
3+
open-source applications. This practice exposes credentials and tokens, increasing the risk of unauthorized access and data breaches.</p>
94
<p>This rule detects variables/fields having a name matching a list of words (secret, token, credential, auth, api[_.-]?key) being assigned a
105
pseudorandom hard-coded value. The pseudorandomness of the hard-coded value is based on its entropy and the probability to be human-readable. The
116
randomness sensibility can be adjusted if needed. Lower values will detect less random values, raising potentially more false positives.</p>
12-
<h2>Ask Yourself Whether</h2>
13-
<ul>
14-
<li> The secret allows access to a sensitive component like a database, a file storage, an API, or a service. </li>
15-
<li> The secret is used in a production environment. </li>
16-
<li> Application re-distribution is required before updating the secret. </li>
17-
</ul>
18-
<p>There would be a risk if you answered yes to any of those questions.</p>
19-
<h2>Recommended Secure Coding Practices</h2>
20-
<ul>
21-
<li> Store the secret in a configuration file that is not pushed to the code repository. </li>
22-
<li> Use your cloud provider’s service for managing secrets. </li>
23-
<li> If a secret has been disclosed through the source code: revoke it and create a new one. </li>
24-
</ul>
25-
<h2>Sensitive Code Example</h2>
26-
<pre>
7+
<h2>How to fix it</h2>
8+
<p>Secrets should be stored in a configuration file that is not committed to the code repository, in a database, or managed by your cloud provider’s
9+
secrets management service. If a secret is exposed in the source code, it must be rotated immediately.</p>
10+
<h3>Code Examples</h3>
11+
<h4>Noncompliant code example</h4>
12+
<pre data-diff-id="1" data-diff-type="noncompliant">
2713
import requests
2814

2915
API_KEY = "1234567890abcdef" # Hard-coded secret (bad practice)
@@ -34,10 +20,10 @@ <h2>Sensitive Code Example</h2>
3420
}
3521
return requests.post("https://api.example.com", headers=headers, data=data)
3622
</pre>
37-
<h2>Compliant Solution</h2>
23+
<h4>Compliant solution</h4>
3824
<p>Using <a href="https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/python/example_code/secretsmanager/scenario_get_secret.py">AWS Secrets
3925
Manager</a>:</p>
40-
<pre>
26+
<pre data-diff-id="1" data-diff-type="compliant">
4127
import boto3
4228
import logging
4329

@@ -73,13 +59,14 @@ <h2>Compliant Solution</h2>
7359
}
7460
return requests.post("https://api.example.com", headers=headers, data=data)
7561
</pre>
76-
<h2>See</h2>
62+
<h2>Resources</h2>
7763
<ul>
7864
<li> OWASP - <a href="https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/">Top 10 2021 Category A7 - Identification and
7965
Authentication Failures</a> </li>
8066
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication">Top 10 2017 Category A2 - Broken Authentication</a>
8167
</li>
8268
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/798">CWE-798 - Use of Hard-coded Credentials</a> </li>
69+
<li> MSC - <a href="https://wiki.sei.cmu.edu/confluence/x/OjdGBQ">MSC03-J - Never hard code sensitive information</a> </li>
8370
<li> AWS Secrets Manager - <a href="https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/secretsmanager">Code Examples</a>
8471
</li>
8572
<li> Azure Key Vault - <a href="https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-python?tabs=azure-cli">Quickstart</a> </li>

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6418.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"title": "Hard-coded secrets are security-sensitive",
3-
"type": "SECURITY_HOTSPOT",
2+
"title": "Secrets should not be hard-coded",
3+
"type": "VULNERABILITY",
44
"code": {
55
"impacts": {
66
"SECURITY": "BLOCKER"
@@ -12,6 +12,7 @@
1212
"func": "Constant\/Issue",
1313
"constantCost": "30min"
1414
},
15+
"quickfix": "infeasible",
1516
"tags": [
1617
"cwe"
1718
],
@@ -40,6 +41,5 @@
4041
"3.5.2",
4142
"6.4.1"
4243
]
43-
},
44-
"quickfix": "unknown"
44+
}
4545
}

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6552.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ <h4>Compliant solution</h4>
5353
<h2>Resources</h2>
5454
<h3>Documentation</h3>
5555
<ul>
56-
<li> <a href="https://docs.djangoproject.com/en/4.1/topics/signals/">Django signals</a> </li>
57-
<li> <a href="https://flask.palletsprojects.com/en/stable/patterns/viewdecorators/">Flask View Decorators</a> </li>
58-
<li> <a href="https://flask.palletsprojects.com/en/stable/quickstart/#routing">Flask Routing</a> </li>
56+
<li> Django - <a href="https://docs.djangoproject.com/en/4.1/topics/signals/">Signals</a> </li>
57+
<li> Flask - <a href="https://flask.palletsprojects.com/en/stable/patterns/viewdecorators/">View Decorators</a> </li>
58+
<li> Flask - <a href="https://flask.palletsprojects.com/en/stable/quickstart/#routing">Routing</a> </li>
5959
</ul>
6060

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S8371.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ <h2>Why is this an issue?</h2>
55
dictionary-style access like <code>request.headers['Authorization']</code>, Flask raises a KeyError if the header is missing.</p>
66
<p>This can cause your application to crash unexpectedly, especially when dealing with optional headers like authentication tokens, custom headers, or
77
headers that vary between different clients and browsers.</p>
8+
<p>Even when the header presence appears to be validated by guards or preconditions, dictionary-style access introduces unnecessary risk due to
9+
potential refactoring.</p>
810
<p>The <code>.get()</code> method provides a safer alternative by returning <code>None</code> (or a default value) when a header is missing, allowing
9-
your code to handle the absence gracefully instead of crashing.</p>
11+
your code to handle the absence gracefully instead of crashing. Using <code>.get()</code> consistently throughout your codebase establishes a robust
12+
pattern that prevents runtime errors, improves code maintainability, and makes the optional nature of headers explicit in the code.</p>
1013
<h3>What is the potential impact?</h3>
1114
<p>A missing header will cause a KeyError exception, potentially crashing the request handler and returning a 500 Internal Server Error to the client.
1215
This creates a poor user experience and can make your application appear unreliable.</p>
1316
<p>In security-sensitive contexts, unexpected crashes might also expose error information that could be useful to attackers.</p>
1417
<h2>How to fix it</h2>
15-
<p>Replace dictionary-style header read access with the <code>.get()</code> method. This returns <code>None</code> for missing headers instead of
16-
raising an exception. Add appropriate checks to handle missing headers gracefully.</p>
18+
<p>Always use the <code>.get()</code> method instead of dictionary-style header access. This returns <code>None</code> for missing headers instead of
19+
raising an exception, and should be used consistently even when guards appear to protect the access. This consistent approach:</p>
20+
<ul>
21+
<li> Prevents KeyError exceptions from missing headers </li>
22+
<li> Makes the optional nature of headers explicit in the code </li>
23+
<li> Reduces the risk of runtime errors during code evolution and refactoring </li>
24+
</ul>
25+
<p>Add appropriate checks to handle missing headers gracefully after retrieving them with <code>.get()</code>.</p>
1726
<h3>Code examples</h3>
1827
<h4>Noncompliant code example</h4>
1928
<pre data-diff-id="1" data-diff-type="noncompliant">

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S8375.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h2>Resources</h2>
3636
<h3>Documentation</h3>
3737
<ul>
3838
<li> Flask preprocess_request documentation - <a href="https://flask.palletsprojects.com/en/stable/api/#flask.Flask.preprocess_request">Official
39-
Flask documentation for the preprocess_request method</a> </li>
39+
documentation</a> </li>
4040
<li> Flask Request Hooks - <a href="https://flask.palletsprojects.com/en/stable/reqcontext/#request-hooks">Documentation about Flask’s
4141
before-request and after-request hooks</a> </li>
4242
</ul>

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S8375.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"constantCost": "5 min"
88
},
99
"tags": [
10-
"flask",
11-
"security",
12-
"bug-prone"
10+
"flask"
1311
],
1412
"defaultSeverity": "Blocker",
1513
"ruleSpecification": "RSPEC-8375",

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S8389.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,5 @@ <h3>Documentation</h3>
168168
encoding</a> </li>
169169
<li> Pydantic - Validators - <a href="https://docs.pydantic.dev/latest/concepts/validators/">Documentation on Pydantic validators for custom data
170170
parsing</a> </li>
171-
<li> OWASP - Logging Cheat Sheet - <a href="https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html">Guidelines on what data should
172-
not be logged, including query parameters with sensitive data</a> </li>
173-
</ul>
174-
<h3>Standards</h3>
175-
<ul>
176-
<li> OWASP Top 10 2021 A01 - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Broken Access Control - exposing sensitive data in
177-
URLs can lead to unauthorized access</a> </li>
178-
<li> OWASP Top 10 2021 A09 - <a href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">Security Logging and Monitoring
179-
Failures - sensitive data in logs creates security risks</a> </li>
180-
<li> CWE 359 - <a href="https://cwe.mitre.org/data/definitions/359.html">Exposure of Private Personal Information to an Unauthorized Actor</a> </li>
181-
<li> CWE 598 - <a href="https://cwe.mitre.org/data/definitions/598.html">Use of GET Request Method With Sensitive Query Strings</a> </li>
182171
</ul>
183172

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S8392.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ <h2>How to fix it in FastAPI</h2>
8787
application is only accessible from your local machine.</p>
8888
<h3>Code examples</h3>
8989
<h4>Noncompliant code example</h4>
90-
<pre data-diff-id="1" data-diff-type="noncompliant">
90+
<pre data-diff-id="3" data-diff-type="noncompliant">
9191
import uvicorn
9292
from fastapi import FastAPI
9393

@@ -97,7 +97,7 @@ <h4>Noncompliant code example</h4>
9797
uvicorn.run(app, host="0.0.0.0", port=8000) # Noncompliant
9898
</pre>
9999
<h4>Compliant solution</h4>
100-
<pre data-diff-id="1" data-diff-type="compliant">
100+
<pre data-diff-id="3" data-diff-type="compliant">
101101
import uvicorn
102102
from fastapi import FastAPI
103103

0 commit comments

Comments
 (0)