← PHP / Laravel · Contents

PHP-027 / Advanced

Not fixing the algorithm during JWT verification (alg none or key confusion)

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

Why is this a problem?

Trusting the header's alg can disable signature checking or allow a public key to be used as an HMAC key.

How to fix it

php
$payload = JWT::decode($token, new Key($publicKey, 'RS256'));  // Fix the allowed algorithm

Further reading