Improved cookie prefix handling in developer mode
authorAlexander Ebert <ebert@woltlab.com>
Thu, 30 Nov 2017 13:20:07 +0000 (14:20 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 30 Nov 2017 13:20:13 +0000 (14:20 +0100)
Closes #2488

extra/examples/wsc-dev-config-31.json
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php

index da5cdd9881a8966f9c55968f8a704fff3c186286..605aa81ebf8de8dbcfb5fcc1a6a1a4a11e9771a9 100644 (file)
@@ -7,7 +7,8 @@
             "username": "root",
             "dbNumber": "2"
         },
-        "useDefaultInstallPath": true
+        "useDefaultInstallPath": true,
+        "forceStaticCookiePrefix": true
     },
     "configuration": {
         "option": {
index f83fd2bd7288b882b8bb34862289008a45193c68..8c5429e3d0e33ff38f1d51893d101ab8177e4c53 100644 (file)
@@ -1220,9 +1220,14 @@ class WCFSetup extends WCF {
                        ]);
                }
                
-               // determine randomized cookie prefix
+               // determine the (randomized) cookie prefix
+               $useRandomCookiePrefix = true;
+               if (self::$developerMode && DevtoolsSetup::getInstance()->forceStaticCookiePrefix()) {
+                       $useRandomCookiePrefix = false;
+               }
+               
                $prefix = 'wsc31_';
-               if (!self::$developerMode) {
+               if ($useRandomCookiePrefix) {
                        $cookieNames = array_keys($_COOKIE);
                        while (true) {
                                $prefix = 'wsc_' . substr(sha1(mt_rand()), 0, 6) . '_';
index 22a2065d77a9d97aadbb9d038f11f03ebc9681b7..1860e6a65c8737cb26b4ef73cf97ee24010613ff 100644 (file)
@@ -79,6 +79,16 @@ class DevtoolsSetup extends SingletonFactory {
                return (isset($this->configuration['setup']) && isset($this->configuration['setup']['useDefaultInstallPath']) && $this->configuration['setup']['useDefaultInstallPath'] === true);
        }
        
+       /**
+        * Returns true if a static cookie prefix should be used, instead of the randomized
+        * value used for non-dev-mode installations.
+        * 
+        * @return      boolean
+        */
+       public function forceStaticCookiePrefix() {
+               return (isset($this->configuration['setup']) && isset($this->configuration['setup']['forceStaticCookiePrefix']) && $this->configuration['setup']['forceStaticCookiePrefix'] === true);
+       }
+       
        /**
         * List of option values that will be set after the setup has completed.
         * 
@@ -87,6 +97,10 @@ class DevtoolsSetup extends SingletonFactory {
        public function getOptionOverrides() {
                if (!isset($this->configuration['configuration']) || empty($this->configuration['configuration']['option'])) return [];
                
+               if (isset($this->configuration['configuration']['option']['cookie_prefix'])) {
+                       throw new \DomainException("The 'cookie_prefix' option cannot be set during the setup, consider using the 'forceStaticCookiePrefix' setting instead.");
+               }
+               
                return $this->configuration['configuration']['option'];
        }