Skip to content
Permalink
Browse files Browse the repository at this point in the history
[CVE-2023-22728] Check canView before printing from GridField
  • Loading branch information
GuySartorelli committed Apr 25, 2023
1 parent 92061a3 commit fd5d821
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
24 changes: 13 additions & 11 deletions src/Forms/GridField/GridFieldPrintButton.php
Expand Up @@ -228,21 +228,23 @@ public function generatePrintData(GridField $gridField)

/** @var DataObject $item */
foreach ($items->limit(null) as $item) {
$itemRow = new ArrayList();
if (!$item->hasMethod('canView') || $item->canView()) {
$itemRow = new ArrayList();

foreach ($printColumns as $field => $label) {
$value = $gridFieldColumnsComponent
? strip_tags($gridFieldColumnsComponent->getColumnContent($gridField, $item, $field))
: $gridField->getDataFieldValue($item, $field);
foreach ($printColumns as $field => $label) {
$value = $gridFieldColumnsComponent
? strip_tags($gridFieldColumnsComponent->getColumnContent($gridField, $item, $field))
: $gridField->getDataFieldValue($item, $field);

$itemRow->push(new ArrayData([
"CellString" => $value,
]));
}

$itemRow->push(new ArrayData([
"CellString" => $value,
$itemRows->push(new ArrayData([
"ItemRow" => $itemRow
]));
}

$itemRows->push(new ArrayData([
"ItemRow" => $itemRow
]));
if ($item->hasMethod('destroy')) {
$item->destroy();
}
Expand Down
16 changes: 14 additions & 2 deletions tests/php/Forms/GridField/GridFieldPrintButtonTest.php
Expand Up @@ -32,6 +32,19 @@ protected function setUp(): void
}

public function testLimit()
{
$this->assertEquals(42, $this->getTestableRows()->count());
}

public function testCanViewIsRespected()
{
$orig = TestObject::$canView;
TestObject::$canView = false;
$this->assertEquals(0, $this->getTestableRows()->count());
TestObject::$canView = $orig;
}

private function getTestableRows()
{
$list = TestObject::get();

Expand All @@ -48,7 +61,6 @@ public function testLimit()

// Printed data should ignore pagination limit
$printData = $button->generatePrintData($gridField);
$rows = $printData->ItemRows;
$this->assertEquals(42, $rows->count());
return $printData->ItemRows;
}
}
Expand Up @@ -12,4 +12,11 @@ class TestObject extends DataObject implements TestOnly
private static $db = [
'Name' => 'Varchar'
];

public static bool $canView = true;

public function canView($member = null)
{
return static::$canView;
}
}

0 comments on commit fd5d821

Please sign in to comment.