Skip to content

Commit c304edb

Browse files
committed
Fix PHP Object Injection vulnerability in Entity ArrayCast
1 parent 27e46b8 commit c304edb

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

system/Entity/Cast/ArrayCast.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ArrayCast extends BaseCast
1818
public static function get($value, array $params = []): array
1919
{
2020
if (is_string($value) && (str_starts_with($value, 'a:') || str_starts_with($value, 's:'))) {
21-
$value = unserialize($value);
21+
$value = unserialize($value, ['allowed_classes' => false]);
2222
}
2323

2424
return (array) $value;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace CodeIgniter\Entity\Cast;
15+
16+
use CodeIgniter\Test\CIUnitTestCase;
17+
use PHPUnit\Framework\Attributes\Group;
18+
use stdClass;
19+
20+
/**
21+
* @internal
22+
*/
23+
#[Group('Others')]
24+
final class ArrayCastTest extends CIUnitTestCase
25+
{
26+
public function testGetPreventsObjectInjection(): void
27+
{
28+
$payload = serialize([new stdClass()]);
29+
30+
$result = ArrayCast::get($payload);
31+
32+
$this->assertIsArray($result);
33+
$this->assertInstanceOf('__PHP_Incomplete_Class', $result[0]);
34+
}
35+
}

0 commit comments

Comments
 (0)