在ASP.Net MVC中删除记录的安全方法

问题描述 投票:3回答:1

我想从我的ASP.Net MVC 5网站上删除一个产品。我想知道添加[AntiForgeryToken][Authorize]是否足以保护删除操作?

视图

 <p>Delete: @Model.Name</p>
 @using (Html.BeginForm("Delete", "ProductController", FormMethod.Post, new { ProductId = Model.ProductId }))
 {
    @Html.AntiForgeryToken()
    <button type="submit">Delete</button>
 }

调节器

[HttpPost]
[Authorize]
[ValidateAntiForgeryToken]
public ActionResult Delete(long ProductId)
{
    /* Do I need to check if the logged in User has permission to delete the product?
    var product = ProductRepository.Get(Id);
    if (product.Creator == User.Identity.GetUserId<long>())
    {
        ProductRepository.Delete(ProductId);
    }
    */

    // or, can I avoid the trip to DB and just delete the record?        
    ProductRepository.Delete(ProductId); 
}

场景:黑客在我的网站上注册并创建一个有效的帐户。现在黑客看到了他自己的产品,显然他有一个AntiForgeryToken。他现在可以在浏览器中更改ProductId并发布删除其他人产品的请求吗?

c# asp.net-mvc asp.net-mvc-5 antiforgerytoken
1个回答
3
投票

简短的回答。这还不够。

防伪令牌只是说制作原始页面请求的人是进行更新的人。

基本授权属性仅验证用户是否已登录。

您正在寻找的是数据安全性。在微软自己的网站上有一个example

您在上一段中说过,黑客可以注册一个帐户创建他们自己的产品列表,并给出您在网址中显示的内容可以猜测合法的其他记录进行编辑

说你有一个网址

https://example.com/product/edit/13

是什么阻止了用户/黑客猜测

https://example.com/product/edit/12https://example.com/product/edit/14

如果没有数据级别的安全性来说明用户可以访问/不能访问/更新哪些记录,则会遇到恶意用户可以查看或编辑各种信息的情况。

这是FISERV发现暴露其他客户信息的确切情况

从文章

Hermansen已经注册以在新交易发布到他的帐户时收到电子邮件警报,并且他注意到该网站将其警报分配了特定的“事件编号”。预感到这些事件编号可能会按顺序分配,而其他记录可能会如果直接请求可用,Hermansen再次请求相同的页面,但首先在他的浏览器中编辑网站的代码,以便他的事件编号减少一位数。

© www.soinside.com 2019 - 2024. All rights reserved.