Add INTERNAL_HOSTNAMES option
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 5 Mar 2021 15:48:05 +0000 (16:48 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 5 Mar 2021 15:48:05 +0000 (16:48 +0100)
Resolves #4049

com.woltlab.wcf/option.xml
constants.php
wcfsetup/install/files/lib/system/application/ApplicationHandler.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 82d256404e1b4b6cf9e1a649078940e9f819e8c7..f0fcb294af409d29a1d05677abd37c640140bed7 100644 (file)
                                <optiontype>boolean</optiontype>
                                <defaultvalue>1</defaultvalue>
                        </option>
+                       <option name="internal_hostnames">
+                               <categoryname>general.page</categoryname>
+                               <optiontype>textarea</optiontype>
+                       </option>
                        <option name="head_code">
                                <categoryname>general.page</categoryname>
                                <optiontype>textarea</optiontype>
@@ -1691,14 +1695,14 @@ DESC:wcf.global.sortOrder.descending</selectoptions>
                </options>
        </import>
        <delete>
-               <option name="http_enable_gzip" />
-               <option name="meta_keywords" />
-               <option name="register_admin_notification" />
-               <option name="session_timeout" />
-               <option name="session_validate_ip_address" />
-               <option name="session_validate_user_agent" />
-               <option name="session_enable_virtualization" />
-               <option name="blacklist_hostnames" />
-               <option name="module_user_cover_photo" />
+               <option name="http_enable_gzip"/>
+               <option name="meta_keywords"/>
+               <option name="register_admin_notification"/>
+               <option name="session_timeout"/>
+               <option name="session_validate_ip_address"/>
+               <option name="session_validate_user_agent"/>
+               <option name="session_enable_virtualization"/>
+               <option name="blacklist_hostnames"/>
+               <option name="module_user_cover_photo"/>
        </delete>
 </data>
index 7cd5e166f1a61fe954cbb8410816b321697c6f46..407d5a855c53ef6a3784a7e59bc618b4613972f2 100644 (file)
 \define('ENABLE_ENTERPRISE_MODE', 0);
 \define('MESSAGE_ENABLE_USER_CONSENT', 1);
 \define('MODIFICATION_LOG_EXPIRATION', 0);
+\define('INTERNAL_HOSTNAMES', '');
index 8d8e2f12e3c7aeed155b72e9ba37bda8616a78d2..9edd53986c5e9ba4e3a7a32a8f0928bebbee180d 100644 (file)
@@ -8,12 +8,14 @@ use wcf\data\application\ApplicationList;
 use wcf\data\package\Package;
 use wcf\data\package\PackageList;
 use wcf\system\cache\builder\ApplicationCacheBuilder;
-use wcf\system\Regex;
 use wcf\system\request\RequestHandler;
 use wcf\system\request\RouteHandler;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
+use wcf\util\ArrayUtil;
 use wcf\util\FileUtil;
+use wcf\util\StringUtil;
+use wcf\util\Url;
 
 /**
  * Handles multi-application environments.
@@ -207,30 +209,25 @@ class ApplicationHandler extends SingletonFactory
      */
     public function isInternalURL($url)
     {
-        $protocolRegex = new Regex('^https(?=://)');
         if (empty($this->pageURLs)) {
             foreach ($this->getApplications() as $application) {
-                $this->pageURLs[] = \preg_replace(
-                    '~/$~',
-                    '',
-                    $protocolRegex->replace(RouteHandler::getProtocol() . $application->domainName, 'http')
-                );
+                $this->pageURLs[] = $application->domainName;
             }
-            $this->pageURLs = \array_unique($this->pageURLs);
-        }
 
-        foreach ($this->pageURLs as $pageURL) {
-            if (\stripos($protocolRegex->replace($url, 'http'), $pageURL) === 0) {
-                return true;
-            }
+            $this->pageURLs = \array_unique(\array_merge(
+                $this->pageURLs,
+                ArrayUtil::trim(\explode("\n", StringUtil::unifyNewlines(\INTERNAL_HOSTNAMES)))
+            ));
         }
 
-        // relative urls contain no protocol, including implied
-        if (!\preg_match('~^([a-zA-Z0-9]+)?://~', $url)) {
+        $host = Url::parse($url)['host'];
+
+        // Relative URLs are internal.
+        if (!$host) {
             return true;
         }
 
-        return false;
+        return Url::getHostnameMatcher($this->pageURLs)($host);
     }
 
     /**
index c85cb570b395e409d25d7caf1c74d39bc6e4118f..3c003102f9e154204205ac1e0f25d679ed2c36da 100644 (file)
@@ -1783,6 +1783,8 @@ Die Datenbestände werden sorgfältig gepflegt, aber es ist nicht ausgeschlossen
                <item name="wcf.acp.option.message_enable_user_consent"><![CDATA[Inhalte von externen Anbietern erst nach Zustimmung anzeigen]]></item>
                <item name="wcf.acp.option.modification_log_expiration"><![CDATA[Speicherzeit für Änderungen]]></item>
                <item name="wcf.acp.option.modification_log_expiration.description"><![CDATA[Zeitraum, nachdem alte Änderungen aus dem Änderungsprotokoll entfernt werden [0, um die Entfernung gänzlich zu deaktivieren]]]></item>
+               <item name="wcf.acp.option.internal_hostnames"><![CDATA[Zusätzliche interne Domains]]></item>
+               <item name="wcf.acp.option.internal_hostnames.description"><![CDATA[Die aufgeführten Domains werden, neben den Domains der installierten Apps, als interne Domains angesehen. Der Abgleich erfolgt auf Basis der strikten Übereinstimmung, optional können Subdomains mit einem Platzhalter berücksichtigt werden: <kbd>*.example.com</kbd> umfasst sowohl <kbd>example.com</kbd> als auch Subdomains wie <kbd>foo.example.com</kbd> oder <kbd>www.example.com</kbd>.<br>Bitte nur eine Domain pro Zeile eingeben.]]></item>
        </category>
        <category name="wcf.acp.customOption">
                <item name="wcf.acp.customOption.list"><![CDATA[Eingabefelder]]></item>
index f64a148e0fda881d88584caefb1239ca1bd0b4f9..fb8915cd72f0e58b47a2d712504c406ffcd898b7 100644 (file)
@@ -1767,6 +1767,8 @@ The database is carefully maintained, but there will be always be a margin of er
                <item name="wcf.acp.option.message_enable_user_consent"><![CDATA[Prompt users before displaying content from external sources]]></item>
                <item name="wcf.acp.option.modification_log_expiration"><![CDATA[Storage Time for Modification Logs]]></item>
                <item name="wcf.acp.option.modification_log_expiration.description"><![CDATA[Modification logs will be deleted after the entered amount of days. To disable deleting old modification logs, enter “0”.]]></item>
+               <item name="wcf.acp.option.internal_hostnames"><![CDATA[Additional Internal Domains]]></item>
+               <item name="wcf.acp.option.internal_hostnames.description"><![CDATA[The listed domains will be considered as internal domains in addition to the domains in use by installed apps. Hostnames are exact matches only, a leading wildcard can be used to exclude an entire domain: <kbd>*.example.com</kbd> matches <kbd>example.com</kbd> and subdomains such as <kbd>foo.example.com</kbd> or <kbd>www.example.com</kbd>.<br>Enter one domain per line only.]]></item>
        </category>
        <category name="wcf.acp.customOption">
                <item name="wcf.acp.customOption.list"><![CDATA[Option Fields]]></item>