Skip to content

Commit

Permalink
security: Inline Image
Browse files Browse the repository at this point in the history
This addresses an issue where we needed to harden inline image regex and
localize the inline images before sanitizing.
  • Loading branch information
JediKev committed Oct 25, 2023
1 parent 88a87a3 commit c4ad48d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/class.format.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,17 @@ static function safe_html($html, $options=array()) {
static function localizeInlineImages($text) {
// Change file.php urls back to content-id's
return preg_replace(
'`src="(?:https?:/)?(?:/[^/"]+)*?/file\\.php\\?(?:\w+=[^&]+&(?:amp;)?)*?key=([^&]+)[^"]*`',
'src="cid:$1', $text);
'`<img src="(?:https?:/)?(?:/[^/"]+)*?/file\\.php\\?(?:\w+=[^&"]+&(?:amp;)?)*?key=([^&]+)[^"]*`',
'<img src="cid:$1', $text);
}

static function sanitize($text, $striptags=false, $spec=false) {
// Localize inline images before sanitizing content
$text = self::localizeInlineImages($text);

//balance and neutralize unsafe tags.
$text = Format::safe_html($text, array('spec' => $spec));

$text = self::localizeInlineImages($text);

//If requested - strip tags with decoding disabled.
return $striptags?Format::striptags($text, false):$text;
}
Expand Down

0 comments on commit c4ad48d

Please sign in to comment.