-
Notifications
You must be signed in to change notification settings - Fork 185
Reviewed the Python Secure Coding Guide and made a lot of minor changes #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Bartlomiej Karas <bartlomiej.karas@ericsson.com>
Signed-off-by: Bartlomiej Karas <bartlomiej.karas@ericsson.com>
Signed-off-by: myteron <myteron@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some different opinion on going to much into STRIDE
Note that Reference section using brackets like in [online] may required [online] to avoid the rat.
# CWE-501: Trust Boundary Violation | ||
|
||
Python does not share the concept of different trust zones within the same runtime as explained in the *JAVA SEI CERT Rule 15 platform security (SEC)* [[SEI CERT 2022]](https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=88487683) rules. Python neither has a security manager that can control access between trusted and untrusted code running on the same JVM. “Private” instance variables that cannot be accessed except from inside an object don’t exist in Python [Python 2023]. | ||
In Python we need to implement different trust zone's by starting python runtime's with individual POSIX/Machine users. The POSIX/Machine user access rights must be set in accordance to level of trust per zone. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is important to point why its required to build up trust zones. So we need to explain that trust management as known by the Java runtime access manger Introducing Oracle Access Management does not exist in CPython
.
|
||
The acronym stands for six key threat categories: | ||
|
||
* Spoofing - Impersonating someone else, foten to gain unauthorized access. | ||
* Tampering - Unauthorised modification of data, code, or configurations. | ||
* Repudiation - Denying the performance of an action, making it difficult to prove responsibility wihtout proper logging or auditing. | ||
* Information Disclosure - Exposing sensitive information to unauthorised parties. | ||
* Denial of Service (DoS) - Disrupting system availability or performance. | ||
* Elevation of Privilege - Gaining higher access rights than intented, often leading to great system control. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I purposefully did not got into details on STRIDE to avoid derailing or distracting the key point. I have neither tried to analyze it in the noncompliant example to this level. Someone not knowing STRIDE can look it up but its not required to understand for understanding the key message.
## Noncompliant Code Example | ||
|
||
The `noncompliant01.py` code demonstrates arbitrary code execution [Checkoway Oct 2013] using `os.system` to launch a program during unpickling when `pickle.loads()`. | ||
The `noncompliant01.py` code demonstrates arbitrary code execution using `os.system` to launch a program during unpickling when `pickle.loads()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its quite an interesting reference, below link also need to be added to the Reference section.
The `noncompliant01.py` code demonstrates arbitrary code execution using `os.system` to launch a program during unpickling when `pickle.loads()`. | |
The `noncompliant01.py` code demonstrates arbitrary code execution using `os.system` to launch a program during unpickling when `pickle.loads()` [[Checkoway Oct 2013](https://checkoway.net/musings/pickle/)] |
## Non-compliant Code Example (Right Shift) | ||
In this non-compliant code example is using an arithmetic right shift >>= operator in an attempt to optimize performance for dividing x by 4 without floating point. | ||
The `nonompliant02.py` code example is using an arithmetic right shift >>= operator in an attempt to optimize performance for dividing x by 4 without floating point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `nonompliant02.py` code example is using an arithmetic right shift >>= operator in an attempt to optimize performance for dividing x by 4 without floating point. | |
The `noncompliant02.py` code example is using an arithmetic right shift `>>=` operator in an attempt to optimize performance for dividing `x` by `4` without floating point. |
## Compliant Solution | ||
|
||
The `compliant01.py` code using the cross-platform compatible pathlib module and restricting filesystem area. The `pathlib` on its own will not prevent all attacks. | ||
The `compliant01.py` code uses the cross-platform compatible pathlib module and restricting filesystem area. The `pathlib` on its own will not prevent all attacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `compliant01.py` code uses the cross-platform compatible pathlib module and restricting filesystem area. The `pathlib` on its own will not prevent all attacks. | |
The `compliant01.py` code uses the cross-platform compatible `pathlib` module and restricting filesystem area. The `pathlib` on its own will not prevent all attacks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some difference in opinion regards going to deep into STRIDE.
some cosmetics you need to pull
Brackets, such as [online] in the Reference section may trip up the linter and needs escapes .[online]
I added a few sentences, moved things around, fixed typos, removed Wikipedia links and inserted new links etc.