Skip to content

Commit 892fb87

Browse files
committed
[SECURITY] Enforce page access in the backend module
It was possible to access mails via powermail modules, where an editor had no page permissions. This commit adds an additional check to prevent this.
1 parent 071b1fe commit 892fb87

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

‎Classes/Controller/ModuleController.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use In2code\Powermail\Domain\Model\Answer;
66
use In2code\Powermail\Domain\Model\Mail;
77
use In2code\Powermail\Domain\Repository\PageRepository;
8+
use In2code\Powermail\Exception\NoPageAccessException;
89
use In2code\Powermail\Utility\BackendUtility;
910
use In2code\Powermail\Utility\BasicFileUtility;
1011
use In2code\Powermail\Utility\ConfigurationUtility;
@@ -25,6 +26,23 @@
2526
class ModuleController extends AbstractController
2627
{
2728

29+
/**
30+
* Enforce the page access of the current backend user before any action of this module reads records
31+
* of the given page. The check is done on the same value ($this->id) that all actions are working
32+
* with, so it can not be circumvented with a non canonical page identifier (e.g. "09002") or by
33+
* sending the identifier via POST only - see BackendUtility::isPageAccessGranted()
34+
*
35+
* @return void
36+
* @throws NoPageAccessException
37+
*/
38+
protected function initializeAction(): void
39+
{
40+
parent::initializeAction();
41+
if ($this->id > 0 && !BackendUtility::isPageAccessGranted($this->id)) {
42+
throw new NoPageAccessException('You don\'t have access to this page', 1755000000);
43+
}
44+
}
45+
2846
/**
2947
* @param string $forwardToAction
3048
* @throws StopActionException
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
declare(strict_types = 1);
3+
namespace In2code\Powermail\Exception;
4+
5+
use TYPO3\CMS\Core\Error\Http\ForbiddenException;
6+
7+
/**
8+
* Class NoPageAccessException
9+
* Thrown if a backend user requests a page in the backend module that she/he is not allowed to access
10+
*/
11+
class NoPageAccessException extends ForbiddenException
12+
{
13+
}

‎Classes/Utility/BackendUtility.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use TYPO3\CMS\Backend\Routing\UriBuilder;
1111
use TYPO3\CMS\Backend\Utility\BackendUtility as BackendUtilityCore;
1212
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
13+
use TYPO3\CMS\Core\Type\Bitmask\Permission;
1314
use TYPO3\CMS\Core\Utility\GeneralUtility;
1415
use TYPO3\CMS\Extbase\Object\Exception;
1516

@@ -247,6 +248,30 @@ public static function filterPagesForAccess(array $pids): array
247248
return $pids;
248249
}
249250

251+
/**
252+
* Check if the current backend user is allowed to see a single page
253+
*
254+
* This check is done on the already resolved (int) page identifier that the actions of the backend module
255+
* are working with. \TYPO3\CMS\Backend\Http\RouteDispatcher checks the page access of a module request
256+
* as well, but only for page identifiers that pass MathUtility::canBeInterpretedAsInteger() and it reads
257+
* them from the query params before the parsed body. The module resolves its page identifier with
258+
* GeneralUtility::_GP() (parsed body first) and a raw (int) cast, so a non canonical identifier like
259+
* "09002" or an identifier that is only sent via POST would reach the mails of a page that the backend
260+
* user is not allowed to see.
261+
* Admins are allowed to see every page, not existing, deleted and not permitted pages are denied.
262+
*
263+
* @param int $pageIdentifier
264+
* @return bool
265+
*/
266+
public static function isPageAccessGranted(int $pageIdentifier): bool
267+
{
268+
if ($pageIdentifier <= 0) {
269+
return false;
270+
}
271+
$permissionClause = self::getBackendUserAuthentication()->getPagePermsClause(Permission::PAGE_SHOW);
272+
return is_array(BackendUtilityCore::readPageAccess($pageIdentifier, $permissionClause));
273+
}
274+
250275
/**
251276
* @return bool
252277
*/

‎Tests/Unit/Utility/BackendUtilityTest.php‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,38 @@ public function filterPagesForAccessReturnsArray()
342342
$this->assertSame([1, 2], BackendUtility::filterPagesForAccess([1, 2]));
343343
}
344344

345+
/**
346+
* Data Provider for isPageAccessGrantedReturnsBool()
347+
*
348+
* @return array
349+
*/
350+
public function isPageAccessGrantedReturnsBoolDataProvider()
351+
{
352+
return [
353+
'no page selected in module' => [
354+
0
355+
],
356+
'negative page identifier' => [
357+
-1
358+
]
359+
];
360+
}
361+
362+
/**
363+
* Page identifiers that can never be accessed are denied before any page record is read.
364+
* The permission check itself needs a database and is covered by manual and behaviour tests.
365+
*
366+
* @param int $pageIdentifier
367+
* @dataProvider isPageAccessGrantedReturnsBoolDataProvider
368+
* @return void
369+
* @test
370+
* @covers ::isPageAccessGranted
371+
*/
372+
public function isPageAccessGrantedReturnsBool($pageIdentifier)
373+
{
374+
$this->assertFalse(BackendUtility::isPageAccessGranted($pageIdentifier));
375+
}
376+
345377
/**
346378
* @return void
347379
* @test

0 commit comments

Comments
 (0)