Skip to content

Commit

Permalink
[BUGFIX] Check extension version number format
Browse files Browse the repository at this point in the history
A false check in the TER API allowed to use
arbitrary version strings, as soon as they start
with the known `XXX.XXX.XXX` schema. This
will be fixed in TER API. However, core as receiver
should also validate the incoming data, before
storing them in the database.

Therefore, the same version number check,
which is used in the TER API, is now also
applied in the ExtensionXmlParser.

Resolves: #96209
Releases: main, 11.5, 10.4
Change-Id: I487eed34c6b25a5e3841d5263b52b9a73aaf681a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72484
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
  • Loading branch information
o-ba committed Dec 3, 2021
1 parent 473410a commit 3062df7
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
Expand Up @@ -230,6 +230,10 @@ protected function loadIntoDatabase(AbstractExtensionXmlParser &$subject)
);
$this->arrRows = [];
}
if (!$subject->isValidVersionNumber()) {
// Skip in case extension version is not valid
return;
}
$versionRepresentations = VersionNumberUtility::convertVersionStringToArray($subject->getVersion());
// order must match that of self::$fieldNames!
$this->arrRows[] = [
Expand Down
Expand Up @@ -368,6 +368,15 @@ public function getVersion()
return $this->version;
}

/**
* Whether the current version number is valid
*/
public function isValidVersionNumber(): bool
{
// Validate the version number, see `isValidVersionNumber` in TER API
return (bool)preg_match('/^(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})$/', $this->version);
}

/**
* @return string
*/
Expand Down
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\Parser;

use TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class ExtensionXmlPullParserTest extends UnitTestCase
{
/**
* @test
* @dataProvider isValidVersionNumberDataProvider
*/
public function isValidVersionNumber(string $versionNumber, bool $isValid): void
{
$subject = $this->getAccessibleMock(ExtensionXmlPullParser::class, ['dummy']);
$subject->_set('version', $versionNumber);

self::assertEquals($isValid, $subject->isValidVersionNumber());
}

public function isValidVersionNumberDataProvider(): \Generator
{
yield 'Successive zeros are not allowed' => [
'00.2.3',
false,
];
yield 'Version premodifiers are not allowed' => [
'v11.2.3',
false,
];
yield 'Version postmodifiers are not allowed' => [
'11.2.3-pre-release',
false,
];
yield 'Characters are not allowed in general' => [
'11.a.3',
false,
];
yield 'More than three characters are not allowed' => [
'11.2.3999',
false,
];
yield 'Version most use three segements (major, minor, patch)' => [
'11.2',
false,
];
yield 'Successive separators are not allowed' => [
'11..2',
false,
];
yield 'Leading separator is not allowed' => [
'.11.2',
false,
];
yield 'Invalid separator' => [
'11-2-3',
false,
];
yield 'Missing separator' => [
'1123',
false,
];
yield 'Valid version number' => [
'11.2.3',
true,
];
}
}

0 comments on commit 3062df7

Please sign in to comment.