我有一个网络应用程序,它允许用户输入搜索查询,然后检索符合此搜索条件的模型。这是我的方法:
@staticmethod
def searchBody(query):
'''
Return all entries whose body text contains the query.
'''
return Entry.objects.get(text__icontains=query)
@staticmethod
def searchTitle(query):
'''
Return all entries whose title text contains the query.
'''
return Entry.objects.get(title__icontains=query)
@staticmethod
def searchAuthor(query):
'''
Return all entries whose author text contains the query.
'''
return Entry.objects.get(author.icontains=query)
我的问题很简单:这是否安全?换句话说,是否incontains
执行了必要的字符串转义操作,这样一个人就不能将 SQL 或 Python 代码注入到查询中来发起攻击?