Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Entity/Cast/ArrayCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ArrayCast extends BaseCast
public static function get($value, array $params = []): array
{
if (is_string($value) && (str_starts_with($value, 'a:') || str_starts_with($value, 's:'))) {
$value = unserialize($value);
$value = unserialize($value, ['allowed_classes' => false]);
}

return (array) $value;
Expand Down
34 changes: 34 additions & 0 deletions tests/system/Entity/Cast/ArrayCastTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Entity\Cast;

use CodeIgniter\Test\CIUnitTestCase;
use PHPUnit\Framework\Attributes\Group;
use stdClass;

/**
* @internal
*/
#[Group('Others')]
final class ArrayCastTest extends CIUnitTestCase
{
public function testGetPreventsObjectInjection(): void
{
$payload = serialize([new stdClass()]);

$result = ArrayCast::get($payload);

$this->assertInstanceOf('__PHP_Incomplete_Class', $result[0]);
}
}
Loading