django-extra (S610)
源自 flake8-bandit linter。
作用
检查 Django 的 extra
函数的使用,该函数传递的一个或多个参数不是字面表达式。
为什么这不好?
Django 的 extra
函数可用于执行任意 SQL 查询,这反过来可能导致 SQL 注入漏洞。
示例
from django.contrib.auth.models import User
# String interpolation creates a security loophole that could be used
# for SQL injection:
User.objects.all().extra(select={"test": "%secure" % "nos"})
建议改为
from django.contrib.auth.models import User
# SQL injection is impossible if all arguments are literal expressions:
User.objects.all().extra(select={"test": "secure"})