CodeIgniter 身份验证安全模型

发布于 2024-10-07 23:13:49 字数 415 浏览 3 评论 0原文

我已经为 CodeIgniter 构建了一个自定义身份验证系统(我知道有各种可用的第三方库,但这是为了我自己的利益),但我担心我错过了一些明显的东西,可能会导致整个事情失败。

我使用 CI 会话(通过数据库)并加密 cookie 值,以进行一些可能毫无意义的混淆。登录通过 SSL 进行(并且 cookie 被修改为仅安全)。我还使用 phpass 来散列密码以进行存储,尽管这与这里并不真正相关。这部分中的某个地方可能存在薄弱环节,但我主要担心的是,页到页检查基本上由 if is_logged_in = true 类型方法及其会话中的用户名组成。这一点让我担心,因为它似乎有点太“容易”了。这种方法很脆弱吗?我是否应该逐页计算用户代理或其他内容的哈希值并确保它们匹配?

任何指示将不胜感激。就像我说的,我知道已有的解决方案,但我试图在这里学习一些知识:)

I've built a custom auth system for CodeIgniter (I know there are various 3rd party libraries available but this is for my own benefit) but I'm worried I'm missing something obvious that could bring the whole thing down.

I use CI sessions (through the database) and encrypt cookie values for a little bit of probably pointless obfuscation. Logins take place over SSL (and cookies are modified to be secure only). I also use phpass to hash passwords for storage, though thats not really relevant here. There may be a weak link in this part somewhere but my main concern is that page-to-page checks basically consist of a if is_logged_in = true type approach along with their username in the session. This bit concerns me as it seems a bit too 'easy'. Is this approach quite vulnerable? Should I be computing a page-by-page hash of, say, user-agent or whatever and making sure they match?

Any pointers would be most appreciated. Like I said, I'm aware of pre-existing solutions but I'm trying to learn me some learning here :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仙气飘飘 2024-10-14 23:13:49

你提到的一切都很好。不过我对 phpass 并不熟悉。确保在对密码进行哈希处理时使用的是盐。

if_logged_in = true 检查就足够了,因为会话数据存储在服务器端。检查用户代理等内容的原因是为了帮助防止会话劫持,即一个人获取另一个人的会话 ID。

Everything you mentioned is good. I'm not familiar with phpass however. Make sure that when you hash the passwords, that you are using a salt.

An if_logged_in = true check is sufficient because session data is stored server-side. The reason for checking things such as user-agent is to help protect against session hijacking, where one person obtains another person's session ID.

左耳近心 2024-10-14 23:13:49

PS:我不是安全专家,所以我更喜欢使用由安全专家检查的系统:openid、facebook connect、twitter(oauth)、google Signin 等

但这是我的清单(我可以认为off):

  • 使用 SSL 确保通过网络发送密码时无人能读取您的密码。
  • 你应该清理你的所有输入($ _POST、$_GET、$_SERVER 等)。如果不是局部变量,你应该小心。例如,您应该使用此过滤器 => 清理 $_SESSION['is_logged_in'] $var = filter_var($_SESSION['is_logged_in'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); AGAIN 您应该对来自服务器的所有输入执行此操作,因为它们不是安全的。最好的方法是使用白名单而不是黑名单。因为你有可能会错过一些东西。
  • 使用 PDO 来最大限度地降低 sql 注入的风险。
  • 不要以纯文本形式将密码存储在数据库中,而是 散列 它们。我想这件事还是有风险的。因为最近 gawker/lifehacker 受到了损害(想知道它是如何发生的?)。我想你的 phpass 非常可靠,因为 owasp 也推荐它。
  • 警惕 XSS 攻击。由于正在清理输入,因此已经完成
  • 针对 CSRF 采取措施。例如,如果您可以在用户登录时修改电子邮件地址,这也可能非常危险。下一步是发送电子邮件以重置您的密码,并且您的系统已受到损害。

P.S: I am no security expert so I prefer using system that are inspected by security-experts: openid, facebook connect, twitter(oauth), google signin, etc

But here is my Checklist(I can think off):

  • use SSL to make sure nobody can read your password when sent over the wire.
  • you should sanitize all your input($_POST, $_GET, $_SERVER, etc). If is not a local variable you should be careful. So for example you should sanitize $_SESSION['is_logged_in'] using this filter => $var = filter_var($_SESSION['is_logged_in'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); AGAIN You should do that for all input coming from the server, because they aren't safe. The best approach is to use whitelist instead of blacklist. Because there is a chance you will miss something.
  • Use PDO to minimize risk of sql-injection.
  • Don't store your passwords in your database in plain text, but hash them. Still risky business I guess. Because recently gawker/lifehacker has been comprimised(wondering how it could happen?). I guess your phpass is pretty solid because owasp also recommends it.
  • Be aware off for XSS attacks. Is already done because of sanitizing input
  • Take measures against CSRF. This can also be very dangerous if for example you can modify e-mail adress when user is logged in. Next step is to sent an e-mail to reset your password and your system is comprimised.
北城半夏 2024-10-14 23:13:49

我不熟悉 phpass 但检查它是否使用 MD5,因为如果使用则它不够好。使用 bycrypt http://www.memonic.com/user/pneff/id/1qHCT

I am not familiar with phpass but check to see if it uses MD5 because if it does then it's not good enough. Use bycrypt http://www.memonic.com/user/pneff/id/1qHCT

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文