dtvx3420 2019-04-18 21:44
浏览 84

会话中生成的CSRF令牌的值不会持久存在

I am writing app in PHP 7.3 where users forms to submit data using forms. These forms have to be protected using CSRF.

When a request is made, I want first to try to validate the CSRF token ($_SESSION against $_POST or $_GET) and store the result in a variable. Then I want to generate a new token and store it in the $_SESSION.

The logic of the app is to validate CSRF, generate new CSRF, check if POST is made and the validation were sucessful, echo multiple forms to output.

I tried to simplify the code, but I have access to only one server, so I am unable to test, whether this is a coding or server error.

<?php

session_start();

echo $_SESSION["a"];
$validateCsrf = false;
if (!empty($_POST["a"]) && $_SESSION["a"] === $_POST["a"]) {
    $validateCsrf = true;
}

$_SESSION["a"] = random_int(100000000,999999999);
echo $_SESSION["a"];

?>

I expect output of this to first show the old CSRF token and then the new CSRF token. If you reload the page, the second token should "move" to the first place as it becomes the old one that is getting validated, however this does not happen there is some other output.

Example output:

209959590 576642097
534067777 374285992

Expected output:

209959590 576642097
576642097 374285992

What am I doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据