Skip to content
Open
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
16 changes: 14 additions & 2 deletions src/Model/LandingPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Model\AbstractExtensibleModel;
use Magento\Framework\Registry;
use Magento\Framework\Model\Context;
use Exception;
use Magento\Framework\Model\ResourceModel\AbstractResource;

/**
Expand Down Expand Up @@ -346,11 +347,22 @@ public function setFilterAttributes(?string $filterAttributes): LandingPageInter
*/
public function getUnserializedFilterAttributes(): array
{
if ($this->getFilterAttributes() === null) {
$raw = $this->getFilterAttributes();
if ($raw === null || $raw === '') {
return [];
}

return unserialize($this->getFilterAttributes());
try {
$result = unserialize($raw, ['allowed_classes' => false]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely a class could never be stored here? This is data retrieved from the admin page's POST request.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the data originates from admin POST requests (so objects aren't expected), it's a security best practice — if the database row were ever tampered with, allowed_classes => false prevents PHP object injection attacks by making unserialize() throw instead of instantiating arbitrary classes.

} catch (Exception $e) {
return [];
}

if (!is_array($result)) {
return [];
}

return $result;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/Model/UrlFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Emico\AttributeLanding\Api\Data\FilterInterface;
use Emico\AttributeLanding\Api\Data\LandingPageInterface;
use Emico\AttributeLanding\Api\LandingPageRepositoryInterface;
use Exception;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\Serialize\SerializerInterface;
Expand Down Expand Up @@ -150,7 +151,13 @@ protected function loadPageLookupArray(): array

$landingPageLookup = [];
foreach ($this->landingPageRepository->getList($searchCriteria)->getItems() as $landingPage) {
$hash = $this->createHashForFilters($landingPage->getFilters(), $landingPage->getCategoryId());
try {
$filters = $landingPage->getFilters();
} catch (Exception $e) {
continue;
}

$hash = $this->createHashForFilters($filters, $landingPage->getCategoryId());
/** @phpstan-ignore-next-line */
$storeId = $landingPage->getData('store_id');
/** @phpstan-ignore-next-line */
Expand Down
Loading