|
| 1 | +<h2>Why is this an issue?</h2> |
1 | 2 | <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 |
2 | 3 | members of the group assigned to this resource.</p> |
3 | 4 | <p>Granting permissions to this category can lead to unintended access to files or directories that could allow attackers to obtain sensitive |
4 | 5 | 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> |
15 | 27 | <pre data-diff-id="1" data-diff-type="noncompliant"> |
16 | 28 | os.umask(0) # Sensitive |
17 | 29 | </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> |
28 | 31 | <pre data-diff-id="1" data-diff-type="compliant"> |
29 | 32 | os.umask(0o777) |
30 | 33 | </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> |
40 | 49 | <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> |
48 | 50 | <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> |
49 | 52 | <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> |
51 | 58 | </ul> |
52 | 59 |
|
0 commit comments