0

我正在构建一个对定时攻击敏感的应用程序。我在考虑不要在嵌套 if 语句的地方创建一个“if 树”,而是运行所有 if 语句,然后在最后检查所有条件,如下所示:


    if (password_verify($pass, $hash)){
        $cond1 = true
    }else{
        $cond1 = false
    }
        // some more ifs that run in serial
    if ($cond1 && $cond2 && cond3 ... etc){
        // some code
    }

但是我相信最终的 if 语句仍然是脆弱的,因为如果存在某些会使整个语句失败的条件,PHP 会缩短 if 语句的评估。我该如何解决这个问题?

4

1 回答 1

0

编辑:这种方法不起作用,因为一旦一个字符关闭,字符串比较也会被缩短。

我想到了。我没有将布尔值分配给条件变量,而是分配了一个字符“0”或“1”。然后我最后连接所有条件并检查该字符串是否为“11111111”。

if (password_verify($pass, $hash)){
    $cond1 = "1";
}else{
    $cond1 = "0";
}
// some more ifs that run in serial
$allcond = $cond1.$cond2.$cond3; //etc
if ($allcond = "11111"){
    // some code
}
于 2019-08-25T11:23:09.960 回答