-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.conf.urls import url | ||
from django.db import connection | ||
|
||
|
||
def show_user(request, username): | ||
with connection.cursor() as cursor: | ||
# BAD -- Using string formatting | ||
cursor.execute("SELECT * FROM users WHERE username = '%s'" % username) | ||
Check failure Code scanning / CodeQL SQL query built from user-controlled sources High test
This SQL query depends on a
user-provided value Error loading related location Loading |
||
user = cursor.fetchone() | ||
|
||
# GOOD -- Using parameters | ||
cursor.execute("SELECT * FROM users WHERE username = %s", username) | ||
user = cursor.fetchone() | ||
|
||
# BAD -- Manually quoting placeholder (%s) | ||
cursor.execute("SELECT * FROM users WHERE username = '%s'", username) | ||
user = cursor.fetchone() | ||
|
||
urlpatterns = [url(r'^users/(?P<username>[^/]+)$', show_user)] |