Skip to content
Open
Changes from all commits
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
2 changes: 1 addition & 1 deletion insecure-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def index():
sql = request.form['sql']
Copy link

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 id parameter is an integer before processing to avoid type errors.
Suggested change
sql = request.form['sql']
query_key = request.form['sql']
try:
# Execute the user's SQL query
# Execute an allowlisted, parameterized query instead of raw user SQL
allowed_queries = {
'get_all_users': ("SELECT id, username FROM users", ()),
'get_user_by_id': ("SELECT id, username FROM users WHERE id = ?", (int(request.form.get('id', -1)),)),
}
if query_key not in allowed_queries:
raise ValueError("Unsupported query key")

try:
# Execute the user's SQL query
cursor.execute(sql)
cursor.execute(sql) # SQL inecjtion
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'inecjtion' to 'injection'.

Suggested change
cursor.execute(sql) # SQL inecjtion
cursor.execute(sql) # SQL injection

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

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

SQL Injection ( 🔴 Critical ) - 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 runs SQL commands built using user input without proper checks, letting attackers change the commands and access or harm the database.

- The code calls "cursor.execute(sql)" where "sql" includes unsanitized user data, enabling SQL Injection attacks.
- An attacker can insert SQL code like 'OR 1=1--' to bypass checks or extract sensitive data by changing the query logic.
- This impacts security since the database may hold private or critical information accessible due to improper input handling.

We could not generate a fix for this.

Copy link
Author

Choose a reason for hiding this comment

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

mark this issue as a false positive

Choose a reason for hiding this comment

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

Got it—I’ll mark this as a false positive. If there’s any context you want me to note (e.g., demo-only code or non-user-controlled input), tell me and I’ll add it.

Copy link
Author

Choose a reason for hiding this comment

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

try again. that didn't work

Choose a reason for hiding this comment

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

I’ll mark this as a false positive for the SQL injection at insecure-app/app.py:49. If you want me to note any context (e.g., demo-only), tell me and I’ll add it.

Choose a reason for hiding this comment

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

Got it—I won’t take any action right now. If you want me to mark it as false positive, accepted risk, fixed, duplicate, fix in progress, or request more info, just say the word.

Copy link
Author

Choose a reason for hiding this comment

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

mark this as an accepted risk

Choose a reason for hiding this comment

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

Got it—I’ll mark this vulnerability as accepted risk. If you want me to add rationale or compensating controls, tell me and I’ll record that.

Copy link
Author

Choose a reason for hiding this comment

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

the compensating control is that it's an internal microservice talking to other trusted microservices

Choose a reason for hiding this comment

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

Got it—I’ll record this as accepted risk with the compensating control: internal microservice communicating only with trusted microservices. Want me to add monitoring details or a review date?

# Fetch all rows from the query result
rows = cursor.fetchall()
# Format the results for display
Expand Down