Skip to content

Commit 7b0399d

Browse files
committed
fix(security): remove HttpGetActionInterface from CategoryMerchandiser Save
Save controller should only handle POST requests. GET functionality is already provided by the Load controller. Removing dual interface ensures proper CSRF protection for all Save requests. Fixes #11
1 parent 060a037 commit 7b0399d

1 file changed

Lines changed: 1 addition & 41 deletions

File tree

  • Controller/Adminhtml/CategoryMerchandiser

Controller/Adminhtml/CategoryMerchandiser/Save.php

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Magento\Backend\App\Action;
88
use Magento\Backend\App\Action\Context;
99
use Magento\Framework\Api\SearchCriteriaBuilder;
10-
use Magento\Framework\App\Action\HttpGetActionInterface;
1110
use Magento\Framework\App\Action\HttpPostActionInterface;
1211
use Magento\Framework\Controller\Result\Json;
1312
use Magento\Framework\Controller\Result\JsonFactory;
@@ -17,7 +16,7 @@
1716
use RunAsRoot\TypeSense\Model\Curation\CategoryMerchandisingSync;
1817
use RunAsRoot\TypeSense\Model\Merchandising\CategoryMerchandisingFactory;
1918

20-
class Save extends Action implements HttpPostActionInterface, HttpGetActionInterface
19+
class Save extends Action implements HttpPostActionInterface
2120
{
2221
public const ADMIN_RESOURCE = 'RunAsRoot_TypeSense::overrides';
2322

@@ -38,45 +37,6 @@ public function execute(): Json
3837
{
3938
$resultJson = $this->jsonFactory->create();
4039

41-
// Handle GET: return existing rules for a category
42-
if ($this->getRequest()->isGet()) {
43-
return $this->handleGet($resultJson);
44-
}
45-
46-
return $this->handlePost($resultJson);
47-
}
48-
49-
private function handleGet(Json $resultJson): Json
50-
{
51-
$categoryId = (int) $this->getRequest()->getParam('category_id', 0);
52-
53-
if ($categoryId === 0) {
54-
return $resultJson->setData(['rules' => []]);
55-
}
56-
57-
$searchCriteria = $this->searchCriteriaBuilder
58-
->addFilter('category_id', $categoryId)
59-
->create();
60-
61-
$searchResults = $this->repository->getList($searchCriteria);
62-
$rules = [];
63-
64-
foreach ($searchResults->getItems() as $item) {
65-
$rules[] = [
66-
'product_id' => $item->getProductId(),
67-
'position' => $item->getPosition(),
68-
'action' => $item->getAction(),
69-
'name' => '',
70-
'sku' => '',
71-
'image_url' => '',
72-
];
73-
}
74-
75-
return $resultJson->setData(['rules' => $rules]);
76-
}
77-
78-
private function handlePost(Json $resultJson): Json
79-
{
8040
try {
8141
$raw = $this->getRequest()->getParam('payload') ?: $this->getRequest()->getContent();
8242
$payload = json_decode((string) $raw, true, 512, JSON_THROW_ON_ERROR);

0 commit comments

Comments
 (0)