SQL injection protection in python
기본적으로 장고의 queryset(ORM)을 사용할 경우에는 injection에 대한 보호가 됨으로 따로 처리해줄 필요가 없다.
extra(),RawSQL()등을 사용하거나 connection을 통해 직접 쿼리를 통해 데이터베이스에 접근하는 경우에는 SQL injection에 대한 처리를 따로 해줄 필요가 있다.
https://bobby-tables.com/python.html 에서 python sql injection에 대해 설명하고 있는데 이를 참고하였다.
다음과 같다.
Bad Case:
# Do NOT do it this way.
cmd = "update people set name='%s' where id='%s'" % (name, id)
curs.execute(cmd)
Good Case:
cmd = "update people set name=%s where id=%s"
curs.execute(cmd, (name, id))
For cases involving a single variable do this:
cmd = "SELECT \* FROM PEOPLE WHERE name = %s"
curs.execute(cmd, (name,))
'Computer > Database' 카테고리의 다른 글
[MySQL] 하루, 일주일, 한달 기간 정하고 데이터 가져오는 query (0) | 2021.04.15 |
---|---|
Relational Data Model and Relational Database constraints (0) | 2020.11.25 |