Skip to content

Commit

Permalink
修复json()方法可能导致的xss攻击
Browse files Browse the repository at this point in the history
  • Loading branch information
PorygonCN committed Oct 24, 2024
1 parent fc66b3a commit 179977d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Show/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,13 @@ public function json()

return $this->unescape()->as(function ($value) use ($field) {
$content = is_string($value) ? json_decode($value, true) : $value;

if (is_array($content)) {
array_walk($content, function (&$v, $k) {
$v = htmlspecialchars($v);
});
} else {
$content = htmlspecialchars($content);
}
$field->wrap(false);

return Dump::make($content);
Expand Down

0 comments on commit 179977d

Please sign in to comment.