PHP cookie和成员安全 [英] PHP cookies and member security

查看:124
本文介绍了PHP cookie和成员安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个论坛,在登录时使用PHP会话来确定用户ID,以及用于日志项登录的Cookie。

I've created a forum which uses a PHP session when logged in to determine the user id, and cookies for log-term login.

两个问题:


  1. 这是最好的/安全的方法吗?

  2. Cookie可以手动添加地址栏用javascript,这是一个巨大的安全风险。这有什么办法吗?

谢谢!

推荐答案

首先,确保您使用的是https而不是http。这将保持您的流量不被嗅探和利用。

First, make sure you are using https and not http. This will keep your traffic from getting sniffed and exploited.

其次,随机生成一个值作为cookie中的令牌。这是多少大网站做他们的用户跟踪。在服务器端有跟踪身份的令牌到用户的地图。记住:来自客户端的任何东西都是不受信任的,可能会被篡改。

Secondly, generate as random a value as possible to use as a token in the cookie. This is how many of the big sites do their user tracking. Have a map of token to user on the server side that tracks the identities. Remember: Anything that comes from the client is untrusted and could be tampered with.

第三,使用 HMAC ,使篡改更加困难。

Third, use an HMAC to make tampering much more difficult. You don't want users being able to brute force other tokens.

编辑:

您可能会发现这些其他SO问题/答案有助于您构建此系统:

You may find these other SO questions/answers helpful as you build this system:


  1. 有关创建和使用令牌的详细信息成为可适用的REST服务): REST Web服务身份验证令牌实施

创建好的令牌(不要使用微时):

Creating good tokens (don't use microtime): Is using microtime() to generate password-reset tokens bad practice

这篇关于PHP cookie和成员安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆