← 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)) { ... }

参考資料