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: 6a294ad6b15677b41b90d93ad8690b92048404fe
Security-Bulletin: TYPO3-CORE-SA-2018-002
Change-Id: I710a0b7d6bfdb425380aebe3cbd7f88e73eb6b21
Reviewed-on: https://review.typo3.org/57546
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 844c6f4 commit 0b0ba0f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 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 @@ -67,6 +67,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: 42 additions & 4 deletions typo3/sysext/rsaauth/Tests/Unit/Backend/CommandLineBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class CommandLineBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC

protected function setUp()
{
if (TYPO3_OS === 'WIN') {
$this->markTestSkipped('This test is not available on Windows as auto-detection of openssl path will fail.');
}

$this->subject = new CommandLineBackend();
}

Expand All @@ -40,6 +36,7 @@ protected function setUp()
*/
public function createNewKeyPairCreatesReadyKeyPair()
{
$this->skipIfWindows();
$keyPair = $this->subject->createNewKeyPair();
if ($keyPair === null) {
$this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
Expand All @@ -53,6 +50,7 @@ public function createNewKeyPairCreatesReadyKeyPair()
*/
public function createNewKeyPairCreatesKeyPairWithDefaultExponent()
{
$this->skipIfWindows();
$keyPair = $this->subject->createNewKeyPair();
if ($keyPair === null) {
$this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
Expand All @@ -69,9 +67,49 @@ public function createNewKeyPairCreatesKeyPairWithDefaultExponent()
*/
public function createNewKeyPairCalledTwoTimesReturnsSameKeyPairInstance()
{
$this->skipIfWindows();
$this->assertSame(
$this->subject->createNewKeyPair(),
$this->subject->createNewKeyPair()
);
}

/**
* @test
*/
public function doesNotAllowUnserialization()
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionCode(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.'
);
}
}
}

0 comments on commit 0b0ba0f

Please sign in to comment.