custom/plugins/SwagPlatformSecurity/src/Fixes/NEXT15183/SecurityFix.php line 55

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Swag\Security\Fixes\NEXT15183;
  3. use Shopware\Core\Checkout\Cart\Exception\CustomerNotLoggedInException;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Exception\EntityNotFoundException;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  8. use Shopware\Core\Framework\Routing\KernelListenerPriorities;
  9. use Shopware\Core\PlatformRequest;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. use Swag\Security\Components\AbstractSecurityFix;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  15. use Symfony\Component\HttpKernel\KernelEvents;
  16. class SecurityFix extends AbstractSecurityFix
  17. {
  18.     /**
  19.      * @var EntityRepositoryInterface
  20.      */
  21.     private $orderRepository;
  22.     public function __construct(EntityRepositoryInterface $orderRepository)
  23.     {
  24.         $this->orderRepository $orderRepository;
  25.     }
  26.     public static function getTicket(): string
  27.     {
  28.         return 'NEXT-15183';
  29.     }
  30.     public static function getMinVersion(): string
  31.     {
  32.         return '6.2.0';
  33.     }
  34.     public static function getMaxVersion(): ?string
  35.     {
  36.         return '6.4.0.0';
  37.     }
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         return [
  41.             KernelEvents::CONTROLLER => [
  42.                 'onKernelRequest'KernelListenerPriorities::KERNEL_CONTROLLER_EVENT_CONTEXT_RESOLVE
  43.             ]
  44.         ];
  45.     }
  46.     public function onKernelRequest(ControllerEvent $event): void
  47.     {
  48.         $request $event->getRequest();
  49.         if (
  50.             $request->attributes->get('_route') !== 'store-api.order.state.cancel' &&
  51.             $request->attributes->get('_route') !== 'store-api.order.state.cancel.major_fallback'
  52.         ) {
  53.             return;
  54.         }
  55.         $orderId $request->get('orderId');
  56.         $context $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
  57.         if ($orderId === null || ! $context instanceof SalesChannelContext) {
  58.             return;
  59.         }
  60.         if ($context->getCustomer() === null) {
  61.             throw new CustomerNotLoggedInException();
  62.         }
  63.         $criteria = new Criteria([$orderId]);
  64.         $criteria->addFilter(new EqualsFilter('orderCustomer.customerId'$context->getCustomer()->getId()));
  65.         if ($this->orderRepository->searchIds($criteria$context->getContext())->firstId() === null) {
  66.             $event->setController(function () {
  67.                 return new Response(''Response::HTTP_NOT_FOUND);
  68.             });
  69.         }
  70.     }
  71. }