Skip to content

Commit 321c711

Browse files
committed
Ensured sensitive properties like $slot and $_attributes are no longer public
Previously, the $slot and $_attributes properties were public and thus appeared in the `wire:snapshot` directive in livewire components. This is obviously a security risk, so this commits creates a workaround to ensure that is no longer the case, while still maintaining previous functionality
1 parent 50fbdd7 commit 321c711

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

resources/views/components/livewire.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
:component="$attributes->get('_')"
44
:slot="serialize($slot)"
55
:laravel-slots="serialize($__laravel_slots)"
6-
:attributes="serialize($attributes)"
6+
:_attributes="serialize($attributes)"
77
/>
88

99

src/Components/XLivewireBaseComponent.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ class XLivewireBaseComponent extends Component
99
{
1010

1111
public string $slot;
12-
public string $attributes;
12+
protected string $_slot = '';
13+
14+
public string $_attributes;
15+
protected string $__attributes = '';
1316

1417

1518
/**
@@ -20,20 +23,21 @@ class XLivewireBaseComponent extends Component
2023
* @var string
2124
*/
2225
public string $laravelSlots;
26+
protected string $_laravelSlots = '';
2327

2428
public function slot()
2529
{
26-
return unserialize($this->slot);
30+
return unserialize($this->_slot);
2731
}
2832

2933
public function attributes()
3034
{
31-
return unserialize($this->attributes);
35+
return unserialize($this->__attributes);
3236
}
3337

3438
public function laravelSlots()
3539
{
36-
return unserialize($this->laravelSlots);
40+
return unserialize($this->_laravelSlots);
3741
}
3842

3943

@@ -67,9 +71,15 @@ public function mount(){
6771
*/
6872
public function setProps(): void
6973
{
74+
$this->__attributes = $this->_attributes;
75+
$this->_slot = $this->slot;
76+
$this->_laravelSlots = $this->laravelSlots;
77+
78+
$attributes = $this->attributes();//->getAttributes();
79+
7080
// The collection of all attributes that were set in the x-livewire tag.
7181
// We name it this way to avoid conflicts with the component's actual $attributes property.
72-
$this->attributesCollection = collect($this->attributes());
82+
$this->attributesCollection = collect($attributes);
7383

7484
// Get a collection of the names of all the public properties.
7585
$r_object = new \ReflectionObject($this);
@@ -101,6 +111,9 @@ public function setProps(): void
101111
}
102112
}
103113

114+
// To hide all these properties from the frontend, we unset them.
115+
unset($this->_attributes, $this->laravelSlots, $this->slot);
116+
104117

105118
}
106119

0 commit comments

Comments
 (0)