← 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'));  // 固定允许的算法

延伸阅读