mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Python: Support django models (with some caveats)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.db import connection, models
|
||||
from django.db.models.expressions import RawSQL
|
||||
|
||||
|
||||
def test_plain(username):
|
||||
@@ -16,3 +17,15 @@ def test_context(username):
|
||||
|
||||
# BAD -- Using string formatting
|
||||
cursor.execute("SELECT * FROM users WHERE username = '%s'" % username) # $getSql=BinaryExpr
|
||||
|
||||
class User(models.Model):
|
||||
pass
|
||||
|
||||
def test_model(username):
|
||||
# GOOD -- Using parameters
|
||||
User.objects.raw("SELECT * FROM users WHERE username = %s", (username,)) # $getSql="SELECT * FROM users WHERE username = %s"
|
||||
|
||||
# BAD -- other ways of executing raw SQL code with string interpolation
|
||||
User.objects.annotate(RawSQL("insert into names_file ('name') values ('%s')" % username)) # $getSql=BinaryExpr
|
||||
User.objects.raw("insert into names_file ('name') values ('%s')" % username) # $getSql=BinaryExpr
|
||||
User.objects.extra("insert into names_file ('name') values ('%s')" % username) # $getSql=BinaryExpr
|
||||
|
||||
Reference in New Issue
Block a user