-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-7322-jrq4-x5hf
Ensure key contents is used for all hashing algorithms
- Loading branch information
Showing
4 changed files
with
45 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,16 @@ | |
use Lcobucci\JWT\Builder; | ||
use Lcobucci\JWT\CheckForDeprecations; | ||
use Lcobucci\JWT\Parser; | ||
use Lcobucci\JWT\Signer\Key\InMemory; | ||
use Lcobucci\JWT\Signer\Key\LocalFileReference; | ||
use Lcobucci\JWT\Token; | ||
use Lcobucci\JWT\Signature; | ||
use Lcobucci\JWT\Signer\Hmac\Sha256; | ||
use Lcobucci\JWT\Signer\Hmac\Sha512; | ||
use ReflectionProperty; | ||
use function file_put_contents; | ||
use function sys_get_temp_dir; | ||
use function tempnam; | ||
|
||
/** | ||
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> | ||
|
@@ -197,4 +203,39 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs() | |
$this->assertEquals('world', $token->getClaim('hello')); | ||
$this->assertTrue($token->verify($this->signer, 'testing')); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @coversNothing | ||
* | ||
* @see \Lcobucci\JWT\Signer\Key::setContent() | ||
*/ | ||
public function signatureValidationWithLocalFileKeyReferenceWillOperateWithKeyContents() | ||
{ | ||
$key = tempnam(sys_get_temp_dir(), 'key'); | ||
file_put_contents($key, 'just a dummy key'); | ||
|
||
$validKey = LocalFileReference::file($key); | ||
$invalidKey = InMemory::plainText($key); | ||
$signer = new Sha256(); | ||
|
||
// 3.4.x implicitly extracts key contents, when `file://` is detected | ||
$reflectionContents = new ReflectionProperty(InMemory::class, 'content'); | ||
$reflectionContents->setAccessible(true); | ||
$reflectionContents->setValue($invalidKey, 'file://' . $key); | ||
|
||
$token = (new Builder()) | ||
->withClaim('foo', 'bar') | ||
->getToken($signer, $validKey); | ||
|
||
self::assertFalse( | ||
$token->verify($signer, $invalidKey), | ||
'Token cannot be validated against the **path** of the key' | ||
); | ||
self::assertTrue( | ||
$token->verify($signer, $validKey), | ||
'Token can be validated against the **contents** of the key' | ||
); | ||
} | ||
} |