GHSA-PQQ3-Q84H-PJ6X

Vulnerability from github – Published: 2025-03-17 21:26 – Updated: 2025-03-17 21:26
VLAI?
Summary
Sylius PayPal Plugin Payment Amount Manipulation Vulnerability
Details

A vulnerability allows users to manipulate the final payment amount processed by PayPal. If a user modifies the item quantity in their shopping cart after initiating the PayPal Checkout process, PayPal will not receive the updated total amount. As a result, PayPal captures only the initially transmitted amount, while Sylius incorrectly considers the order fully paid based on the modified total. This flaw can be exploited both accidentally and intentionally, potentially enabling fraud by allowing customers to pay less than the actual order value.

Impact

  • Attackers can intentionally pay less than the actual total order amount.
  • Business owners may suffer financial losses due to underpaid orders.
  • Integrity of payment processing is compromised.

Patches

The issue is fixed in versions: 1.6.1, 1.7.1, 2.0.1 and above.

Workarounds

To resolve the problem in the end application without updating to the newest patches, there is a need to overwrite ProcessPayPalOrderAction with modified logic:

<?php

declare(strict_types=1);

namespace App\Controller;

use Doctrine\Persistence\ObjectManager;
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Sylius\Abstraction\StateMachine\WinzouStateMachineAdapter;
use Sylius\Component\Core\Factory\AddressFactoryInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Core\OrderCheckoutTransitions;
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface;
use Sylius\PayPalPlugin\Api\OrderDetailsApiInterface;
use Sylius\PayPalPlugin\Manager\PaymentStateManagerInterface;
use Sylius\PayPalPlugin\Provider\OrderProviderInterface;
use Sylius\PayPalPlugin\Verifier\PaymentAmountVerifierInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class ProcessPayPalOrderAction
{
    public function __construct(
        private readonly CustomerRepositoryInterface $customerRepository,
        private readonly FactoryInterface $customerFactory,
        private readonly AddressFactoryInterface $addressFactory,
        private readonly ObjectManager $orderManager,
        private readonly StateMachineFactoryInterface|StateMachineInterface $stateMachineFactory,
        private readonly PaymentStateManagerInterface $paymentStateManager,
        private readonly CacheAuthorizeClientApiInterface $authorizeClientApi,
        private readonly OrderDetailsApiInterface $orderDetailsApi,
        private readonly OrderProviderInterface $orderProvider,
    ) {
    }

    public function __invoke(Request $request): Response
    {
        $orderId = $request->request->getInt('orderId');
        $order = $this->orderProvider->provideOrderById($orderId);
        /** @var PaymentInterface $payment */
        $payment = $order->getLastPayment(PaymentInterface::STATE_CART);

        $data = $this->getOrderDetails((string) $request->request->get('payPalOrderId'), $payment);

        /** @var CustomerInterface|null $customer */
        $customer = $order->getCustomer();
        if ($customer === null) {
            $customer = $this->getOrderCustomer($data['payer']);
            $order->setCustomer($customer);
        }

        $purchaseUnit = (array) $data['purchase_units'][0];

        $address = $this->addressFactory->createNew();

        if ($order->isShippingRequired()) {
            $name = explode(' ', $purchaseUnit['shipping']['name']['full_name']);
            $address->setLastName(array_pop($name) ?? '');
            $address->setFirstName(implode(' ', $name));
            $address->setStreet($purchaseUnit['shipping']['address']['address_line_1']);
            $address->setCity($purchaseUnit['shipping']['address']['admin_area_2']);
            $address->setPostcode($purchaseUnit['shipping']['address']['postal_code']);
            $address->setCountryCode($purchaseUnit['shipping']['address']['country_code']);

            $this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);
            $this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING);
        } else {
            $address->setFirstName($customer->getFirstName());
            $address->setLastName($customer->getLastName());

            $defaultAddress = $customer->getDefaultAddress();

            $address->setStreet($defaultAddress ? $defaultAddress->getStreet() : '');
            $address->setCity($defaultAddress ? $defaultAddress->getCity() : '');
            $address->setPostcode($defaultAddress ? $defaultAddress->getPostcode() : '');
            $address->setCountryCode($data['payer']['address']['country_code']);

            $this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);
        }

        $order->setShippingAddress(clone $address);
        $order->setBillingAddress(clone $address);

        $this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);

        $this->orderManager->flush();

        try {
            $this->verify($payment, $data);
        } catch (\Exception) {
            $this->paymentStateManager->cancel($payment);

            return new JsonResponse(['orderID' => $order->getId()]);
        }

        $this->paymentStateManager->create($payment);
        $this->paymentStateManager->process($payment);

        return new JsonResponse(['orderID' => $order->getId()]);
    }

    private function getOrderCustomer(array $customerData): CustomerInterface
    {
        /** @var CustomerInterface|null $existingCustomer */
        $existingCustomer = $this->customerRepository->findOneBy(['email' => $customerData['email_address']]);
        if ($existingCustomer !== null) {
            return $existingCustomer;
        }

        /** @var CustomerInterface $customer */
        $customer = $this->customerFactory->createNew();
        $customer->setEmail($customerData['email_address']);
        $customer->setFirstName($customerData['name']['given_name']);
        $customer->setLastName($customerData['name']['surname']);

        return $customer;
    }

    private function getOrderDetails(string $id, PaymentInterface $payment): array
    {
        /** @var PaymentMethodInterface $paymentMethod */
        $paymentMethod = $payment->getMethod();
        $token = $this->authorizeClientApi->authorize($paymentMethod);

        return $this->orderDetailsApi->get($token, $id);
    }

    private function getStateMachine(): StateMachineInterface
    {
        if ($this->stateMachineFactory instanceof StateMachineFactoryInterface) {
            return new WinzouStateMachineAdapter($this->stateMachineFactory);
        }

        return $this->stateMachineFactory;
    }

    private function verify(PaymentInterface $payment, array $paypalOrderDetails): void
    {
        $totalAmount = $this->getTotalPaymentAmountFromPaypal($paypalOrderDetails);

        if ($payment->getAmount() !== $totalAmount) {
            throw new \Exception();
        }
    }

    private function getTotalPaymentAmountFromPaypal(array $paypalOrderDetails): int
    {
        if (!isset($paypalOrderDetails['purchase_units']) || !is_array($paypalOrderDetails['purchase_units'])) {
            return 0;
        }

        $totalAmount = 0;

        foreach ($paypalOrderDetails['purchase_units'] as $unit) {
            $stringAmount = $unit['amount']['value'] ?? '0';

            $totalAmount += (int) ($stringAmount * 100);
        }

        return $totalAmount;
    }
}

Also there is a need to overwrite CompletePayPalOrderFromPaymentPageAction with modified logic:

<?php

declare(strict_types=1);

namespace App\Controller;

use Doctrine\Persistence\ObjectManager;
use SM\Factory\FactoryInterface;
use Sylius\Abstraction\StateMachine\StateMachineInterface;
use Sylius\Abstraction\StateMachine\WinzouStateMachineAdapter;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\OrderCheckoutTransitions;
use Sylius\Component\Order\Processor\OrderProcessorInterface;
use Sylius\PayPalPlugin\Exception\PaymentAmountMismatchException;
use Sylius\PayPalPlugin\Manager\PaymentStateManagerInterface;
use Sylius\PayPalPlugin\Provider\OrderProviderInterface;
use Sylius\PayPalPlugin\Verifier\PaymentAmountVerifierInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

final class CompletePayPalOrderFromPaymentPageAction
{
    public function __construct(
        private readonly PaymentStateManagerInterface $paymentStateManager,
        private readonly UrlGeneratorInterface $router,
        private readonly OrderProviderInterface $orderProvider,
        private readonly FactoryInterface|StateMachineInterface $stateMachine,
        private readonly ObjectManager $orderManager,
        private readonly OrderProcessorInterface $orderProcessor,
    ) {
    }

    public function __invoke(Request $request): Response
    {
        $orderId = $request->attributes->getInt('id');

        $order = $this->orderProvider->provideOrderById($orderId);
        /** @var PaymentInterface $payment */
        $payment = $order->getLastPayment(PaymentInterface::STATE_PROCESSING);

        try {
            $this->verify($payment);
        } catch (\Exception) {
            $this->paymentStateManager->cancel($payment);
            $order->removePayment($payment);

            $this->orderProcessor->process($order);

            return new JsonResponse([
                'return_url' => $this->router->generate('sylius_shop_checkout_complete', [], UrlGeneratorInterface::ABSOLUTE_URL),
            ]);
        }

        $this->paymentStateManager->complete($payment);

        $this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);
        $this->getStateMachine()->apply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_COMPLETE);

        $this->orderManager->flush();

        $request->getSession()->set('sylius_order_id', $order->getId());

        return new JsonResponse([
            'return_url' => $this->router->generate('sylius_shop_order_thank_you', [], UrlGeneratorInterface::ABSOLUTE_URL),
        ]);
    }

    private function getStateMachine(): StateMachineInterface
    {
        if ($this->stateMachine instanceof FactoryInterface) {
            return new WinzouStateMachineAdapter($this->stateMachine);
        }

        return $this->stateMachine;
    }

    private function verify(PaymentInterface $payment): void
    {
        $totalAmount = $this->getTotalPaymentAmountFromPaypal($payment);

        if ($payment->getOrder()->getTotal() !== $totalAmount) {
            throw new \Exception();
        }
    }

    private function getTotalPaymentAmountFromPaypal(PaymentInterface $payment): int
    {
        $details = $payment->getDetails();

        return $details['payment_amount'] ?? 0;
    }
}

And to overwrite CaptureAction with modified logic:

<?php

declare(strict_types=1);

namespace App\Payum\Action;

use Payum\Core\Action\ActionInterface;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Request\Capture;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface;
use Sylius\PayPalPlugin\Api\CreateOrderApiInterface;
use Sylius\PayPalPlugin\Payum\Action\StatusAction;
use Sylius\PayPalPlugin\Provider\UuidProviderInterface;

final class CaptureAction implements ActionInterface
{
    public function __construct(
        private CacheAuthorizeClientApiInterface $authorizeClientApi,
        private CreateOrderApiInterface $createOrderApi,
        private UuidProviderInterface $uuidProvider,
    ) {
    }

    /** @param Capture $request */
    public function execute($request): void
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var PaymentInterface $payment */
        $payment = $request->getModel();
        /** @var PaymentMethodInterface $paymentMethod */
        $paymentMethod = $payment->getMethod();

        $token = $this->authorizeClientApi->authorize($paymentMethod);

        $referenceId = $this->uuidProvider->provide();
        $content = $this->createOrderApi->create($token, $payment, $referenceId);

        if ($content['status'] === 'CREATED') {
            $payment->setDetails([
                'status' => StatusAction::STATUS_CAPTURED,
                'paypal_order_id' => $content['id'],
                'reference_id' => $referenceId,
                'payment_amount' => $payment->getAmount(),
            ]);
        }
    }

    public function supports($request): bool
    {
        return
            $request instanceof Capture &&
            $request->getModel() instanceof PaymentInterface
        ;
    }
}

After that, register services in the container when using PayPal 1.x:

services:
    App\Controller\ProcessPayPalOrderAction:
        class: App\Controller\ProcessPayPalOrderAction
        public: true
        arguments:
            - '@sylius.repository.customer'
            - '@sylius.factory.customer'
            - '@sylius.factory.address'
            - '@sylius.manager.order'
            - '@sylius_abstraction.state_machine'
            - '@Sylius\PayPalPlugin\Manager\PaymentStateManagerInterface'
            - '@Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface'
            - '@Sylius\PayPalPlugin\Api\OrderDetailsApiInterface'
            - '@Sylius\PayPalPlugin\Provider\OrderProviderInterface'

    Sylius\PayPalPlugin\Controller\ProcessPayPalOrderAction:
        alias: App\Controller\ProcessPayPalOrderAction

    App\Controller\CompletePayPalOrderFromPaymentPageAction:
        class: App\Controller\CompletePayPalOrderFromPaymentPageAction
        public: true
        arguments:
            - '@Sylius\PayPalPlugin\Manager\PaymentStateManagerInterface'
            - '@router'
            - '@Sylius\PayPalPlugin\Provider\OrderProviderInterface'
            - '@sylius_abstraction.state_machine'
            - '@sylius.manager.order'
            - '@sylius.order_processing.order_processor'

    Sylius\PayPalPlugin\Controller\CompletePayPalOrderFromPaymentPageAction:
        alias: App\Controller\CompletePayPalOrderFromPaymentPageAction

    Sylius\PayPalPlugin\Payum\Action\CaptureAction:
        class: App\Payum\Action\CaptureAction
        public: true
        arguments:
            - '@Sylius\PayPalPlugin\Api\CacheAuthorizeClientApiInterface'
            - '@Sylius\PayPalPlugin\Api\CreateOrderApiInterface'
            - '@Sylius\PayPalPlugin\Provider\UuidProviderInterface'
        tags:
            - { name: 'payum.action', factory: 'sylius.pay_pal', alias: 'payum.action.capture' }

or when using PayPal 2.x:

services:
    App\Controller\ProcessPayPalOrderAction:
        class: App\Controller\ProcessPayPalOrderAction
        public: true
        arguments:
            - '@sylius.repository.customer'
            - '@sylius.factory.customer'
            - '@sylius.factory.address'
            - '@sylius.manager.order'
            - '@sylius_abstraction.state_machine'
            - '@sylius_paypal.manager.payment_state'
            - '@sylius_paypal.api.cache_authorize_client'
            - '@sylius_paypal.api.order_details'
            - '@sylius_paypal.provider.order'

    sylius_paypal.controller.process_paypal_order:
        alias: App\Controller\ProcessPayPalOrderAction

    App\Controller\CompletePayPalOrderFromPaymentPageAction:
        class: App\Controller\CompletePayPalOrderFromPaymentPageAction
        public: true
        arguments:
            - '@sylius_paypal.manager.payment_state'
            - '@router'
            - '@sylius_paypal.provider.order'
            - '@sylius_abstraction.state_machine'
            - '@sylius.manager.order'
            - '@sylius.order_processing.order_processor'

    sylius_paypal.controller.complete_paypal_order_from_payment_page:
        alias: App\Controller\CompletePayPalOrderFromPaymentPageAction

    sylius_paypal.payum.action.capture:
        class: App\Payum\Action\CaptureAction
        public: true
        arguments:
            - '@sylius_paypal.api.cache_authorize_client'
            - '@sylius_paypal.api.create_order'
            - '@sylius_paypal.provider.uuid'
        tags:
            - { name: 'payum.action', factory: 'sylius.paypal', alias: 'payum.action.capture' }

For more information

If you have any questions or comments about this advisory: * Open an issue in Sylius issues * Email us at security@sylius.com

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "sylius/paypal-plugin"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "1.6.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "sylius/paypal-plugin"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "1.7.0"
            },
            {
              "fixed": "1.7.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "Packagist",
        "name": "sylius/paypal-plugin"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "2.0.0"
            },
            {
              "fixed": "2.0.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2025-29788"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-472"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2025-03-17T21:26:50Z",
    "nvd_published_at": "2025-03-17T14:15:22Z",
    "severity": "MODERATE"
  },
  "details": "A vulnerability allows users to manipulate the final payment amount processed by PayPal. If a user modifies the item quantity in their shopping cart after initiating the PayPal Checkout process, PayPal will not receive the updated total amount. As a result, PayPal captures only the initially transmitted amount, while Sylius incorrectly considers the order fully paid based on the modified total. This flaw can be exploited both accidentally and intentionally, potentially enabling fraud by allowing customers to pay less than the actual order value.\n\n### Impact\n\n- Attackers can intentionally pay less than the actual total order amount.\n- Business owners may suffer financial losses due to underpaid orders.\n- Integrity of payment processing is compromised.\n\n### Patches\n\nThe issue is fixed in versions: 1.6.1, 1.7.1, 2.0.1 and above.\n\n### Workarounds\n\nTo resolve the problem in the end application without updating to the newest patches, there is a need to overwrite `ProcessPayPalOrderAction` with modified logic:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Controller;\n\nuse Doctrine\\Persistence\\ObjectManager;\nuse SM\\Factory\\FactoryInterface as StateMachineFactoryInterface;\nuse Sylius\\Abstraction\\StateMachine\\StateMachineInterface;\nuse Sylius\\Abstraction\\StateMachine\\WinzouStateMachineAdapter;\nuse Sylius\\Component\\Core\\Factory\\AddressFactoryInterface;\nuse Sylius\\Component\\Core\\Model\\CustomerInterface;\nuse Sylius\\Component\\Core\\Model\\PaymentInterface;\nuse Sylius\\Component\\Core\\Model\\PaymentMethodInterface;\nuse Sylius\\Component\\Core\\OrderCheckoutTransitions;\nuse Sylius\\Component\\Core\\Repository\\CustomerRepositoryInterface;\nuse Sylius\\Component\\Resource\\Factory\\FactoryInterface;\nuse Sylius\\PayPalPlugin\\Api\\CacheAuthorizeClientApiInterface;\nuse Sylius\\PayPalPlugin\\Api\\OrderDetailsApiInterface;\nuse Sylius\\PayPalPlugin\\Manager\\PaymentStateManagerInterface;\nuse Sylius\\PayPalPlugin\\Provider\\OrderProviderInterface;\nuse Sylius\\PayPalPlugin\\Verifier\\PaymentAmountVerifierInterface;\nuse Symfony\\Component\\HttpFoundation\\JsonResponse;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nfinal class ProcessPayPalOrderAction\n{\n    public function __construct(\n        private readonly CustomerRepositoryInterface $customerRepository,\n        private readonly FactoryInterface $customerFactory,\n        private readonly AddressFactoryInterface $addressFactory,\n        private readonly ObjectManager $orderManager,\n        private readonly StateMachineFactoryInterface|StateMachineInterface $stateMachineFactory,\n        private readonly PaymentStateManagerInterface $paymentStateManager,\n        private readonly CacheAuthorizeClientApiInterface $authorizeClientApi,\n        private readonly OrderDetailsApiInterface $orderDetailsApi,\n        private readonly OrderProviderInterface $orderProvider,\n    ) {\n    }\n\n    public function __invoke(Request $request): Response\n    {\n        $orderId = $request-\u003erequest-\u003egetInt(\u0027orderId\u0027);\n        $order = $this-\u003eorderProvider-\u003eprovideOrderById($orderId);\n        /** @var PaymentInterface $payment */\n        $payment = $order-\u003egetLastPayment(PaymentInterface::STATE_CART);\n\n        $data = $this-\u003egetOrderDetails((string) $request-\u003erequest-\u003eget(\u0027payPalOrderId\u0027), $payment);\n\n        /** @var CustomerInterface|null $customer */\n        $customer = $order-\u003egetCustomer();\n        if ($customer === null) {\n            $customer = $this-\u003egetOrderCustomer($data[\u0027payer\u0027]);\n            $order-\u003esetCustomer($customer);\n        }\n\n        $purchaseUnit = (array) $data[\u0027purchase_units\u0027][0];\n\n        $address = $this-\u003eaddressFactory-\u003ecreateNew();\n\n        if ($order-\u003eisShippingRequired()) {\n            $name = explode(\u0027 \u0027, $purchaseUnit[\u0027shipping\u0027][\u0027name\u0027][\u0027full_name\u0027]);\n            $address-\u003esetLastName(array_pop($name) ?? \u0027\u0027);\n            $address-\u003esetFirstName(implode(\u0027 \u0027, $name));\n            $address-\u003esetStreet($purchaseUnit[\u0027shipping\u0027][\u0027address\u0027][\u0027address_line_1\u0027]);\n            $address-\u003esetCity($purchaseUnit[\u0027shipping\u0027][\u0027address\u0027][\u0027admin_area_2\u0027]);\n            $address-\u003esetPostcode($purchaseUnit[\u0027shipping\u0027][\u0027address\u0027][\u0027postal_code\u0027]);\n            $address-\u003esetCountryCode($purchaseUnit[\u0027shipping\u0027][\u0027address\u0027][\u0027country_code\u0027]);\n\n            $this-\u003egetStateMachine()-\u003eapply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);\n            $this-\u003egetStateMachine()-\u003eapply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_SHIPPING);\n        } else {\n            $address-\u003esetFirstName($customer-\u003egetFirstName());\n            $address-\u003esetLastName($customer-\u003egetLastName());\n\n            $defaultAddress = $customer-\u003egetDefaultAddress();\n\n            $address-\u003esetStreet($defaultAddress ? $defaultAddress-\u003egetStreet() : \u0027\u0027);\n            $address-\u003esetCity($defaultAddress ? $defaultAddress-\u003egetCity() : \u0027\u0027);\n            $address-\u003esetPostcode($defaultAddress ? $defaultAddress-\u003egetPostcode() : \u0027\u0027);\n            $address-\u003esetCountryCode($data[\u0027payer\u0027][\u0027address\u0027][\u0027country_code\u0027]);\n\n            $this-\u003egetStateMachine()-\u003eapply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_ADDRESS);\n        }\n\n        $order-\u003esetShippingAddress(clone $address);\n        $order-\u003esetBillingAddress(clone $address);\n\n        $this-\u003egetStateMachine()-\u003eapply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);\n\n        $this-\u003eorderManager-\u003eflush();\n\n        try {\n            $this-\u003everify($payment, $data);\n        } catch (\\Exception) {\n            $this-\u003epaymentStateManager-\u003ecancel($payment);\n\n            return new JsonResponse([\u0027orderID\u0027 =\u003e $order-\u003egetId()]);\n        }\n\n        $this-\u003epaymentStateManager-\u003ecreate($payment);\n        $this-\u003epaymentStateManager-\u003eprocess($payment);\n\n        return new JsonResponse([\u0027orderID\u0027 =\u003e $order-\u003egetId()]);\n    }\n\n    private function getOrderCustomer(array $customerData): CustomerInterface\n    {\n        /** @var CustomerInterface|null $existingCustomer */\n        $existingCustomer = $this-\u003ecustomerRepository-\u003efindOneBy([\u0027email\u0027 =\u003e $customerData[\u0027email_address\u0027]]);\n        if ($existingCustomer !== null) {\n            return $existingCustomer;\n        }\n\n        /** @var CustomerInterface $customer */\n        $customer = $this-\u003ecustomerFactory-\u003ecreateNew();\n        $customer-\u003esetEmail($customerData[\u0027email_address\u0027]);\n        $customer-\u003esetFirstName($customerData[\u0027name\u0027][\u0027given_name\u0027]);\n        $customer-\u003esetLastName($customerData[\u0027name\u0027][\u0027surname\u0027]);\n\n        return $customer;\n    }\n\n    private function getOrderDetails(string $id, PaymentInterface $payment): array\n    {\n        /** @var PaymentMethodInterface $paymentMethod */\n        $paymentMethod = $payment-\u003egetMethod();\n        $token = $this-\u003eauthorizeClientApi-\u003eauthorize($paymentMethod);\n\n        return $this-\u003eorderDetailsApi-\u003eget($token, $id);\n    }\n\n    private function getStateMachine(): StateMachineInterface\n    {\n        if ($this-\u003estateMachineFactory instanceof StateMachineFactoryInterface) {\n            return new WinzouStateMachineAdapter($this-\u003estateMachineFactory);\n        }\n\n        return $this-\u003estateMachineFactory;\n    }\n\n    private function verify(PaymentInterface $payment, array $paypalOrderDetails): void\n    {\n        $totalAmount = $this-\u003egetTotalPaymentAmountFromPaypal($paypalOrderDetails);\n\n        if ($payment-\u003egetAmount() !== $totalAmount) {\n            throw new \\Exception();\n        }\n    }\n\n    private function getTotalPaymentAmountFromPaypal(array $paypalOrderDetails): int\n    {\n        if (!isset($paypalOrderDetails[\u0027purchase_units\u0027]) || !is_array($paypalOrderDetails[\u0027purchase_units\u0027])) {\n            return 0;\n        }\n\n        $totalAmount = 0;\n\n        foreach ($paypalOrderDetails[\u0027purchase_units\u0027] as $unit) {\n            $stringAmount = $unit[\u0027amount\u0027][\u0027value\u0027] ?? \u00270\u0027;\n\n            $totalAmount += (int) ($stringAmount * 100);\n        }\n\n        return $totalAmount;\n    }\n}\n```\n\nAlso there is a need to overwrite `CompletePayPalOrderFromPaymentPageAction` with modified logic:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Controller;\n\nuse Doctrine\\Persistence\\ObjectManager;\nuse SM\\Factory\\FactoryInterface;\nuse Sylius\\Abstraction\\StateMachine\\StateMachineInterface;\nuse Sylius\\Abstraction\\StateMachine\\WinzouStateMachineAdapter;\nuse Sylius\\Component\\Core\\Model\\PaymentInterface;\nuse Sylius\\Component\\Core\\OrderCheckoutTransitions;\nuse Sylius\\Component\\Order\\Processor\\OrderProcessorInterface;\nuse Sylius\\PayPalPlugin\\Exception\\PaymentAmountMismatchException;\nuse Sylius\\PayPalPlugin\\Manager\\PaymentStateManagerInterface;\nuse Sylius\\PayPalPlugin\\Provider\\OrderProviderInterface;\nuse Sylius\\PayPalPlugin\\Verifier\\PaymentAmountVerifierInterface;\nuse Symfony\\Component\\HttpFoundation\\JsonResponse;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface;\n\nfinal class CompletePayPalOrderFromPaymentPageAction\n{\n    public function __construct(\n        private readonly PaymentStateManagerInterface $paymentStateManager,\n        private readonly UrlGeneratorInterface $router,\n        private readonly OrderProviderInterface $orderProvider,\n        private readonly FactoryInterface|StateMachineInterface $stateMachine,\n        private readonly ObjectManager $orderManager,\n        private readonly OrderProcessorInterface $orderProcessor,\n    ) {\n    }\n\n    public function __invoke(Request $request): Response\n    {\n        $orderId = $request-\u003eattributes-\u003egetInt(\u0027id\u0027);\n\n        $order = $this-\u003eorderProvider-\u003eprovideOrderById($orderId);\n        /** @var PaymentInterface $payment */\n        $payment = $order-\u003egetLastPayment(PaymentInterface::STATE_PROCESSING);\n\n        try {\n            $this-\u003everify($payment);\n        } catch (\\Exception) {\n            $this-\u003epaymentStateManager-\u003ecancel($payment);\n            $order-\u003eremovePayment($payment);\n\n            $this-\u003eorderProcessor-\u003eprocess($order);\n\n            return new JsonResponse([\n                \u0027return_url\u0027 =\u003e $this-\u003erouter-\u003egenerate(\u0027sylius_shop_checkout_complete\u0027, [], UrlGeneratorInterface::ABSOLUTE_URL),\n            ]);\n        }\n\n        $this-\u003epaymentStateManager-\u003ecomplete($payment);\n\n        $this-\u003egetStateMachine()-\u003eapply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);\n        $this-\u003egetStateMachine()-\u003eapply($order, OrderCheckoutTransitions::GRAPH, OrderCheckoutTransitions::TRANSITION_COMPLETE);\n\n        $this-\u003eorderManager-\u003eflush();\n\n        $request-\u003egetSession()-\u003eset(\u0027sylius_order_id\u0027, $order-\u003egetId());\n\n        return new JsonResponse([\n            \u0027return_url\u0027 =\u003e $this-\u003erouter-\u003egenerate(\u0027sylius_shop_order_thank_you\u0027, [], UrlGeneratorInterface::ABSOLUTE_URL),\n        ]);\n    }\n\n    private function getStateMachine(): StateMachineInterface\n    {\n        if ($this-\u003estateMachine instanceof FactoryInterface) {\n            return new WinzouStateMachineAdapter($this-\u003estateMachine);\n        }\n\n        return $this-\u003estateMachine;\n    }\n\n    private function verify(PaymentInterface $payment): void\n    {\n        $totalAmount = $this-\u003egetTotalPaymentAmountFromPaypal($payment);\n\n        if ($payment-\u003egetOrder()-\u003egetTotal() !== $totalAmount) {\n            throw new \\Exception();\n        }\n    }\n\n    private function getTotalPaymentAmountFromPaypal(PaymentInterface $payment): int\n    {\n        $details = $payment-\u003egetDetails();\n\n        return $details[\u0027payment_amount\u0027] ?? 0;\n    }\n}\n```\n\nAnd to overwrite `CaptureAction` with modified logic:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Payum\\Action;\n\nuse Payum\\Core\\Action\\ActionInterface;\nuse Payum\\Core\\Exception\\RequestNotSupportedException;\nuse Payum\\Core\\Request\\Capture;\nuse Sylius\\Component\\Core\\Model\\PaymentInterface;\nuse Sylius\\Component\\Core\\Model\\PaymentMethodInterface;\nuse Sylius\\PayPalPlugin\\Api\\CacheAuthorizeClientApiInterface;\nuse Sylius\\PayPalPlugin\\Api\\CreateOrderApiInterface;\nuse Sylius\\PayPalPlugin\\Payum\\Action\\StatusAction;\nuse Sylius\\PayPalPlugin\\Provider\\UuidProviderInterface;\n\nfinal class CaptureAction implements ActionInterface\n{\n    public function __construct(\n        private CacheAuthorizeClientApiInterface $authorizeClientApi,\n        private CreateOrderApiInterface $createOrderApi,\n        private UuidProviderInterface $uuidProvider,\n    ) {\n    }\n\n    /** @param Capture $request */\n    public function execute($request): void\n    {\n        RequestNotSupportedException::assertSupports($this, $request);\n\n        /** @var PaymentInterface $payment */\n        $payment = $request-\u003egetModel();\n        /** @var PaymentMethodInterface $paymentMethod */\n        $paymentMethod = $payment-\u003egetMethod();\n\n        $token = $this-\u003eauthorizeClientApi-\u003eauthorize($paymentMethod);\n\n        $referenceId = $this-\u003euuidProvider-\u003eprovide();\n        $content = $this-\u003ecreateOrderApi-\u003ecreate($token, $payment, $referenceId);\n\n        if ($content[\u0027status\u0027] === \u0027CREATED\u0027) {\n            $payment-\u003esetDetails([\n                \u0027status\u0027 =\u003e StatusAction::STATUS_CAPTURED,\n                \u0027paypal_order_id\u0027 =\u003e $content[\u0027id\u0027],\n                \u0027reference_id\u0027 =\u003e $referenceId,\n                \u0027payment_amount\u0027 =\u003e $payment-\u003egetAmount(),\n            ]);\n        }\n    }\n\n    public function supports($request): bool\n    {\n        return\n            $request instanceof Capture \u0026\u0026\n            $request-\u003egetModel() instanceof PaymentInterface\n        ;\n    }\n}\n\n```\n\nAfter that, register services in the container when using PayPal 1.x:\n\n```yaml\nservices:\n    App\\Controller\\ProcessPayPalOrderAction:\n        class: App\\Controller\\ProcessPayPalOrderAction\n        public: true\n        arguments:\n            - \u0027@sylius.repository.customer\u0027\n            - \u0027@sylius.factory.customer\u0027\n            - \u0027@sylius.factory.address\u0027\n            - \u0027@sylius.manager.order\u0027\n            - \u0027@sylius_abstraction.state_machine\u0027\n            - \u0027@Sylius\\PayPalPlugin\\Manager\\PaymentStateManagerInterface\u0027\n            - \u0027@Sylius\\PayPalPlugin\\Api\\CacheAuthorizeClientApiInterface\u0027\n            - \u0027@Sylius\\PayPalPlugin\\Api\\OrderDetailsApiInterface\u0027\n            - \u0027@Sylius\\PayPalPlugin\\Provider\\OrderProviderInterface\u0027\n\n    Sylius\\PayPalPlugin\\Controller\\ProcessPayPalOrderAction:\n        alias: App\\Controller\\ProcessPayPalOrderAction\n\n    App\\Controller\\CompletePayPalOrderFromPaymentPageAction:\n        class: App\\Controller\\CompletePayPalOrderFromPaymentPageAction\n        public: true\n        arguments:\n            - \u0027@Sylius\\PayPalPlugin\\Manager\\PaymentStateManagerInterface\u0027\n            - \u0027@router\u0027\n            - \u0027@Sylius\\PayPalPlugin\\Provider\\OrderProviderInterface\u0027\n            - \u0027@sylius_abstraction.state_machine\u0027\n            - \u0027@sylius.manager.order\u0027\n            - \u0027@sylius.order_processing.order_processor\u0027\n\n    Sylius\\PayPalPlugin\\Controller\\CompletePayPalOrderFromPaymentPageAction:\n        alias: App\\Controller\\CompletePayPalOrderFromPaymentPageAction\n\n    Sylius\\PayPalPlugin\\Payum\\Action\\CaptureAction:\n        class: App\\Payum\\Action\\CaptureAction\n        public: true\n        arguments:\n            - \u0027@Sylius\\PayPalPlugin\\Api\\CacheAuthorizeClientApiInterface\u0027\n            - \u0027@Sylius\\PayPalPlugin\\Api\\CreateOrderApiInterface\u0027\n            - \u0027@Sylius\\PayPalPlugin\\Provider\\UuidProviderInterface\u0027\n        tags:\n            - { name: \u0027payum.action\u0027, factory: \u0027sylius.pay_pal\u0027, alias: \u0027payum.action.capture\u0027 }\n```\n\nor when using PayPal 2.x:\n\n```yaml\nservices:\n    App\\Controller\\ProcessPayPalOrderAction:\n        class: App\\Controller\\ProcessPayPalOrderAction\n        public: true\n        arguments:\n            - \u0027@sylius.repository.customer\u0027\n            - \u0027@sylius.factory.customer\u0027\n            - \u0027@sylius.factory.address\u0027\n            - \u0027@sylius.manager.order\u0027\n            - \u0027@sylius_abstraction.state_machine\u0027\n            - \u0027@sylius_paypal.manager.payment_state\u0027\n            - \u0027@sylius_paypal.api.cache_authorize_client\u0027\n            - \u0027@sylius_paypal.api.order_details\u0027\n            - \u0027@sylius_paypal.provider.order\u0027\n\n    sylius_paypal.controller.process_paypal_order:\n        alias: App\\Controller\\ProcessPayPalOrderAction\n\n    App\\Controller\\CompletePayPalOrderFromPaymentPageAction:\n        class: App\\Controller\\CompletePayPalOrderFromPaymentPageAction\n        public: true\n        arguments:\n            - \u0027@sylius_paypal.manager.payment_state\u0027\n            - \u0027@router\u0027\n            - \u0027@sylius_paypal.provider.order\u0027\n            - \u0027@sylius_abstraction.state_machine\u0027\n            - \u0027@sylius.manager.order\u0027\n            - \u0027@sylius.order_processing.order_processor\u0027\n\n    sylius_paypal.controller.complete_paypal_order_from_payment_page:\n        alias: App\\Controller\\CompletePayPalOrderFromPaymentPageAction\n\n    sylius_paypal.payum.action.capture:\n        class: App\\Payum\\Action\\CaptureAction\n        public: true\n        arguments:\n            - \u0027@sylius_paypal.api.cache_authorize_client\u0027\n            - \u0027@sylius_paypal.api.create_order\u0027\n            - \u0027@sylius_paypal.provider.uuid\u0027\n        tags:\n            - { name: \u0027payum.action\u0027, factory: \u0027sylius.paypal\u0027, alias: \u0027payum.action.capture\u0027 }\n```\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n* Open an issue in [Sylius issues](https://github.com/Sylius/Sylius/issues)\n* Email us at security@sylius.com",
  "id": "GHSA-pqq3-q84h-pj6x",
  "modified": "2025-03-17T21:26:51Z",
  "published": "2025-03-17T21:26:50Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/PayPalPlugin/security/advisories/GHSA-pqq3-q84h-pj6x"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2025-29788"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/PayPalPlugin/commit/31e71b0457e5d887a6c19f8cfabb8b16125ec406"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/PayPalPlugin/commit/8a81258f965b7860d4bccb52942e4c5b53e6774d"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/Sylius/PayPalPlugin"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/PayPalPlugin/releases/tag/v1.6.1"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/PayPalPlugin/releases/tag/v1.7.1"
    },
    {
      "type": "WEB",
      "url": "https://github.com/Sylius/PayPalPlugin/releases/tag/v2.0.1"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Sylius PayPal Plugin Payment Amount Manipulation Vulnerability"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Sightings

Author Source Type Date

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.


Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…