Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bde7966

Browse filesBrowse files
joke1196sonartech
authored andcommitted
SONARPY-3892 Updated rule metadata (#949)
GitOrigin-RevId: c4bf2e467841a6dd376dffb4fa16e876b92e7b31
1 parent 50598ad commit bde7966
Copy full SHA for bde7966

File tree

Expand file treeCollapse file tree

7 files changed

+68
-56
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+68
-56
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2068.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "VULNERABILITY",
44
"code": {
55
"impacts": {
6-
"SECURITY": "BLOCKER"
6+
"SECURITY": "MEDIUM"
77
},
88
"attribute": "TRUSTWORTHY"
99
},
@@ -16,7 +16,7 @@
1616
"tags": [
1717
"cwe"
1818
],
19-
"defaultSeverity": "Blocker",
19+
"defaultSeverity": "Major",
2020
"ruleSpecification": "RSPEC-2068",
2121
"sqKey": "S2068",
2222
"scope": "Main",
Collapse file
+44-37Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,59 @@
1+
<h2>Why is this an issue?</h2>
12
<p>In Unix file system permissions, the "<code>others</code>" category refers to all users except the owner of the file system resource and the
23
members of the group assigned to this resource.</p>
34
<p>Granting permissions to this category can lead to unintended access to files or directories that could allow attackers to obtain sensitive
45
information, disrupt services or elevate privileges.</p>
5-
<h2>Ask Yourself Whether</h2>
6-
<ul>
7-
<li>The application is designed to be run on a multi-user environment.</li>
8-
<li>Corresponding files and directories may contain confidential information.</li>
9-
</ul>
10-
<p>There is a risk if you answered yes to any of those questions.</p>
11-
<h2>Recommended Secure Coding Practices</h2>
12-
<p>The most restrictive possible permissions should be assigned to files and directories.</p>
13-
<h2>Sensitive Code Example</h2>
14-
<p>For <a href="https://docs.python.org/3/library/os.html#os.umask">os.umask</a>:</p>
6+
<h3>What is the potential impact?</h3>
7+
<h4>Unauthorized access to sensitive information</h4>
8+
<p>When file or directory permissions grant access to all users on a system (often represented as "others" or "everyone" in permission models),
9+
attackers who gain access to any user account can read sensitive files containing credentials, configuration data, API keys, database passwords,
10+
personal information, or proprietary business data. This exposure can lead to data breaches, identity theft, compliance violations, and competitive
11+
disadvantage.</p>
12+
<h4>Service disruption and data corruption</h4>
13+
<p>Granting write permissions to broad user categories allows any user on the system to modify or delete critical files and directories. Attackers or
14+
compromised low-privileged accounts can corrupt application data, modify configuration files to alter system behavior or disrupt services, or delete
15+
important resources, leading to service outages, system instability, data loss, and denial of service.</p>
16+
<h4>Privilege escalation</h4>
17+
<p>When executable files or scripts have overly permissive permissions, especially when combined with special permission bits that allow programs to
18+
execute with the permissions of the file owner or group rather than the executing user, attackers can replace legitimate executables with malicious
19+
code. When these modified files are executed by privileged users or processes, the attacker’s code runs with elevated privileges, potentially enabling
20+
them to escalate from a low-privileged account to root or administrator access, install backdoors, or pivot to other systems in the network.</p>
21+
<h2>How to fix it</h2>
22+
<p>When using <code>os.umask</code>, set a restrictive umask value that prevents permissions for "others". The umask value <code>0o777</code> ensures
23+
that no permissions are granted to any category by default. This is the most secure approach as it requires explicit permission grants rather than
24+
implicit ones.</p>
25+
<h3>Code examples</h3>
26+
<h4>Noncompliant code example</h4>
1527
<pre data-diff-id="1" data-diff-type="noncompliant">
1628
os.umask(0) # Sensitive
1729
</pre>
18-
<p>For <a href="https://docs.python.org/3/library/os.html#os.chmod">os.chmod</a>, <a
19-
href="https://docs.python.org/3/library/os.html#os.lchmod">os.lchmod</a>, and <a
20-
href="https://docs.python.org/3/library/os.html#os.fchmod">os.fchmod</a>:</p>
21-
<pre data-diff-id="2" data-diff-type="noncompliant">
22-
os.chmod("/tmp/fs", stat.S_IRWXO) # Sensitive
23-
os.lchmod("/tmp/fs", stat.S_IRWXO) # Sensitive
24-
os.fchmod(fd, stat.S_IRWXO) # Sensitive
25-
</pre>
26-
<h2>Compliant Solution</h2>
27-
<p>For <a href="https://docs.python.org/3/library/os.html#os.umask">os.umask</a>:</p>
30+
<h4>Compliant solution</h4>
2831
<pre data-diff-id="1" data-diff-type="compliant">
2932
os.umask(0o777)
3033
</pre>
31-
<p>For <a href="https://docs.python.org/3/library/os.html#os.chmod">os.chmod</a>, <a
32-
href="https://docs.python.org/3/library/os.html#os.lchmod">os.lchmod</a>, and <a
33-
href="https://docs.python.org/3/library/os.html#os.fchmod">os.fchmod</a>:</p>
34-
<pre data-diff-id="2" data-diff-type="compliant">
35-
os.chmod("/tmp/fs", stat.S_IRWXU)
36-
os.lchmod("/tmp/fs", stat.S_IRWXU)
37-
os.fchmod(fd, stat.S_IRWXU)
38-
</pre>
39-
<h2>See</h2>
34+
<h2>Resources</h2>
35+
<h3>Documentation</h3>
36+
<ul>
37+
<li>OWASP File Permission Testing Guide - <a
38+
href="https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/02-Configuration_and_Deployment_Management_Testing/09-Test_File_Permission">OWASP guidance on testing file permissions in web applications</a></li>
39+
<li>Python Documentation - os.umask - <a href="https://docs.python.org/3/library/os.html#os.umask">Official Python documentation for the os.umask
40+
function</a></li>
41+
<li>Python Documentation - os.chmod - <a href="https://docs.python.org/3/library/os.html#os.chmod">Official Python documentation for the os.chmod
42+
function</a></li>
43+
<li>Python Documentation - os.lchmod - <a href="https://docs.python.org/3/library/os.html#os.lchmod">Official Python documentation for the os.lchmod
44+
function</a></li>
45+
<li>Python Documentation - os.fchmod - <a href="https://docs.python.org/3/library/os.html#os.fchmod">Official Python documentation for the os.fchmod
46+
function</a></li>
47+
</ul>
48+
<h3>Standards</h3>
4049
<ul>
41-
<li>OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a></li>
42-
<li>OWASP - <a href="https://owasp.org/Top10/A04_2021-Insecure_Design/">Top 10 2021 Category A4 - Insecure Design</a></li>
43-
<li>OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A5_2017-Broken_Access_Control">Top 10 2017 Category A5 - Broken Access
44-
Control</a></li>
45-
<li><a
46-
href="https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/02-Configuration_and_Deployment_Management_Testing/09-Test_File_Permission">OWASP File Permission</a></li>
47-
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/732">CWE-732 - Incorrect Permission Assignment for Critical Resource</a></li>
4850
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/266">CWE-266 - Incorrect Privilege Assignment</a></li>
51+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/732">CWE-732 - Incorrect Permission Assignment for Critical Resource</a></li>
4952
<li>STIG Viewer - <a href="https://stigviewer.com/stigs/application_security_and_development/2024-12-06/finding/V-222430">Application Security and
50-
Development: V-222430</a> - The application must execute without excessive account permissions.</li>
53+
Development: V-222430</a> - The application must execute without excessive account permissions</li>
54+
<li>OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a></li>
55+
<li>OWASP - <a href="https://owasp.org/Top10/A04_2021-Insecure_Design/">Top 10 2021 Category A4 - Insecure Design</a></li>
56+
<li>OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A5_2017-Broken_Access_Control">Top 10 2017 Category A5 - Broken Access Control -
57+
OWASP Top 10 2017</a></li>
5158
</ul>
5259

Collapse file

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

Copy file name to clipboardExpand all lines: python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2612.json
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"title": "Setting loose POSIX file permissions is security-sensitive",
3-
"type": "SECURITY_HOTSPOT",
2+
"title": "File permissions should not be set to world-accessible values",
3+
"type": "VULNERABILITY",
44
"code": {
55
"impacts": {
66
"SECURITY": "MEDIUM"
@@ -43,5 +43,6 @@
4343
"STIG ASD_V5R3": [
4444
"V-222430"
4545
]
46-
}
46+
},
47+
"quickfix": "unknown"
4748
}
Collapse file

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

Copy file name to clipboardExpand all lines: python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6984.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<p>This rule raises an issue when an incorrect pattern is provided to an <code>einops</code> operation.</p>
22
<h2>Why is this an issue?</h2>
33
<p>The <code>einops</code> library provides a powerful and flexible way to manipulate tensors using the Einstein summation convention. The
4-
<code>einops</code> uses a different convention than the <a href="https://ejenner.com/post/einsum/">traditional</a> one. In particular, the axis names
4+
<code>einops</code> uses a different convention than the <a href="https://ejenner.com/post/einsum">traditional</a> one. In particular, the axis names
55
can be more than one letter long and are separated by spaces.</p>
66
<h2>How to fix it</h2>
77
<p>Correct the syntax of the <code>einops</code> operation by balancing the parentheses and following the convention.</p>
Collapse file

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

Copy file name to clipboardExpand all lines: python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S8392.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ <h3>Documentation</h3>
117117
(127.0.0.1) and production (0.0.0.0) binding</a></li>
118118
<li>Flask Deployment Options - <a href="https://flask.palletsprojects.com/en/2.3.x/deploying/">Official Flask documentation on secure deployment
119119
practices</a></li>
120-
<li>Flask Security Considerations - <a href="https://flask.palletsprojects.com/en/2.3.x/security/">Flask security best practices and common
120+
<li>Flask Security Considerations - <a href="https://flask.palletsprojects.com/en/stable/web-security/">Flask security best practices and common
121121
vulnerabilities</a></li>
122-
<li>Gunicorn Documentation - <a href="https://docs.gunicorn.org/en/stable/">Production WSGI server for Python web applications</a></li>
122+
<li>Gunicorn Documentation - <a href="https://gunicorn.org/quickstart/">Production WSGI server for Python web applications</a></li>
123123
</ul>
124124
<h3>Standards</h3>
125125
<ul>
Collapse file

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

Copy file name to clipboardExpand all lines: python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S8396.html
+14-10Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<p>This is an issue when a Pydantic model field uses <code>Optional[Type]</code> or <code>Type | None</code> type hints without providing an explicit
2-
default value, or when using <code>Field(…​)</code> with the ellipsis operator.</p>
1+
<p>This is an issue when a Pydantic model field uses <code>Optional[Type]</code> without providing an explicit default value, or when using
2+
<code>Field(…​)</code> with <code>Optional[Type]</code> and the ellipsis operator.</p>
33
<h2>Why is this an issue?</h2>
44
<p>In Pydantic models, there is a common misconception about what <code>Optional[Type]</code> means. Many developers assume that marking a field as
55
<code>Optional[Type]</code> makes it optional during validation, but this is not the case.</p>
@@ -9,14 +9,17 @@ <h2>Why is this an issue?</h2>
99
<p>To make a field truly optional (meaning it doesn’t need to be provided during validation), you must assign a default value. This is typically
1010
<code>None</code> for optional fields, but can be any appropriate default value.</p>
1111
<p>A particularly problematic pattern is using <code>Field(…​)</code> with <code>Optional[Type]</code>. The ellipsis (<code>…​</code>) is Pydantic’s
12-
way of explicitly marking a field as required. This creates a direct contradiction: the type hint says the field can be <code>None</code>, but the
13-
<code>Field(…​)</code> says it must be provided. In this case, Pydantic prioritizes the ellipsis, making the field required despite the
14-
<code>Optional</code> annotation.</p>
12+
way of explicitly marking a field as required. This creates a direct contradiction: the type hint says the field can be <code>None</code>, but
13+
<code>Field(…​)</code> says it must be provided.</p>
1514
<p>This mismatch between developer intent and actual behavior leads to unexpected validation errors in production, confusing API consumers who receive
1615
"field required" errors for fields they reasonably expected to be optional based on the type hints.</p>
16+
<h3>Exceptions</h3>
17+
<p>Fields typed as <code>Type | None</code>, <code>None | Type</code>, or <code>Union[Type, None]</code> are compliant, with or without a default
18+
value.</p>
19+
<p>These annotations are explicit nullable type declarations and do not imply that the field may be omitted from input data.</p>
1720
<h3>What is the potential impact?</h3>
18-
<p>When optional fields lack explicit default values, the application will reject valid requests where users omit fields they believe to be optional.
19-
This leads to:</p>
21+
<p>When <code>Optional[…​]</code> fields lack explicit default values, the application may reject requests where users omit fields they believe to be
22+
optional. This leads to:</p>
2023
<ul>
2124
<li>Poor user experience with confusing "field required" validation errors</li>
2225
<li>API contract violations where the schema suggests fields are optional but validation requires them</li>
@@ -26,11 +29,12 @@ <h3>What is the potential impact?</h3>
2629
<h2>How to fix it</h2>
2730
<p>Add an explicit default value (typically <code>None</code>) to fields with <code>Optional</code> type hints. This makes the field truly optional
2831
during validation while maintaining the type safety that allows <code>None</code> values.</p>
32+
<p>For <code>Optional[…​]</code> fields, avoid the ellipsis form (<code>Field(…​)</code>) and provide an explicit default instead.</p>
2933
<h3>Code examples</h3>
3034
<h4>Noncompliant code example</h4>
3135
<pre data-diff-id="1" data-diff-type="noncompliant">
3236
from typing import Optional
33-
from pydantic import BaseModel
37+
from pydantic import BaseModel, Field
3438

3539
class TwitterAccount(BaseModel):
3640
username: str
@@ -42,8 +46,8 @@ <h4>Noncompliant code example</h4>
4246
</pre>
4347
<h4>Compliant solution</h4>
4448
<pre data-diff-id="1" data-diff-type="compliant">
45-
from typing import Optional
46-
from pydantic import BaseModel
49+
from typing import Optional, Union
50+
from pydantic import BaseModel, Field
4751

4852
class TwitterAccount(BaseModel):
4953
username: str
Collapse file

‎sonarpedia.json‎

Copy file name to clipboardExpand all lines: sonarpedia.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"languages": [
44
"PY"
55
],
6-
"latest-update": "2026-02-18T12:35:08.274727508Z",
6+
"latest-update": "2026-03-10T13:34:05.699012606Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": true

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.