generated from ossf/project-template
-
Notifications
You must be signed in to change notification settings - Fork 183
CWE-778 Insufficient Logging, updating Readme and code files. #844
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ef98248
CWE-778 Insufficient Logging, updating Readme and code files.
6e021b9
Update docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/README.md
andrew-costello 70f68c4
Update docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/README.md
andrew-costello 00b9e4a
Update docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/noncomplia…
andrew-costello 985fc73
Update docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/compliant0…
andrew-costello cdbe9c6
Update docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/README.md
andrew-costello 1d6ae62
Update README.md
andrew-costello a5658fc
Update docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/README.md
andrew-costello 8c0d06b
Update compliant01.py
andrew-costello 7a33ad5
Update noncompliant01.py
andrew-costello 13a1dcd
Update README.md
andrew-costello 9c2b86b
Update docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/README.md
andrew-costello 84fe116
fixed nl lint issue
myteron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # CWE-778: Insufficient Logging | ||
|
|
||
| Ensure you have sufficient logging in order to adequately record important events within an application and/or system. | ||
|
|
||
| This can leave applications vulnerable to undetected attacks, as malicious users are able to perform harmful activities without leaving a trace in the logs. Without comprehensive and sufficient logging, it becomes challenging to identify and respond to security incidents, leading to delayed and/or inefficient incident response efforts. | ||
|
|
||
| Insufficient logging also negatively affects forensic analysis, hindering the ability to reconstruct events accurately after a breach. | ||
|
|
||
| Writing exceptions to stdout, stderr or local files is not sufficient as: | ||
|
|
||
| The stdout or stderr buffer may be exhausted or closed, preventing subsequent writes | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Trust level of stdout or stderr may be the end-user or attacker | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logfiles which are only on a local filesystem can be deleted by an attacker | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If errors occur while recording logs, they can hinder the logging process unless preventive measures are implemented. Security risks can occur when these error's occur. For example, an attacker hiding crucial security issues by refraining the attacker from being logged. Therefore it is essential that logging functions in applications are effective, even when exceptions arise when completing the logging process. | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Non-Compliant Code Example | ||
|
|
||
| In noncompliant01.py, if a risky operation occurs such as the division by zero, the try block catches the ZeroDivisionError exception and prints it to the console without logging it, leaving the system vulnerable to undetected issues. The error print is also vague. | ||
|
|
||
| *[noncompliant01.py](noncompliant01.py):* | ||
andrew-costello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```python | ||
| """ Non-compliant Code Example """ | ||
|
|
||
| try: | ||
| result = 10 / 0 | ||
| except ZeroDivisionError as e: | ||
| print("Error occurred:", e) | ||
| #Continues to execute | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Compliant Solution | ||
|
|
||
| The security exception output in compliant01.py is using the logger. The program catches the ZeroDivisionError exception and logs it with the "critical" level, ensuring that errors are properly recorded. Production projects should setup log forwarding to a remote logging service. | ||
|
|
||
| *[compliant01.py](compliant01.py):* | ||
|
|
||
| ```python | ||
| """ Compliant Code Example """ | ||
|
|
||
| import logging | ||
|
|
||
| try: | ||
| result = 10 / 0 | ||
| except ZeroDivisionError: | ||
| logging.critical("Error occurred: Division by zero") | ||
| #Continues to execute | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Automated Detection | ||
|
|
||
| |Tool|Version|Checker|Description| | ||
| |:---|:---|:---|:---| | ||
| |Bandit|1.6.2|No Detection|| | ||
|
|
||
| ## Related Guidelines | ||
|
|
||
| ||| | ||
| |:---|:---| | ||
| |MITRE CWE Pillar|[CWE-693: Protection Mechanism Failure (4.16) (mitre.org)](https://cwe.mitre.org/data/definitions/693.html)| | ||
| |MITRE CWE Base|[CWE-778: Numeric Truncation Error](https://cwe.mitre.org/data/definitions/778.html)| | ||
| |[SEI CERT](https://wiki.sei.cmu.edu/confluence/display/java/SEI+CERT+Oracle+Coding+Standard+for+Java)|[ERR02-J. Prevent exceptions while logging data](https://wiki.sei.cmu.edu/confluence/display/java/ERR02-J.+Prevent+exceptions+while+logging+data)| | ||
8 changes: 4 additions & 4 deletions
8
docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/compliant01.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| # SPDX-FileCopyrightText: OpenSSF project contributors | ||
| # SPDX-License-Identifier: MIT | ||
| """ Compliant Code Example """ | ||
|
|
||
| import logging | ||
|
|
||
| try: | ||
| result = 10 / 0 | ||
| except ZeroDivisionError as e: | ||
| except ZeroDivisionError: | ||
| logging.critical("Error occurred: Division by zero") | ||
| #Continues to execute | ||
| #Continues to execute | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
4 changes: 2 additions & 2 deletions
4
docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-778/noncompliant01.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # SPDX-FileCopyrightText: OpenSSF project contributors | ||
| # SPDX-License-Identifier: MIT | ||
| """ Non-compliant Code Example """ | ||
|
|
||
| try: | ||
| result = 10 / 0 | ||
| except ZeroDivisionError as e: | ||
| print("Error occurred:", e) | ||
| #Continues to execute | ||
| #Continues to execute | ||
andrew-costello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.