Skip to content

Commit 624d873

Browse files
committed
block json mass assignment
1 parent 5dfafef commit 624d873

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public function isFillable($key)
163163
*/
164164
public function isGuarded($key)
165165
{
166+
if (strpos($key, '->')) {
167+
$key = Str::before($key, '->');
168+
}
169+
166170
return $this->getGuarded() == ['*'] || ! empty(preg_grep('/^'.preg_quote($key).'$/i', $this->getGuarded()));
167171
}
168172

tests/Integration/Database/EloquentModelTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public function testCantUpdateGuardedAttributesUsingDifferentCasing()
3838
$this->assertNull($model->ID);
3939
}
4040

41+
public function testCantUpdateGuardedAttributeUsingJson()
42+
{
43+
$model = new TestModel2;
44+
45+
$model->fill(['id->foo' => 123]);
46+
47+
$this->assertNull($model->id);
48+
}
49+
4150
public function testUserCanUpdateNullableDate()
4251
{
4352
$user = TestModel1::create([

0 commit comments

Comments
 (0)