fix: only linkify http and https URIs on the error page

escapeButPreserveUris() matched the scheme with "[A-z]+?://", which accepts
any scheme. A frame comment containing javascript://x.co/?%0Aalert(1) survives
htmlspecialchars() untouched and was then wrapped in an anchor, so clicking it
executed script in the origin of the error page. "[A-z]" is also a code point
range rather than a letter class, so it additionally matched the six characters
between "Z" and "a", making "_://x.co/a" a link too.

Match the scheme with "https?" instead, case-insensitively so uppercase
"HTTP://" keeps working. Other schemes stay as escaped plain text. The editor
integration links are not affected, they are emitted directly by the template
and never pass through this method.

Fixes #791
This commit is contained in:
dualfroz committed 2026-09-03 14:14:10 +02:00
1 parent 238f0d6b9a
commit 8652196c72
2 files changed
+48 -1

No files matched your search

+5 -1
View File
@@ -80,6 +80,10 @@ class TemplateHelper
* Escapes a string for output in an HTML document, but preserves
* URIs within it, and converts them to clickable anchor elements.
*
* Only http and https URIs are turned into links. Any other scheme is left as
* plain text, because schemes such as javascript: and data: would otherwise
* become clickable script execution on the error page.
*
* @param string $raw
* @return string
*/
@@ -87,7 +91,7 @@ class TemplateHelper
{
$escaped = $this->escape($raw);
return preg_replace(
"@([A-z]+?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@",
"@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@i",
"<a href=\"$1\" target=\"_blank\" rel=\"noreferrer noopener\">$1</a>",
$escaped
);