duanjiang7505 2014-08-22 14:07
浏览 99
已采纳

golang中的查询字符串安全吗?

Consider the following fetch of the URLParam userId passed on a URL:

userId := http.Request.URL.Query().Get("userId")

Is this safe (escaped and ready to be used in a db call) as it is or do I need to escape it /sanitize it before use?

  • 写回答

1条回答 默认 最新

  • doutong1890 2014-08-22 14:08
    关注

    This is not db-safe, and you should use the database driver's escaping before putting anything in it.

    You should use functions like sql.DB.Query() that let you pass arguments and properly escape them. http://golang.org/pkg/database/sql/#DB.Query

    e.g.

    userId := http.Request.URL.Query().Get("userId")
    
    rows, err := db.Query("SELECT * FROM users WHERE id=?", userId)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?