Prioritize JSON parsing for body#356
Draft
kapyteinaikido wants to merge 19 commits into
Draft
Conversation
|
|
||
| with connection.cursor() as cursor: | ||
| query = 'INSERT INTO sample_app_dogs (dog_name, dog_boss) VALUES ("%s", "N/A")' % dog_name | ||
| cursor.execute(query) |
Check failure
Code scanning / CodeQL
SQL query built from user-controlled sources
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to use parameterized queries instead of string formatting to construct the SQL query. Parameterized queries ensure that user input is properly escaped and handled by the database driver, preventing SQL injection attacks.
The best way to fix the problem without changing existing functionality is to modify the cursor.execute call to use query parameters. This involves replacing the string formatting with a parameterized query and passing the user-provided value as a parameter to the execute method.
Suggested changeset
1
sample-apps/django-mysql/sample_app/views.py
| @@ -36,5 +36,5 @@ | ||
| with connection.cursor() as cursor: | ||
| query = 'INSERT INTO sample_app_dogs (dog_name, dog_boss) VALUES ("%s", "N/A")' % dog_name | ||
| print("QUERY : ", query) | ||
| cursor.execute(query) | ||
| query = 'INSERT INTO sample_app_dogs (dog_name, dog_boss) VALUES (%s, "N/A")' | ||
| print("QUERY : ", query % dog_name) | ||
| cursor.execute(query, [dog_name]) | ||
| return HttpResponse("Dog page created") | ||
| @@ -49,4 +49,4 @@ | ||
| with connection.cursor() as cursor: | ||
| query = 'INSERT INTO sample_app_dogs (dog_name, dog_boss) VALUES ("%s", "N/A")' % dog_name | ||
| cursor.execute(query) | ||
| query = 'INSERT INTO sample_app_dogs (dog_name, dog_boss) VALUES (%s, "N/A")' | ||
| cursor.execute(query, [dog_name]) | ||
| return JsonResponse({"status": "Dog page created"}) |
Copilot is powered by AI and may make mistakes. Always verify output.
kapyteinaikido
marked this pull request as draft
April 8, 2025 12:26
…ewall-python into django_body_parsing_bypass
kapyteinaikido
marked this pull request as ready for review
April 9, 2025 09:39
bitterpanda63
marked this pull request as draft
April 11, 2025 12:28
bitterpanda63
self-requested a review
April 11, 2025 12:28
kapyteinaikido
marked this pull request as ready for review
April 14, 2025 14:31
willem-delbare
approved these changes
Jun 25, 2025
bitterpanda63
marked this pull request as draft
August 18, 2025 09:43
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
https://app.intigriti.com/company/submissions/AIKIDO-X6HFZR7E