Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CVE-2024-29885] Respect canView permissions for viewing reports #189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/ReportAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public function handleAction($request, $action)
return $this->httpError(404);
}
$this->reportObject = $allReports[$this->reportClass];
if (!$this->reportObject->canView()) {
return Security::permissionFailure($this);
}
}

// Delegate to sub-form
Expand Down
34 changes: 31 additions & 3 deletions tests/ReportAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use ReflectionClass;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Reports\Report;
use SilverStripe\Reports\ReportAdmin;
use SilverStripe\Reports\Tests\ReportAdminTest\CannotViewReport;
use SilverStripe\Reports\Tests\ReportAdminTest\FakeReport;
use SilverStripe\Reports\Tests\ReportAdminTest\FakeReport2;

class ReportAdminTest extends SapphireTest
class ReportAdminTest extends FunctionalTest
{
public function testBreadcrumbsAreGenerated()
{
Expand Down Expand Up @@ -46,6 +46,34 @@ public function testBreadcrumbsAreGenerated()
$this->assertSame('Fake report two', $map['Title']);
}

public function provideShowReport(): array
{
return [
'cannot view' => [
'reportClass' => CannotViewReport::class,
'expected' => 403,
],
'can view' => [
'reportClass' => FakeReport::class,
'expected' => 200,
],
];
}

/**
* @dataProvider provideShowReport
*/
public function testShowReport(string $reportClass, int $expected): void
{
$this->logInWithPermission('ADMIN');
$report = new $reportClass();
$controller = $this->mockController($report);
$breadcrumbs = $controller->BreadCrumbs();
$response = $this->get($breadcrumbs[1]->Link);

$this->assertSame($expected, $response->getStatusCode());
}

/**
* @param Report $report
* @return ReportAdmin
Expand Down
19 changes: 19 additions & 0 deletions tests/ReportAdminTest/CannotViewReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace SilverStripe\Reports\Tests\ReportAdminTest;

use SilverStripe\Dev\TestOnly;
use SilverStripe\Reports\Report;

class CannotViewReport extends Report implements TestOnly
{
public function title()
{
return 'Cannot View report';
}

public function canView($member = null)
{
return false;
}
}
9 changes: 9 additions & 0 deletions tests/ReportAdminTest/FakeReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
namespace SilverStripe\Reports\Tests\ReportAdminTest;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Reports\Report;
use SilverStripe\Security\Member;

class FakeReport extends Report implements TestOnly
{
public function title()
{
return 'Fake report';
}

public function sourceRecords($params = [], $sort = null, $limit = null)
{
$list = new ArrayList();
$list->setDataClass(Member::class);
return $list;
}
}
Loading