简体   繁体   English

从数据库中删除内容,安全预防措施

[英]Removing content from database, security precautions

UPDATE: 更新:

I added the CSRF protection like Berdir told me, with the help of the link below to make my application work again. 我添加了像Berdir这样的CSRF保护,借助下面的链接让我的应用程序再次运行。 However.. I'm not quite sure what I did right now :D How is this going to make my app more secure? 但是..我不太清楚我现在做了什么:D这怎么能让我的应用程序更安全? I'm particularly bothered by the fact that I'm now getting a cookie value in my ajax code, because I have to pass it with my ajax call.. otherwise it just doesn't work. 我特别感到困扰的是,我现在在我的ajax代码中获得了一个cookie值,因为我必须通过我的ajax调用传递它...否则它只是不起作用。 Doesn't this give away some crucial information about the cookie? 这不会泄露一些关于cookie的重要信息吗? Or am I just being paranoid. 或者我只是偏执狂。 Thanks! 谢谢!

http://aymsystems.com/ajax-csrf-protection-codeigniter-20 http://aymsystems.com/ajax-csrf-protection-codeigniter-20

//old Hi. //老嗨

In this web app I'm building, I have a functionality to add 'tips and tricks' about certain subjects. 在我正在构建的这个Web应用程序中,我有一个功能可以添加关于某些主题的“提示和技巧”。 These pages can be added only by accounts with the admin role. 这些页面只能由具有admin角色的帐户添加。 However, I also want the ability to remove these pages. 但是,我也希望能够删除这些页面。 (Always handy, right). (总是很方便,对吧)。 Since I'm using CodeIgniter, I was thinking of just making a controller function which takes an ID, and passes this ID to the model where the page corresponding to that ID would get deleted from the database. 因为我正在使用CodeIgniter,所以我想要创建一个带有ID的控制器函数,并将此ID传递给模型,在该模型中,与该ID相对应的页面将从数据库中删除。

Just to make this clear: 只是为了说清楚:

Controller: 控制器:

public function del_content($id)
{
    $this->content_model->del_content($id)
}

Model: 模型:

public function del_content($id)
{
    // database code which I can't be bothered to look up now
    // something like $this->db->where(), $this->db->delete()
}

This is all really simple, but I'm scared that it might be too simple. 这一切都很简单,但我很害怕它可能简单了。 This doesn't really seem oh so very secure to me, is it? 这对我来说真的不太安全哦,是吗? Since you would be able to call the function from the URL address bar in your browser, you could basically remove the whole content table through that. 由于您可以从浏览器中的URL地址栏调用该函数,因此您基本上可以删除整个内容表。 (Since you'd be doing http://mywebsite/controller/del_content/3 for the item with ID 3). (因为你要对ID为3的项目进行http://mywebsite/controller/del_content/3 3)。 Of course, only administrator accounts would have access to that function, but still.. 当然,只有管理员帐户才能访问该功能,但仍然...

I have never programmed anything like this before and thus never had to think about the security measures I should take in this case. 我以前从来没有编过这样的事情,因此从来没有考虑过我应该采取的安全措施。 Would anyone be kind enough to give me some things I should keep an eye out for and perhaps some ideas, suggestions, on how to make this more secure? 有人会善意地给我一些我应该留意的事情,也许还有一些关于如何使这更安全的想法,建议?

Thanks a lot! 非常感谢!

What you need to protect against are CSRF attacks. 您需要防范的是CSRF攻击。 Put simply, they are attacks which trick administrators into visiting a certain URL by GET or POST request. 简而言之,它们是通过GET或POST请求诱使管理员访问某个URL的攻击。

The typical way to do that are tokens. 典型的方法是令牌。 When generating the link or form that points to the delete action, you generate a token that you send to the client (either as hidden form field or as part of the GET URL), also store it on the server for the current session and when that action is executed, you compare the submitted and the stored token and only continue if they match. 生成指向删除操作的链接或表单时,您将生成一个发送到客户端的令牌(作为隐藏表单字段或作为GET URL的一部分),还将其存储在服务器上以用于当前会话以及何时执行该操作后,您将比较提交的和存储的令牌,并且仅在匹配时才继续。

Many frameworks/systems have this built-in in some ways, for example are all forms generated with the Form API in Drupal protected against such attacks. 许多框架/系统在某些方面具有内置功能,例如,使用Drupal中的Form API生成的所有表单都可以防止此类攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM