File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -303,6 +303,10 @@ public function set($data, $value = null)
303303 }
304304
305305 foreach ($ data as $ sessionKey => $ sessionValue ) {
306+ if (is_string ($ sessionKey ) && str_starts_with ($ sessionKey , '__ci_ ' )) {
307+ continue ;
308+ }
309+
306310 $ _SESSION [$ sessionKey ] = $ sessionValue ;
307311 }
308312 }
@@ -370,6 +374,10 @@ public function remove($key)
370374 */
371375 public function __set (string $ key , $ value )
372376 {
377+ if (str_starts_with ($ key , '__ci_ ' )) {
378+ return ;
379+ }
380+
373381 $ _SESSION [$ key ] = $ value ;
374382 }
375383
Original file line number Diff line number Diff line change @@ -328,6 +328,30 @@ public function testSetMagicMethod(): void
328328 $ this ->assertSame ('bar ' , $ _SESSION ['foo ' ]);
329329 }
330330
331+ public function testSetIgnoresCiVars (): void
332+ {
333+ $ session = $ this ->getInstance ();
334+ $ session ->start ();
335+
336+ $ session ->set ('__ci_vars ' , 'malicious ' );
337+ $ session ->set ('__ci_last_regenerate ' , 'malicious ' );
338+
339+ $ this ->assertArrayNotHasKey ('__ci_vars ' , $ _SESSION );
340+ $ this ->assertNotSame ('malicious ' , $ _SESSION ['__ci_last_regenerate ' ]);
341+ }
342+
343+ public function testSetMagicMethodIgnoresCiVars (): void
344+ {
345+ $ session = $ this ->getInstance ();
346+ $ session ->start ();
347+
348+ $ session ->__ci_vars = 'malicious ' ; // @phpstan-ignore property.notFound
349+ $ session ->__ci_last_regenerate = 'malicious ' ; // @phpstan-ignore property.notFound
350+
351+ $ this ->assertArrayNotHasKey ('__ci_vars ' , $ _SESSION );
352+ $ this ->assertNotSame ('malicious ' , $ _SESSION ['__ci_last_regenerate ' ]);
353+ }
354+
331355 public function testCanFlashData (): void
332356 {
333357 $ session = $ this ->getInstance ();
You can’t perform that action at this time.
0 commit comments