文章詳情頁(yè)
python 操作mysql如何經(jīng)量防止自己的程序在之后被惡意注入(說(shuō)白了就是問一下python防注入的一些要點(diǎn))
瀏覽:111日期:2022-06-11 13:45:45
問題描述
有沒有必要參考以往的php或者java之類的語(yǔ)言的防注入文檔呢?python相關(guān)的防注入文檔實(shí)在不好找
問題解答
回答1:1.通過
cursor.execute('select * from table where name=%s', 'name')
可以防注入。
2.如果通過
sql = 'select * from table where name=%s' % MySQLdb.escape_string(name)
這種格式,需要MySQLdb.escape_string(name),可以防注入.
推薦使用第一種。
回答2:sql = 'INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)'cursor.execute(sql, (’webmaster@python.org’, ’very-secret’))
我知道的一點(diǎn)是不要使用 sql.format('x1', 'x2'), 要把參數(shù)傳給cursor.execute去處理
相關(guān)文章:
1. 為什么我ping不通我的docker容器呢???2. 用Java8的 stream 操作外部集合是否存在并發(fā)問題?3. html5 - 百度echart官網(wǎng)下載的地圖json數(shù)據(jù)亂碼4. 為什么學(xué)習(xí)PHP5. html5 - vue怎么實(shí)現(xiàn)像京東天貓banner圖片圖片點(diǎn)擊放大,并可滑動(dòng)到下一張6. html5和Flash對(duì)抗是什么情況?7. css - 使手機(jī)版可左右托移?8. python - Pycharm的Debug用不了9. JAVA 版本問題?10. javascript - 關(guān)于json中獲取多個(gè)key-value對(duì)中多層嵌套key的name
排行榜

熱門標(biāo)簽