Skip to content
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

Update flask.py #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_sources_7(something):
# comment
return "foo"
# comment
assert(True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM  Improper handling of checking for unusual or exceptional conditions
    File: flask.py | Checkov ID: CKV3_SAST_4

Description

CWE: CWE-754: Improper Check for Unusual or Exceptional Conditions

The assert statement in Python is used for debugging purposes. It lets you test if a certain condition is met, and if not, the program will raise an AssertionError exception.

The main problem with assert is that it can be globally disabled with the -O (optimize) option in Python, or by setting the environment variable PYTHONOPTIMIZE to a non-empty string. This means that when Python code is run in optimized mode, all assert statements are ignored.

Therefore, if you're using assert to check for conditions that should prevent the program from continuing (for example, validating user input or checking configuration files), those checks will be skipped in optimized mode, which could lead to incorrect program behavior or even security vulnerabilities.

Here is an example of problematic code:

def process_data(data):
    assert data is not None, "Data must not be None"
    # Continue with processing...

In this code, if Python is run with optimization enabled, the assert statement will be ignored, and the process_data function will proceed even if data is None, which could cause errors later on.

@app.route("/sanitized/<something>")
def test_sources_7(something):
data = flask.request.args.get("key")
Expand Down