Skip to content

Commit

Permalink
Prevent XSS in image alt/title
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdenotter committed Aug 15, 2019
1 parent 1ef6237 commit 2634a56
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Helpers/Image/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Bolt\Helpers\Image;

use Bolt\Helpers\Str;

/**
* Thumbnail helper class.
*
Expand Down Expand Up @@ -73,10 +75,10 @@ public function setFileName($fileName)
public function getTitle()
{
if ($this->title) {
return $this->title;
return $this->sanitize($this->title);
}

return $this->altTitle;
return $this->sanitize($this->altTitle);
}

/**
Expand All @@ -101,10 +103,10 @@ public function setTitle($title)
public function getAltTitle()
{
if ($this->altTitle) {
return $this->altTitle;
return $this->sanitize($this->altTitle);
}

return $this->title;
return $this->sanitize($this->title);
}

/**
Expand Down Expand Up @@ -222,4 +224,9 @@ public function setScale($scale)

return $this;
}

private function sanitize($str)
{
return Str::makeSafe($str, false, '()[]!@$%&*~`^-_=+{},.~<>:; /?');
}
}

0 comments on commit 2634a56

Please sign in to comment.