Skip to content

Commit ee60faf

Browse files
committed
feat(other): add HTML email sanitizer to remove external background images
1 parent 7596eb2 commit ee60faf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

modules/core/message_functions.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ function format_msg_html($str, $images=false) {
4545
}
4646
}}
4747

48+
/**
49+
* Sanitize HTML for email
50+
* @subpackage core/functions
51+
* @param string $html content to sanitize
52+
* @return string
53+
*/
54+
if (!hm_exists('sanitize_email_html')) {
55+
function sanitize_email_html($html) {
56+
$html = preg_replace('/<([^>]+)style\s*=\s*["\'][^"\']*background-image\s*:\s*url\((["\']?)https?:\/\/.*?\2\)[^"\']*["\']/i', '<$1', $html);
57+
58+
return $html;
59+
}}
60+
4861
/**
4962
* Convert HTML to plain text
5063
* @param string $html content to convert

modules/imap/output_modules.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ protected function output() {
126126
}
127127
}
128128

129+
$msgText = sanitize_email_html($msgText);
129130
$txt .= format_msg_html($msgText, $allowed);
130131
}
131132
elseif (isset($struct['type']) && mb_strtolower($struct['type']) == 'image') {
@@ -1677,7 +1678,7 @@ protected function output() {
16771678
$ceo_rate_limit = $settings['ceo_rate_limit'];
16781679
}
16791680
}
1680-
1681+
16811682
$res = '<tr class="general_setting"><td><label for="ceo_use_detect_ceo_fraud">'.
16821683
$this->trans('CEO fraud: Use Detect CEO Fraud').
16831684
'</label></td><td><input class="form-check-input" type="checkbox" role="switch" id="ceo_use_detect_ceo_fraud" name="ceo_use_detect_ceo_fraud" '. $ceo_use_detect_ceo_fraud .' ></td></tr>';

0 commit comments

Comments
 (0)