forked from latiotech/insecure-kubernetes-deployments
-
Notifications
You must be signed in to change notification settings - Fork 0
Update app.py 3 #7
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
Open
asadeddin
wants to merge
1
commit into
main
Choose a base branch
from
asadeddin-patch-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
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.
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.
SQL Injection ( 🔴 High ) - The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. View in Corgea ↗
More Details
🎟️Issue Explanation: The code directly takes user input to build an SQL command, risking attackers changing the query to access or damage data. This is called SQL Injection.
- The input "request.form['sql']" is used raw, allowing attackers to insert malicious SQL like "' OR 1=1 --".
- This can modify SQL queries, leading to data leaks, deletion, or unauthorized access.
- Since SQL commands are important and often handle sensitive info, this flaw can cause serious security breaches.
🪄Fix Explanation: The fix replaces directly executing raw SQL from user input with a parameterized, allowlisted set of predefined queries, preventing arbitrary SQL execution and thus mitigating SQL injection risks.
- Replaces `"sql = request.form['sql']"` with `"query_key = request.form['sql']"`, treating input as a key, not raw SQL.
- Introduces `"allowed_queries"`, a dictionary of predefined SQL statements and their parameters, enforcing a whitelist.
- Checks if `"query_key"` exists in `"allowed_queries"`, raising an error for unsupported keys.
- Uses parameterized queries via `"cursor.execute(sql, params)"` to safely insert user-supplied ID, preventing injection.
- Eliminates direct execution of user-supplied SQL, drastically reducing injection attack surface.
💡Important Instructions: Ensure the upstream code always provides valid query keys and validate the
idparameter is an integer before processing to avoid type errors.