php session 安全
在stackoverflow上看到关于 php session 安全的讨论,特记录之。(http://stackoverflow.com/questions/328/php-session-security)
1.使用ssl
2.重设session_id
引用php中可以:session_regenerate_id(true);
3.设置session有效时间
可以参考鸟哥的文章:http://www.laruence.com/2012/01/10/2469.html
4.不是全局变量
5.存储信息在服务器上,不发送重要信息到cookie上
6.检查用户user_agent和ip
引用
php 使用:if ($_session['user_agent'] != $_server['http_user_agent']
|| $_session['user_ip'] != $_server['remote_addr']) {
//something fishy is going on here?
}
7.设置 httponly 避免 session 攻击
参考:http://ilia.ws/archives/121-httponly-cookie-flag-support-in-php-5.2.html
8.lock down access to the sessions on the file system or use custom session handling
引用可是自定义session session_set_save_handler()
将session存储在db, memcached等
9.for sensitive operations consider requiring logged in users to provide their authenication details again