我的应用程序(主要是用主干编写的客户端代码)与 Node.js 服务器接口。我的服务器的唯一目的是为我的主干应用程序提供 API 端点。
GET
请求非常安全,攻击者在这里无能为力。但我确实有一些 POST 和 PUT 请求。其中一个PUT
请求负责更新特定用户的投票计数,例如
app.put('/api/vote`, function(req, res) {
// POST form data from the client
var winningPerson = req.body.winner; // userID
var losingPerson = req.body.loser; // userID
}
我注意到有些人只是PUT
通过 JS 控制台或某种 REST API 控制台向某个特定用户发送垃圾邮件请求,绕过了用户界面强制执行的应用程序的意图。如果您按预期使用此应用程序,它将永远不允许您连续多次投票给同一个人,更不用说数据库中的任意用户(假设您知道他们的用户 ID)。
But yes, yes I know: "Don't trust the client". So how can I fix the above problem? Will some kind of IP address checking help here to prevent voting multiple times within a span of 3-5 minutes? What can I do to disallow access to my API from the console so that users cannot arbitrarily vote for anyone they wish, but instead only vote by clicking on an image with a mouse, or at the very least vote from console just for those two people, not any arbitrary person?