← PHP / Laravel · 目次

PHP-027 / 上級

JWT 検証時のアルゴリズム未固定(alg none・鍵混同)

A07:2021 Identification and Authentication Failures · CWE-347 Improper Verification of Cryptographic Signature

なぜ問題になるのか?

ヘッダの alg を信頼すると署名検証が無力化されたり、公開鍵を HMAC 鍵として使われたりします。

修正方法

php
$payload = JWT::decode($token, new Key($publicKey, 'RS256'));  // 許可アルゴリズムを固定

参考資料