我什么时候以及为什么应该使用 session_regenerate_id()? [英] When and why I should use session_regenerate_id()?

查看:25
本文介绍了我什么时候以及为什么应该使用 session_regenerate_id()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以及何时应该在 php 中使用 session_regenerate_id() 函数?我应该在使用 session_start() 后一直使用它吗?我已经读到我必须使用它来防止会话固定,这是唯一的原因吗?

Why and when should I use the session_regenerate_id() function in php? Should I always use it after I use the session_start()? I've read that I have to use it to prevent session fixation, is this the only reason?

推荐答案

什么是session_regenerate_id()?

正如函数名所说,它是一个将当前会话 ID 替换为新 ID 并保留当前会话信息的函数.

What is session_regenerate_id()?

As the function name says, it is a function that will replace the current session ID with a new one, and keep the current session information.

它主要有助于防止会话固定攻击.会话固定攻击是恶意用户试图利用系统中的漏洞来固定(设置)另一个用户的会话 ID (SID).通过这样做,他们将获得原始用户的完全访问权限,并能够执行原本需要身份验证的任务.

It mainly helps prevent session fixation attacks. Session fixation attacks is where a malicious user tries to exploit the vulnerability in a system to fixate (set) the session ID (SID) of another user. By doing so, they will get complete access as the original user and be able to do tasks that would otherwise require authentication.

为防止此类攻击,当用户成功登录时(或每 X 个请求),使用 session_regenerate_id() 为用户分配一个新的会话 ID.现在只有他拥有会话 ID,而您旧的(固定的)会话 ID 不再有效.

To prevent such attacks, assign the user a new session ID using session_regenerate_id() when he successfully signs in (or for every X requests). Now only he has the session ID, and your old (fixated) session ID is no longer valid.

正如 symbecean 在下面的评论中指出的那样,会话 ID 必须在任何身份验证状态转换时更改,并且仅在身份验证转换时.

As symbecean points out in the comments below, the session id must be changed at any transition in authentication state and only at authentication transitions.

进一步阅读:

这篇关于我什么时候以及为什么应该使用 session_regenerate_id()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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