File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 | Command to generate |
12+ | -----------| -----------------------| ---------------------------------------------------|
13+ | HS256 | 32 bytes (256 bits) | ` php -r 'echo base64_encode(random_bytes(32));' ` |
14+ | HS384 | 48 bytes (384 bits) | ` php -r 'echo base64_encode(random_bytes(48));' ` |
15+ | HS512 | 64 bytes (512 bits) | ` php -r 'echo base64_encode(random_bytes(64));' ` |
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+ Run the command for your algorithm, then update ` $keys ` in ** app/Config/AuthJWT.php** :
21+
22+ ``` php
23+ 'secret' => '<output of the command above >',
24+ ```
25+
26+ > [ !NOTE]
27+ > Existing tokens signed with the old short secret will become unverifiable once
28+ > the secret is replaced. Users will need to re-authenticate to obtain new tokens.
29+
330## Version 1.0.0-beta.8 to 1.0.0
431
532## Removed Deprecated Items
Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class AuthJWT extends BaseConfig
5858 [
5959 'kid ' => '' , // Key ID. Optional if you have only one key.
6060 'alg ' => 'HS256 ' , // algorithm.
61- // Set secret random string. Needs at least 256 bits for HS256 algorithm .
61+ // Set secret random string. Needs at least 256/384/512 bits for HS256/HS384/HS512 .
6262 // E.g., $ php -r 'echo base64_encode(random_bytes(32));'
6363 'secret ' => '<Set secret random string> ' ,
6464 ],
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments