Skip to content

Commit b1023f2

Browse files
committed
πŸ”’ Block visitor-supplied [html_snippet] and enforce integer snippet IDs
- πŸ›‘οΈ Strip [html_snippet] from visitor messages in addmsguser.php since [html] and [html_snippet] are system/operator only bbcodes - βœ… Validate extracted html_snippet meta in lhbbcode.php and lhbbcode_cleanup.php: reject empty/non-numeric values and cast to int - 🧱 Prevent visitor message content from being treated as a canned snippet reference - πŸ’‰ Cast msg and canned message IDs to int in html_snippet.tpl.php to harden the client-side sendHTML call against injection
1 parent cb0778f commit b1023f2

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php foreach ($metaMessage as $messageCanned) : ?>
2-
<script>lhinst.sendHTML(<?php echo $msg['id']?>,{'type':'msg','id':<?php echo $messageCanned?>});</script>
2+
<script>lhinst.sendHTML(<?php echo (int)$msg['id']?>,{'type':'msg','id':<?php echo (int)$messageCanned?>});</script>
33
<?php endforeach; ?>

β€Žlhc_web/lib/core/lhbbcode/lhbbcode.phpβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,8 +1130,14 @@ public static function extractMetaByMessage(& $msg) {
11301130
$matches = array();
11311131
preg_match_all('/\[html_snippet\](.*?)\[\/html_snippet\]/is',$msg,$matches);
11321132
foreach ($matches[0] as $index => $match) {
1133+
// Only a canned message id is a valid html_snippet reference. Anything else
1134+
// (e.g. a visitor supplied message) must never be treated as a snippet.
1135+
$messageCanned = trim($matches[1][$index]);
1136+
if ($messageCanned === '' || !ctype_digit($messageCanned)) {
1137+
continue;
1138+
}
11331139
$msg = str_replace($match,'',$msg);
1134-
$meta['html_snippet'][] = $matches[1][$index];
1140+
$meta['html_snippet'][] = (int)$messageCanned;
11351141
}
11361142
}
11371143
return $meta;

β€Žlhc_web/lib/core/lhbbcode/lhbbcode_cleanup.phpβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,14 @@ public static function extractMetaByMessage(& $msg) {
979979
$matches = array();
980980
preg_match_all('/\[html_snippet\](.*?)\[\/html_snippet\]/is',$msg,$matches);
981981
foreach ($matches[0] as $index => $match) {
982+
// Only a canned message id is a valid html_snippet reference. Anything else
983+
// (e.g. a visitor supplied message) must never be treated as a snippet.
984+
$messageCanned = trim($matches[1][$index]);
985+
if ($messageCanned === '' || !ctype_digit($messageCanned)) {
986+
continue;
987+
}
982988
$msg = str_replace($match,'',$msg);
983-
$meta['html_snippet'][] = $matches[1][$index];
989+
$meta['html_snippet'][] = (int)$messageCanned;
984990
}
985991
}
986992
return $meta;

β€Žlhc_web/modules/lhchat/addmsguser.phpβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
if ($chat->hash == $Params['user_parameters']['hash'] && (in_array($chat->status,$validStatuses)) && !in_array($chat->status_sub, array(erLhcoreClassModelChat::STATUS_SUB_SURVEY_COMPLETED, erLhcoreClassModelChat::STATUS_SUB_USER_CLOSED_CHAT, erLhcoreClassModelChat::STATUS_SUB_SURVEY_SHOW, erLhcoreClassModelChat::STATUS_SUB_CONTACT_FORM))) // Allow add messages only if chat is active
3636
{
3737

38-
$msgText = preg_replace('/\[html\](.*?)\[\/html\]/ms','',$form->msg);
38+
// [html] and [html_snippet] are system/operator bbcodes and must never be accepted from a visitor
39+
$msgText = preg_replace(array('/\[html\](.*?)\[\/html\]/ms','/\[html_snippet\](.*?)\[\/html_snippet\]/is'),'',$form->msg);
3940

4041
$messagesToStore = explode('[[msgitm]]', trim($msgText));
4142

0 commit comments

Comments
Β (0)