// WoltLab modification: prevent catastrophic backtracing
var pattern = '((xn--)?[\\W\\w\\D\\d]+(-(?!-[\\W\\w\\D\\d])+)*\\.)+[\\W\\w]{2,}';
- // WoltLab modification: added `ts3server`
- var re1 = new RegExp('^(http|ftp|https|ts3server)://' + pattern, 'i');
+ // WoltLab modification: added `steam` and `ts3server`
+ var re1 = new RegExp('^(http|ftp|https|steam|ts3server)://' + pattern, 'i');
var re2 = new RegExp('^' + pattern, 'i');
var re3 = new RegExp('\.(html|php)$', 'i');
var re4 = new RegExp('^/', 'i');
--- /dev/null
+<?php
+// @codingStandardsIgnoreFile
+/**
+ * Steam direct join protocol
+ */
+class HTMLPurifier_URIScheme_steam extends HTMLPurifier_URIScheme
+{
+ /**
+ * @param HTMLPurifier_URI $uri
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool
+ */
+ public function doValidate(&$uri, $config, $context)
+ {
+ $uri->userinfo = null;
+
+ return true;
+ }
+}
+
+// vim: et sw=4 sts=4
*/
protected function getPurifier() {
if (self::$purifier === null) {
+ require_once(WCF_DIR . 'lib/system/html/input/filter/HTMLPurifier_URIScheme_steam.php');
require_once(WCF_DIR . 'lib/system/html/input/filter/HTMLPurifier_URIScheme_ts3server.php');
$config = \HTMLPurifier_Config::createDefault();
$config->set('HTML.ForbiddenAttributes', ['*@lang', '*@xml:lang']);
$allowedSchemes = $config->get('URI.AllowedSchemes');
+ $allowedSchemes['steam'] = true;
$allowedSchemes['ts3server'] = true;
$config->set('URI.AllowedSchemes', $allowedSchemes);
* @since 3.0
*/
class UrlMetacodeConverter extends AbstractMetacodeConverter {
+ /**
+ * list of allowed schemas as defined by HTMLPurifier
+ * @var string[]
+ */
+ public static $allowedSchemes = ['http', 'https', 'mailto', 'ftp', 'nntp', 'news', 'tel', 'steam', 'ts3server'];
+
/**
* @inheritDoc
*/
}
$href = StringUtil::decodeHTML($href);
+ if (mb_strpos($href, '//') === 0) {
+ // dynamic protocol, treat as https
+ $href = "https:{$href}";
+ }
+ else if (preg_match('~^(?P<schema>[a-z0-9]+)://~', $href, $match)) {
+ if (!in_array($match['schema'], self::$allowedSchemes)) {
+ // invalid schema, replace it with `http`
+ $href = 'http' . mb_substr($href, strlen($match['schema']));
+ }
+ }
+ else if (mb_strpos($href, 'index.php') === false) {
+ // unless it's a relative `index.php` link, assume it is missing the protocol
+ $href = "http://{$href}";
+ }
// check if the link is empty, use the href value instead
$useHrefAsValue = false;