← PHP / Laravel · 目录

PHP-064 / 入门

PHP 宽松比较(==)与类型转换

A07:2021 Identification and Authentication Failures · CWE-697 Incorrect Comparison

为什么存在问题?

比较可能被绕过,例如 PHP 7 及更早版本中 "0e123" == "0e456" 为真。

如何修复

php
if (is_string($code) && hash_equals($expected, $code)) { ... }

延伸阅读