在使用“数据库/ SQL”时如何防止Go中的SQL注入攻击?

问题描述

只要您使用PrepareQuery,您都是安全的。

// this is safe
db.Query("SELECT name FROM users WHERE age=?", req.FormValue("age"))
// this allows sql injection.
db.Query("SELECT name FROM users WHERE age=" + req.FormValue("age"))

解决方法

构建我的第一个Web应用程序,并希望更好地理解SQL注入(https://github.com/astaxie/build-web-
application-with-
golang/blob/master/en/eBook/09.4.md)。

从始终使用’database / sql’库和使用’构造查询可以得到多少保护?而不是容纳字符串?在这种情况下,我仍然需要担心哪种SQL注入攻击?