Skip to content

Commit caa88ed

Browse files
committed
Add example code for CodeQL to flag
1 parent 2fa11a8 commit caa88ed

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.conf.urls import url
2+
from django.db import connection
3+
4+
5+
def show_user(request, username):
6+
with connection.cursor() as cursor:
7+
# BAD -- Using string formatting
8+
cursor.execute("SELECT * FROM users WHERE username = '%s'" % username)
9+
user = cursor.fetchone()
10+
11+
# GOOD -- Using parameters
12+
cursor.execute("SELECT * FROM users WHERE username = %s", username)
13+
user = cursor.fetchone()
14+
15+
# BAD -- Manually quoting placeholder (%s)
16+
cursor.execute("SELECT * FROM users WHERE username = '%s'", username)
17+
user = cursor.fetchone()
18+
19+
urlpatterns = [url(r'^users/(?P<username>[^/]+)$', show_user)]

0 commit comments

Comments
 (0)