gpt4 book ai didi

php - 成功登录后重新生成 session ID 是否足以防止 session 固定?

转载 作者:可可西里 更新时间:2023-11-01 12:33:01 26 4
gpt4 key购买 nike

我读了a guide目前,我对此有点困惑:

To address this weakness, it helps to understand the scope of the problem. Session fixation is merely a stepping-stone—the purpose of the attack is to get a session identifier that can be used to hijack a session. This is most useful when the session being hijacked has a higher level of privilege than the attacker can obtain through legitimate means. This level of privilege can be as simple as being logged in. If the session identifier is regenerated every time there is a change in the level of privilege, the risk of session fixation is practically eliminated:

<?php
$_SESSION['logged_in'] = FALSE;
if (check_login())
{
session_regenerate_id();
$_SESSION['logged_in'] = TRUE;
}
?>

如果我理解正确的话,我只需要做一个session_regenerate_id()在我分配像 logged_in = true 这样的值之前或 user_id = id然后我做了一个防止 session 固定的保护?

这就够了吗?我还能做什么?

最佳答案

实际上, session 固定最常见的情况是攻击者将放置一个链接,例如到您的主页或登录页面,在 url 上设置 session ID(作为 GET 变量)并等待一些用户登录。由于攻击者知道这些用户的 session ID,并且可以在 url 中设置此 session ID,因此攻击者可以重新访问注册用户的个人资料页面/仪表板等链接并冒充此用户。

因此,为了防止此类攻击, session ID 重新生成就足够了,因为攻击者仍然使用未经身份验证的 session 。您可以采取的另一个步骤是不接受 url 中的 session ID。为此,您必须设置(如果您可以在服务器上访问此文件,则在 php.ini 中或通过 ini_set)设置以下内容:

  1. session.use_only_cookies 应设置为 TRUE(仅使用 cookie 作为 php session ID,不要通过 url 传递)
  2. session.use_trans_sid 应设置为 FALSE(如果禁用 cookie,则不应通过 url 传递 session ID)

这样,攻击者甚至无法为未经身份验证的 session 设置 session ID。

关于php - 成功登录后重新生成 session ID 是否足以防止 session 固定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7461835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com