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 routes.py #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update routes.py #2

wants to merge 1 commit into from

Conversation

4m4dis
Copy link
Owner

@4m4dis 4m4dis commented Feb 2, 2025

SQLi is added

@@ -13,7 +13,7 @@

if name:
cursor.execute(
"SELECT * FROM books WHERE name LIKE %s", name
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"

Check failure

Code scanning / CodeQL

SQL query built from user-controlled sources High

This SQL query depends on a
user-provided value
.

Copilot Autofix AI 19 days ago

To fix the problem, we need to use parameterized queries to safely embed user-provided data into the SQL query. This approach ensures that the database connector library handles the escaping and quoting of the user input, preventing SQL injection attacks.

In the provided code snippet, we will replace the vulnerable query on line 16 with a parameterized query. We will use the cursor.execute method with placeholders for the user-provided data and pass the data as a separate argument.

Suggested changeset 1
server/routes.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/routes.py b/server/routes.py
--- a/server/routes.py
+++ b/server/routes.py
@@ -15,3 +15,3 @@
         cursor.execute(
-            "SELECT * FROM books WHERE name LIKE '%" + name + "%'"
+            "SELECT * FROM books WHERE name LIKE %s", ('%' + name + '%',)
         )
EOF
@@ -15,3 +15,3 @@
cursor.execute(
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
"SELECT * FROM books WHERE name LIKE %s", ('%' + name + '%',)
)
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@4m4dis
Copy link
Owner Author

4m4dis commented Feb 2, 2025

This is dangerous PR. need to fix sqli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant