Skip to content

Commit

Permalink
block json mass assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 6, 2020
1 parent 5dfafef commit 624d873
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public function isFillable($key)
*/
public function isGuarded($key)
{
if (strpos($key, '->')) {
$key = Str::before($key, '->');
}

return $this->getGuarded() == ['*'] || ! empty(preg_grep('/^'.preg_quote($key).'$/i', $this->getGuarded()));
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Database/EloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public function testCantUpdateGuardedAttributesUsingDifferentCasing()
$this->assertNull($model->ID);
}

public function testCantUpdateGuardedAttributeUsingJson()
{
$model = new TestModel2;

$model->fill(['id->foo' => 123]);

$this->assertNull($model->id);
}

public function testUserCanUpdateNullableDate()
{
$user = TestModel1::create([
Expand Down

0 comments on commit 624d873

Please sign in to comment.