If the relocation placeholder appeared multiple times within the source code,
it would also be replaced multiple times. This might allow an attacker to blow
up the HTML structure by including the placeholder within UGC.
Fix this issue by only ever replacing the last placeholder, which should be the
“real” one from footer.tpl. In the future this should be protected further by
including a random nonce to prevent this attack entirely.
return '';
}, self::$output);
- self::$output = str_replace('<!-- JAVASCRIPT_RELOCATE_POSITION -->', implode("\n", $javascript), self::$output);
+ $placeholder = '<!-- JAVASCRIPT_RELOCATE_POSITION -->';
+ if (($placeholderPosition = \strrpos(self::$output, $placeholder)) !== false) {
+ self::$output = \substr(self::$output, 0, $placeholderPosition)
+ . \implode("\n", $javascript)
+ . \substr(self::$output, $placeholderPosition + \strlen($placeholder));
+ }
// 3rd party plugins may differ the actual output before it is sent to the browser
// please be aware, that $eventObj is not available here due to this being a static