
Cloud Vulnerability DB
A community-led vulnerabilities database
Lcobucci\JWT\Signer\Ecdsa::verify() throws an unhandled error instead of returning false when given a correctly sized ECDSA signature (for example 64 bytes for ES256) whose R or S value has 17 or more leading zero bytes, such as R = 1 and S = 1. The cause is MultibyteStringConverter::toAsn1(), which writes the DER integer lengths with dechex() without zero-padding them to two hex digits, so hex2bin() receives an odd-length string and fails. An unauthenticated attacker who can submit a token to an application that verifies ES256/ES384/ES512 signatures can trigger this with a crafted signature, causing a server error rather than a clean authentication failure. It affects 5.6.1 and the current 6.0.x branch; the ConversionFailed handling added in 5.6.1 does not cover this path.
Lcobucci\JWT\Signer\Ecdsa::verify() converts the raw (IEEE P1363) signature into DER before calling openssl_verify(). It does this with Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter::toAsn1(). toAsn1() removes the leading zero bytes from each of R and S. It then writes each INTEGER’s length, and the SEQUENCE’s total length, as hex with dechex($lengthR), dechex($lengthS) and dechex($totalLength). These values are not zero-padded to two hex digits. Once an integer shrinks to fewer than 16 bytes (17 or more leading zero bytes in a 32-byte half), its length is a single hex digit. The assembled hex string then has an odd length, and hex2bin() rejects it: hex2bin() raises the warning “Hexadecimal input string must have an even length” and returns false. Applications that convert warnings to exceptions, as Laravel and Symfony do by default, get an ErrorException. Without such a handler, the method’s string return type gives a TypeError. Version 5.6.1 added catch (ConversionFailed) in Ecdsa::verify(), but that exception is only thrown by the length check that comes earlier. This failure happens later, in hex2bin(), so it isn’t caught. Affected: 5.6.1, and the 6.0.x branch at the time of writing. The code is unchanged since at least 5.6.0.
<?php require 'vendor/autoload.php'; use Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter; // 64-byte ES256 signature with R = 1 and S = 1 $sig = str_repeat("\0", 31) . "\x01" . str_repeat("\0", 31) . "\x01"; (new MultibyteStringConverter())->toAsn1($sig, 64); // => Warning/ErrorException: hex2bin(): Hexadecimal input string must have an even length ?> Steps:
Any application that verifies untrusted ES256, ES384 or ES512 tokens with this library can be made to throw an unhandled error, instead of cleanly rejecting the token, by an unauthenticated attacker sending one crafted signature. The attacker needs no key and no valid token: the header and claims can be anything well formed. Depending on the application, the consequences include:
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."