我正在构建一个对定时攻击敏感的应用程序。我在考虑不要在嵌套 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 语句的评估。我该如何解决这个问题?