Skip to content

Commit

Permalink
Merge pull request #146 from NathanaelGT/prevent-xss-attack
Browse files Browse the repository at this point in the history
Prevent xss attack
  • Loading branch information
luanfreitasdev authored Nov 24, 2021
2 parents f5d0436 + 29ccabc commit 68e5075
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions resources/views/assets/scripts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ function copyToClipboard(button) {
document.body.removeChild(el);
}
function htmlSpecialChars(string) {
const el = document.createElement('div');
el.innerText = string;
return el.innerHTML;
}
function isV2() {
return window.Alpine && window.Alpine.version && /^2\..+\..+$/.test(window.Alpine.version)
}
Expand Down
6 changes: 3 additions & 3 deletions resources/views/components/editable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
field: '{{ $field }}',
content: '{{ addslashes($row->{$field}) }}'
}">
<div x-text="content"
<div x-html="content"
style="border-bottom: dotted 1px; cursor: pointer"
x-show="!editable"
x-on:dblclick="editable = true"
Expand All @@ -22,12 +22,12 @@
<input
type="text"
x-on:dblclick="editable = true"
x-on:keydown.enter="sendEventInputChanged($event, id, field); editable = false; content = $event.target.value"
x-on:keydown.enter="sendEventInputChanged($event, id, field); editable = false; content = htmlSpecialChars($event.target.value)"
:class="{'cursor-pointer': !editable}"
class="{{ $theme->inputClass }} p-2"
x-ref="editable"
x-text="content"
:value="content">
:value="$root.firstElementChild.innerText">
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/PowerGridEloquent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function eloquent(): PowerGridEloquent
*/
public function addColumn(string $field, Closure $closure = null): PowerGridEloquent
{
$this->columns[$field] = $closure ?? fn ($model) => $model->{$field};
$this->columns[$field] = $closure ?? fn ($model) => e($model->{$field});

return $this;
}
Expand Down

0 comments on commit 68e5075

Please sign in to comment.