简体   繁体   English

控制器安全性问题中的代码点火器身份验证代码

[英]Code igniter authentication code in controller security question

I have a main controller to handle the very front-end of my authentication system, it handles login, logout, update user info, etc. functions that I anticipate calling by POST'ing from views/forms. 我有一个主控制器来处理我的身份验证系统的前端,它处理登录,注销,更新用户信息等功能,这些功能预计将通过视图/窗体的POST调用。 What about something like a "delete_user" function though? 但是,类似“ delete_user”功能的东西呢? My thoughts are a button in someones admin panel would say "Delete Account" and it would post to "/auth/delete", and the function would delete the user based on their session username or id. 我的想法是某人的管理面板中的一个按钮会显示“删除帐户”,并将其发布到“ / auth / delete”,并且该功能将根据其会话用户名或ID删除用户。 This seems a bit open ended, you could send out a link to someone and when they opened it while in that application it would delete their account.. Whats the best way to handle this? 这似乎有点开放,您可以向某人发送一个链接,当他们在该应用程序中打开该链接时,它将删除其帐户。.处理此问题的最佳方法是什么?

What you are concerned about is actually called Cross Site Request Forgery , or XSRF. 您实际上担心的是跨站点请求伪造或XSRF。 You can read more about it on the OWASP Website . 您可以在OWASP网站上阅读有关它的更多信息。

A few things that you should do overcome this problem - 您应该做的一些事情可以克服这个问题-

  1. Use POST for the delete operation. 使用POST进行删除操作。 This doesn't protect you from XSRF, but protects you from link followers/page accelerators. 这不能保护您免受XSRF的侵害,但可以保护您免受链接关注者/页面加速器的侵害。 Its also a http best practice. 这也是http的最佳做法。
  2. Post your session identifier in the body of the request . 在请求正文中发布您的会话标识符。 On the server side, compare the session identifier from cookie and from the request - if they are different, reject the request. 在服务器端,比较cookie和请求中的会话标识符-如果它们不同,则拒绝该请求。 This is the " double submit cookie " method to prevent XSRF. 这是防止XSRF的“ 双重提交cookie ”方法。
  3. Alternatively, you can ask the user to solve a captcha. 或者,您可以要求用户解决验证码。

Additionally, a "soft-delete" on the lines of what Tom mentions is also a good idea. 另外,在汤姆提到的内容上进行“软删除”也是一个好主意。

It sounds like adding some other piece of information to the function is the answer. 听起来像向功能添加其他一些信息就是答案。 Here is the function in question: 这是有问题的功能:

function delete()   {
        $id = $this->session->userdata('user_id');
        $this->auth->delete_user($id);
        redirect('home');   
    }

In code igniter this can be accessed by just visiting site.com/class/delete which is my problem. 在代码点火器中,这可以通过访问site.com/class/delete来访问,这是我的问题。 I think a good plan will be to post an authentication token (saved in cookie) with the delete button, so it can't take action via the URL: 我认为一个好的计划是使用Delete按钮发布身份验证令牌(保存在Cookie中),因此它无法通过URL采取措施:

function delete()   {
        if($this->input->post("token") == $this->session->userdata('token'))    {
            $id = $this->session->userdata('user_id');
            $this->auth->delete_user($id);
        }
        redirect('home');   
    }

I don't think i need a soft-delete right now, but thank you for that good tip! 我不认为我现在需要进行软删除,但是感谢您的提示! If you see any other issues please explain, thank you. 如果您发现任何其他问题,请解释,谢谢。

Have a look at one of the better known authentication libraries for CodeIgniter: 看看CodeIgniter最为人熟知的身份验证库之一:

https://github.com/benedmunds/CodeIgniter-Ion-Auth https://github.com/benedmunds/CodeIgniter-Ion-Auth

If you don't decide to just use it, you can at least get some good ideas about how to go about creating your own 如果您不决定只使用它,那么至少可以得到一些有关如何创建自己的想法的好主意。

The way i handle this is as follows. 我处理此问题的方式如下。 On your account page you have a link to delete the account. 在您的帐户页面上,您有一个删除帐户的链接。 They click that page and are greeted with another page asking if they are really sure and if so please enter their password to confirm they are sure. 他们单击该页面,然后看到另一个页面,询问他们是否确实确定,如果确定,请输入密码以确认他们确定。

After they do that i deactivate their account (not delete) and send an email saying that their account was deactivated and if this was intended no other action is needed on their part. 在他们这样做之后,我将停用他们的帐户(而不是删除),并发送电子邮件说他们的帐户已被停用,如果打算这样做,则他们不需要采取其他任何措施。 If it was not intended they can login to their account and it will reactivate it. 如果不希望这样做,他们可以登录自己的帐户,它将重新激活它。 (within 48 hours) after 48 hours i delete their account and information. (48小时内)(在48小时内)我删除了他们的帐户和信息。

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

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