CVE-2016-5431 (published 2019-08-07T15:15Z)

The PHP JOSE Library by Gree Inc. before version 2.2.1 is vulnerable to key confusion/algorithm substitution in the JWS component resulting in bypassing the signature verification via crafted tokens.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:N/I:P/A:N)
CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N)

Weakness information:
cwe_id: CWE-327
cwe_name: Use of a Broken or Risky Cryptographic Algorithm
description: The product uses a broken or risky cryptographic algorithm or protocol.
extended_description: 
	   Cryptographic algorithms are the methods by which data is scrambled to prevent observation or influence by unauthorized actors. Insecure cryptography can be exploited to expose sensitive information, modify data in unexpected ways, spoof identities of other users or devices, or other impacts.
           It is very difficult to produce a secure algorithm, and even high-profile algorithms by accomplished cryptographic experts have been broken. Well-known techniques exist to break or weaken various kinds of cryptography. Accordingly, there are a small number of well-understood and heavily studied algorithms that should be used by most products. Using a non-standard or known-insecure algorithm is dangerous because a determined adversary may be able to break the algorithm and compromise whatever data has been protected.
           Since the state of cryptography advances so rapidly, it is common for an algorithm to be considered "unsafe" even if it was once thought to be strong. This can happen when new attacks are discovered, or if computing power increases so much that the cryptographic algorithm no longer provides the amount of protection that was originally thought.
	   For a number of reasons, this weakness is even more challenging to manage with hardware deployment of cryptographic algorithms as opposed to software implementation. First, if a flaw is discovered with hardware-implemented cryptography, the flaw cannot be fixed in most cases without a recall of the product, because hardware is not easily replaceable like software. Second, because the hardware product is expected to work for years, the adversary's computing power will only increase over time.
	 
         

Fix information:
repo_url: https://github.com/nov/jose-php
commit_details: repo_url: https://github.com/nov/jose-php
author: nov
author_date: 2016-08-30 10:37:36+09:00
msg: explicit alg check & secure hash comparison
repository: repo_url: https://github.com/nov/jose-php
repo_name: nov/jose-php
description: PHP JOSE Library (JWT, JWS, JWE, JWK, JWK Set, JWK Thumbprint are supported)
repo_language: PHP
owner: nov
file_changes: filename: JWS.php
change_type: ModificationType.MODIFY
diff: @@ -122,14 +122,20 @@ class JOSE_JWS extends JOSE_JWT {
         $segments = explode('.', $this->raw);
         $signature_base_string = implode('.', array($segments[0], $segments[1]));
         if (!$expected_alg) {
-            # NOTE: might better to warn here
             $expected_alg = $this->header['alg'];
+            $using_autodetected_alg = true;
         }
         switch ($expected_alg) {
             case 'HS256':
             case 'HS384':
             case 'HS512':
-                return $this->signature === hash_hmac($this->digest(), $signature_base_string, $public_key_or_secret, true);
+                if ($using_autodetected_alg) {
+                    throw new JOSE_Exception_UnexpectedAlgorithm(
+                        'HMAC algs MUST be explicitly specified as $expected_alg'
+                    );
+                }
+                $hmac_hash = hash_hmac($this->digest(), $signature_base_string, $public_key_or_secret, true);
+                return hash_equals($this->signature, $hmac_hash);
             case 'RS256':
             case 'RS384':
             case 'RS512':

programming_language: PHP