我最近读了一篇关于花旗集团黑客事件的有趣文章 http://www.nytimes.com/2011/06/14/technology/14security.html?_r=2&pagewanted=1&ref=technology
这让我开始思考,假设我的数据库中有一个包含 100,000 行敏感员工数据的表。该表有一个名为 Id 的主键,它是一个标识列。
员工可以登录 Web Portal 并通过 RESTful Url ({Controller}/{Action}/{Id}) 检索他的详细信息,例如/员工/详细信息/31
现在,是什么阻止我用 {Id} 参数替换任何参数(例如 Id = 32)和 检索员工 #32 的详细信息?花旗集团就是这样吗?
如何防止这种情况发生?即用户已经在门户网站上进行了身份验证 但未授权查看其他用户记录?我应该使用其他一些特定的“ token ”吗? 除了 Id 之外的客户?
最佳答案
这就是我在完全相同的情况下所做的,首先我声明了一个对象的扩展:
public static bool Editable(this EXPENSE_OBJ e)
{
if (e != null)
{
UserRepository ur = new UserRepository();
if (ur.CurrentUser().UserId == e.UserId) //Check if the user owns the claim
{
return true; //User owns the claim
}
else
{
return false; //User does not own the claim
}
}
}
然后在 Controller 中:
public ActionResult Details(id)
{
var item = repo.GetItem(id);
if(!item.Editable())
{
return View("InvalidURL");
}
...
}
关于asp.net-mvc - 如何保护 MVC RESTful Urls 免受黑客攻击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6361095/