Skip to content

Commit

Permalink
[SECURITY] Explicitly deny object deserialization
Browse files Browse the repository at this point in the history
Resolves: #85385
Releases: master, 8.7, 7.6
Security-Commit: f4d645d131fabc98cbbdcefcffb951040d2dd246
Security-Bulletin: TYPO3-CORE-SA-2018-002
Change-Id: Ia138f22856c7dd754e373803af799273868c622b
Reviewed-on: https://review.typo3.org/57560
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
  • Loading branch information
ohader committed Jul 12, 2018
1 parent 421ef42 commit b6a04a1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
14 changes: 14 additions & 0 deletions typo3/sysext/rsaauth/Classes/Backend/CommandLineBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public function __construct()
}
}

/**
* 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).
*
Expand Down
46 changes: 43 additions & 3 deletions typo3/sysext/rsaauth/Tests/Unit/Backend/CommandLineBackendTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
declare(strict_types = 1);

namespace TYPO3\CMS\Rsaauth\Tests\Unit\Backend;

/*
Expand Down Expand Up @@ -34,9 +35,6 @@ class CommandLineBackendTest extends UnitTestCase
*/
protected function setUp()
{
if (Environment::isWindows()) {
$this->markTestSkipped('This test is not available on Windows as auto-detection of openssl path will fail.');
}
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['rsaauth']['temporaryDirectory'] = '';
}

Expand All @@ -45,6 +43,7 @@ protected function setUp()
*/
public function createNewKeyPairCreatesReadyKeyPair()
{
$this->skipIfWindows();
$subject = new CommandLineBackend();
$keyPair = $subject->createNewKeyPair();
if ($keyPair === null) {
Expand All @@ -59,6 +58,7 @@ public function createNewKeyPairCreatesReadyKeyPair()
*/
public function createNewKeyPairCreatesKeyPairWithDefaultExponent()
{
$this->skipIfWindows();
$subject = new CommandLineBackend();
$keyPair = $subject->createNewKeyPair();
if ($keyPair === null) {
Expand All @@ -76,10 +76,50 @@ public function createNewKeyPairCreatesKeyPairWithDefaultExponent()
*/
public function createNewKeyPairCalledTwoTimesReturnsSameKeyPairInstance()
{
$this->skipIfWindows();
$subject = new CommandLineBackend();
$this->assertSame(
$subject->createNewKeyPair(),
$subject->createNewKeyPair()
);
}

/**
* @test
*/
public function doesNotAllowUnserialization(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionCode(1531336156);

$subject = new CommandLineBackend();
$serialized = serialize($subject);
unserialize($serialized);
}

/**
* @test
*/
public function unsetsPathsOnUnserialization(): void
{
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(): void
{
if (Environment::isWindows()) {
$this->markTestSkipped(
'This test is not available on Windows as auto-detection of openssl path will fail.'
);
}
}
}

0 comments on commit b6a04a1

Please sign in to comment.