Strip port from cookie domain
authorAlexander Ebert <ebert@woltlab.com>
Thu, 28 Sep 2017 11:18:29 +0000 (13:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 15 Nov 2017 16:22:07 +0000 (17:22 +0100)
Cookies are set per host regardless of the domain as per RFC 6265

wcfsetup/install/files/lib/util/HeaderUtil.class.php

index 955450cf8d2ff6e2e785e3f13b48e771e6756ad7..f414d9e87fa68ddd901eb03bb9880fe6ff51a00e 100644 (file)
@@ -43,8 +43,12 @@ final class HeaderUtil {
        public static function setCookie($name, $value = '', $expire = 0) {
                $application = ApplicationHandler::getInstance()->getActiveApplication();
                $addDomain = (mb_strpos($application->cookieDomain, '.') === false || StringUtil::endsWith($application->cookieDomain, '.lan') || StringUtil::endsWith($application->cookieDomain, '.local')) ? false : true;
+               $cookieDomain = $application->cookieDomain;
+               if ($addDomain && strpos($cookieDomain, ':') !== false) {
+                       $cookieDomain = explode(':', $cookieDomain, 2)[0];
+               }
                
-               @header('Set-Cookie: '.rawurlencode(COOKIE_PREFIX.$name).'='.rawurlencode($value).($expire ? '; expires='.gmdate('D, d-M-Y H:i:s', $expire).' GMT; max-age='.($expire - TIME_NOW) : '').'; path=/'.($addDomain ? '; domain='.$application->cookieDomain : '').(RouteHandler::secureConnection() ? '; secure' : '').'; HttpOnly', false);
+               @header('Set-Cookie: '.rawurlencode(COOKIE_PREFIX.$name).'='.rawurlencode($value).($expire ? '; expires='.gmdate('D, d-M-Y H:i:s', $expire).' GMT; max-age='.($expire - TIME_NOW) : '').'; path=/'.($addDomain ? '; domain='.$cookieDomain : '').(RouteHandler::secureConnection() ? '; secure' : '').'; HttpOnly', false);
        }
        
        /**