[SECURITY] Explicitly deny object deserialization 42/57542/2
authorOliver Hader <oliver@typo3.org>
Thu, 12 Jul 2018 09:31:33 +0000 (11:31 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 12 Jul 2018 09:31:36 +0000 (11:31 +0200)
Resolves: #85385
Releases: master, 8.7, 7.6
Security-Commit: 8cd7fa85f5b60c508aaac3184101008ba2e8df7f
Security-Bulletin: TYPO3-CORE-SA-2018-002
Change-Id: I2494702e67a180fff36173645b8478a12680b870
Reviewed-on: https://review.typo3.org/57542
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/rsaauth/Classes/Backend/CommandLineBackend.php
typo3/sysext/rsaauth/Tests/Unit/Backend/CommandLineBackendTest.php

index 6a63a1a..4839ca1 100644 (file)
@@ -67,6 +67,20 @@ class CommandLineBackend extends AbstractBackend
     }
 
     /**
+     * Denies deserialization.
+     */
+    public function __wakeup()
+    {
+        $this->opensslPath = null;
+        $this->temporaryDirectory = null;
+
+        throw new \RuntimeException(
+            __CLASS__ . ' cannot be unserialized',
+            1531336156
+        );
+    }
+
+    /**
      * Creates a new key pair for the encryption or gets the existing key pair (if one already has been generated).
      *
      * There should only be one key pair per request because the second private key would overwrites the first private
index de3170d..a982ca0 100644 (file)
@@ -28,10 +28,6 @@ class CommandLineBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     protected function setUp()
     {
-        if (TYPO3_OS === 'WIN') {
-            $this->markTestSkipped('This test is not available on Windows.');
-        }
-
         $this->subject = new CommandLineBackend();
     }
 
@@ -40,6 +36,7 @@ class CommandLineBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function createNewKeyPairCreatesReadyKeyPair()
     {
+        $this->skipIfWindows();
         $keyPair = $this->subject->createNewKeyPair();
         if ($keyPair === null) {
             $this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
@@ -53,6 +50,7 @@ class CommandLineBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function createNewKeyPairCreatesKeyPairWithDefaultExponent()
     {
+        $this->skipIfWindows();
         $keyPair = $this->subject->createNewKeyPair();
         if ($keyPair === null) {
             $this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
@@ -69,9 +67,48 @@ class CommandLineBackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function createNewKeyPairCalledTwoTimesReturnsSameKeyPairInstance()
     {
+        $this->skipIfWindows();
         $this->assertSame(
             $this->subject->createNewKeyPair(),
             $this->subject->createNewKeyPair()
         );
     }
+
+    /**
+     * @test
+     */
+    public function doesNotAllowUnserialization()
+    {
+        $this->setExpectedException(\RuntimeException::class, '', 1531336156);
+
+        $subject = new CommandLineBackend();
+        $serialized = serialize($subject);
+        unserialize($serialized);
+    }
+
+    /**
+     * @test
+     */
+    public function unsetsPathsOnUnserialization()
+    {
+        try {
+            $subject = $this->getAccessibleMock(CommandLineBackend::class);
+            $subject->_set('opensslPath', 'foo');
+            $subject->_set('temporaryDirectory', 'foo');
+            $serialized = serialize($subject);
+            unserialize($serialized);
+        } catch (\RuntimeException $e) {
+            $this->assertNull($subject->_get('opensslPath'));
+            $this->assertNull($subject->_get('temporaryDirectory'));
+        }
+    }
+
+    protected function skipIfWindows()
+    {
+        if (TYPO3_OS === 'WIN') {
+            $this->markTestSkipped(
+                'This test is not available on Windows as auto-detection of openssl path will fail.'
+            );
+        }
+    }
 }