Skip to content

Commit eea5597

Browse files
committed
chore: upgrade firebase/php-jwt to v7
1 parent 6430943 commit eea5597

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

UPGRADING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
# Upgrade Guide
22

3+
## Version 1.2 to 1.3
4+
5+
### JWT: Minimum Key Length Now Enforced
6+
7+
If you use the JWT authenticator with an HMAC algorithm (`HS256`, `HS384`, or
8+
`HS512`), the underlying `firebase/php-jwt` library was upgraded to v7, which
9+
now enforces minimum key lengths at runtime.
10+
11+
| Algorithm | Minimum secret length |
12+
|-----------|-----------------------|
13+
| HS256 | 32 bytes (256 bits) |
14+
| HS384 | 48 bytes (384 bits) |
15+
| HS512 | 64 bytes (512 bits) |
16+
17+
If your secret is too short, every JWT encode **and** decode call will throw a
18+
`LogicException` with the message `Cannot encode/decode JWT: Provided key is too short`.
19+
20+
To generate a valid secret, run:
21+
22+
```console
23+
php -r 'echo base64_encode(random_bytes(32));'
24+
```
25+
26+
Then update `$keys` in **app/Config/AuthJWT.php**:
27+
28+
```php
29+
'secret' => '<output of the command above>',
30+
```
31+
32+
> [!NOTE]
33+
> Existing tokens signed with the old short secret will become unverifiable once
34+
> the secret is replaced. Users will need to re-authenticate to obtain new tokens.
35+
336
## Version 1.0.0-beta.8 to 1.0.0
437

538
## Removed Deprecated Items

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"codeigniter/phpstan-codeigniter": "^1.3",
3333
"codeigniter4/devkit": "^1.3",
3434
"codeigniter4/framework": ">=4.3.5 <4.5.0 || ^4.5.1",
35-
"firebase/php-jwt": "^6.4",
35+
"firebase/php-jwt": "^7.0.3",
3636
"mikey179/vfsstream": "^1.6.7",
3737
"mockery/mockery": "^1.0",
3838
"phpstan/phpstan-strict-rules": "^2.0"

tests/Unit/Authentication/JWT/JWTManagerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function testParseCanDecodeTokenSignedByOldKey(): void
273273
[
274274
'kid' => 'Key01',
275275
'alg' => 'HS256', // algorithm.
276-
'secret' => 'Key01_Secret',
276+
'secret' => 'Key01_Secret_at_least_256_bits!!',
277277
],
278278
];
279279

@@ -289,12 +289,12 @@ public function testParseCanDecodeTokenSignedByOldKey(): void
289289
[
290290
'kid' => 'Key02',
291291
'alg' => 'HS256', // algorithm.
292-
'secret' => 'Key02_Secret',
292+
'secret' => 'Key02_Secret_at_least_256_bits!!',
293293
],
294294
[
295295
'kid' => 'Key01',
296296
'alg' => 'HS256', // algorithm.
297-
'secret' => 'Key01_Secret',
297+
'secret' => 'Key01_Secret_at_least_256_bits!!',
298298
],
299299
];
300300

@@ -311,7 +311,7 @@ public function testParseCanSpecifyKey(): void
311311
[
312312
'kid' => 'Key01',
313313
'alg' => 'HS256', // algorithm.
314-
'secret' => 'Key01_Secret',
314+
'secret' => 'Key01_Secret_at_least_256_bits!!',
315315
],
316316
];
317317

tests/_support/TestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,10 @@ protected function setUp(): void
5151
$config = config('Security');
5252
$config->csrfProtection = 'session';
5353
Factories::injectMock('config', 'Security', $config);
54+
55+
// Set a valid JWT secret (≥ 256 bits for HS256) required by firebase/php-jwt v7
56+
$config = config('AuthJWT');
57+
$config->keys['default'][0]['secret'] = 'a-very-secure-secret-key-for-hs256-ok';
58+
Factories::injectMock('config', 'AuthJWT', $config);
5459
}
5560
}

0 commit comments

Comments
 (0)