python - icontains and SQL Security -
i have web app allows users enter search query retrieve models match search criteria. here methods:
@staticmethod def searchbody(query): ''' return entries body text contains query. ''' return entry.objects.get(text__icontains=query) @staticmethod def searchtitle(query): ''' return entries title text contains query. ''' return entry.objects.get(title__icontains=query) @staticmethod def searchauthor(query): ''' return entries author text contains query. ''' return entry.objects.get(author.icontains=query) my question simply: secure stands? in other words, incontains perform necessary string escaping operations person can't inject sql or python code query launch attack?
yes, django orm protects against sql injection.
of course can never entirely sure there no security vulnerability in application. nevertheless, orm component responsible protecting against sql injection, should assume it's safe , keep django install date!
on unrelated note, there typo in entry.objects.get(author.icontains=query).
also, using .get going throw lot of errors here (whenever object doesn't exist, or more 1 exist). doesn't docstring says either.
you want using .filter instead.
Comments
Post a Comment