{"id":"CVE-2026-31821","aliases":["CVE-2026-31821","GHSA-wjmg-4cq5-m8hg"],"related":[],"kind":"vulnerability","state":"published","title":"Sylius is Missing Authorization in API v2 Add Item Endpoint","summary":"Sylius is an Open Source eCommerce Framework on Symfony. The POST /api/v2/shop/orders/{tokenValue}/items endpoint does not verify cart ownership. An unauthenticated attacker can add items to other registered customers' carts by knowing the cart tokenValue. An attacker who obtains a cart tokenValue can add arbitrary items to another customer's cart. The endpoint returns the full cart representation in the response (HTTP 201). The issue is fixed in versions: 2.0.16, 2.1.12, 2.2.3 and above.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Sylius is an Open Source eCommerce Framework on Symfony. The POST /api/v2/shop/orders/{tokenValue}/items endpoint does not verify cart ownership. An unauthenticated attacker can add items to other registered customers' carts by knowing the cart tokenValue. An attacker who obtains a cart tokenValue can add arbitrary items to another customer's cart. The endpoint returns the full cart representation in the response (HTTP 201). The issue is fixed in versions: 2.0.16, 2.1.12, 2.2.3 and above.","source":"cvelist"},{"lang":"en","text":"### Impact\nThe `POST /api/v2/shop/orders/{tokenValue}/items` endpoint does not verify cart ownership. An unauthenticated attacker can add items to other registered customers' carts by knowing the cart `tokenValue`.\n\n```\nPOST /api/v2/shop/orders/{tokenValue}/items\n```\n\nOther mutation endpoints (PUT, PATCH, DELETE) are **not affected**. API Platform loads the Order entity through the state provider for these operations, which triggers `VisitorBasedExtension` and returns 404 for unauthorized users.\n\nAn attacker who obtains a cart `tokenValue` can add arbitrary items to another customer's cart. The endpoint returns the full cart representation in the response (HTTP 201), potentially leaking:\n\n- Customer email address\n- Cart contents (products, quantities, prices)\n- Address data (billing and shipping if set)\n- Payment and shipment IDs\n- Order totals and tax breakdown\n- Checkout state\n\n### Patches\nThe issue is fixed in versions: 2.0.16, 2.1.12, 2.2.3, and above.\n\n### Workarounds\nAdd an ownership check in `AddItemToCartHandler` by injecting `UserContextInterface` and verifying the current user matches the cart owner before adding items.\n\n#### Step 1. Patch the handler\n\nCreate new  `src/CommandHandler/Cart/AddItemToCartHandler.php`:\n\n```php\n<?php\n\ndeclare(strict_types=1);\n\nnamespace App\\CommandHandler\\Cart;\n\nuse Sylius\\Bundle\\ApiBundle\\Command\\Cart\\AddItemToCart;\nuse Sylius\\Bundle\\ApiBundle\\Context\\UserContextInterface;\nuse Sylius\\Component\\Core\\Factory\\CartItemFactoryInterface;\nuse Sylius\\Component\\Core\\Model\\OrderInterface;\nuse Sylius\\Component\\Core\\Model\\OrderItemInterface;\nuse Sylius\\Component\\Core\\Model\\ProductVariantInterface;\nuse Sylius\\Component\\Core\\Model\\ShopUserInterface;\nuse Sylius\\Component\\Core\\Repository\\OrderRepositoryInterface;\nuse Sylius\\Component\\Core\\Repository\\ProductVariantRepositoryInterface;\nuse Sylius\\Component\\Order\\Modifier\\OrderItemQuantityModifierInterface;\nuse Sylius\\Component\\Order\\Modifier\\OrderModifierInterface;\nuse Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException;\nuse Symfony\\Component\\Messenger\\Attribute\\AsMessageHandler;\n\n#[AsMessageHandler]\nfinal readonly class AddItemToCartHandler\n{\n    public function __construct(\n        private OrderRepositoryInterface $orderRepository,\n        private ProductVariantRepositoryInterface $productVariantRepository,\n        private OrderModifierInterface $orderModifier,\n        private CartItemFactoryInterface $cartItemFactory,\n        private OrderItemQuantityModifierInterface $orderItemQuantityModifier,\n        private UserContextInterface $userContext,\n    ) {\n    }\n\n    public function __invoke(AddItemToCart $addItemToCart): OrderInterface\n    {\n        /** @var ProductVariantInterface|null $productVariant */\n        $productVariant = $this->productVariantRepository->findOneBy(['code' => $addItemToCart->productVariantCode]);\n\n        if ($productVariant === null) {\n            throw new \\InvalidArgumentException('Product variant with given code has not been found.');\n        }\n\n        /** @var OrderInterface|null $cart */\n        $cart = $this->orderRepository->findCartByTokenValue($addItemToCart->orderTokenValue);\n\n        if ($cart === null) {\n            throw new \\InvalidArgumentException('Cart with given token has not been found.');\n        }\n\n        $this->assertCartAccessible($cart);\n\n        /** @var OrderItemInterface $cartItem */\n        $cartItem = $this->cartItemFactory->createNew();\n        $cartItem->setVariant($productVariant);\n\n        $this->orderItemQuantityModifier->modify($cartItem, $addItemToCart->quantity);\n        $this->orderModifier->addToOrder($cart, $cartItem);\n\n        return $cart;\n    }\n\n    private function assertCartAccessible(OrderInterface $cart): void\n    {\n        if ($cart->isCreatedByGuest()) {\n            return;\n        }\n\n        $cartCustomer = $cart->getCustomer();\n\n        if (null === $cartCustomer || null === $cartCustomer->getUser()) {\n            return;\n        }\n\n        $currentUser = $this->userContext->getUser();\n\n        if (\n            $currentUser instanceof ShopUserInterface\n            && $currentUser->getCustomer()?->getId() === $cartCustomer->getId()\n        ) {\n            return;\n        }\n\n        throw new NotFoundHttpException('Cart not found.');\n    }\n}\n```\n\n#### Step 2. Override the service\n\n```diff\n# config/services.yaml\n\nservices:\n    App\\:\n        resource: '../src/*'\n-       exclude: '../src/{Entity,Kernel.php}'                                                                         \n+       exclude: '../src/{Entity,Kernel.php,CommandHandler}'\n\n    sylius_api.command_handler.cart.add_item_to_cart:\n        class: App\\CommandHandler\\Cart\\AddItemToCartHandler\n        arguments:\n            $orderRepository: '@sylius.repository.order'\n            $productVariantRepository: '@sylius.repository.product_variant'\n            $orderModifier: '@sylius.modifier.order'\n            $cartItemFactory: '@sylius.factory.order_item'\n            $orderItemQuantityModifier: '@sylius.modifier.order_item_quantity'\n            $userContext: '@Sylius\\Bundle\\ApiBundle\\Context\\UserContextInterface'\n        tags:\n            - { name: messenger.message_handler, bus: sylius.command_bus }\n```\n\n#### Step 3. Clear cache\n\n```bash\nbin/console cache:clear\n```\n\n### Reporters\n\nWe would like to extend our gratitude to the following individuals for their detailed reporting and responsible disclosure of this vulnerability:\n- @rokorolov\n\n### For more information\nIf you have any questions or comments about this advisory:\n\n- Open an issue in [Sylius issues](https://github.com/Sylius/Sylius/issues?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen)\n- Email us at [security@sylius.com](mailto:security@sylius.com)","format":"markdown","source":"ghsa"},{"lang":"es","text":"Sylius es un Framework de eCommerce de Código Abierto en Symfony. El endpoint POST /api/v2/shop/orders/{tokenValue}/items no verifica la propiedad del carrito. Un atacante no autenticado puede añadir artículos a los carritos de otros clientes registrados conociendo el tokenValue del carrito. Un atacante que obtiene un tokenValue de carrito puede añadir artículos arbitrarios al carrito de otro cliente. El endpoint devuelve la representación completa del carrito en la respuesta (HTTP 201). El problema está solucionado en las versiones: 2.0.16, 2.1.12, 2.2.3 y superiores.","source":"nvd"}],"published":"2026-03-10T21:25:20.368Z","modified":"2026-06-17T10:34:31.280Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N","score":6.9,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N","score":6.9,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N","rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N","score":5.3,"rating":"MEDIUM"}],"cwes":["CWE-862"],"affected":[{"ranges":[{"version":">= 2.2.0, < 2.2.3","status":"affected"},{"version":">= 2.1.0, < 2.1.12","status":"affected"},{"version":">= 2.0.0, < 2.0.16","status":"affected"}],"vendor":"Sylius","product":"Sylius","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"2.0.0","status":"affected","fixed":"2.0.16"}],"ecosystem":"Packagist","package":"sylius/sylius","purl":"pkg:composer/sylius/sylius","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.1.0","status":"affected","fixed":"2.1.12"}],"ecosystem":"Packagist","package":"sylius/sylius","purl":"pkg:composer/sylius/sylius","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.2.0","status":"affected","fixed":"2.2.3"}],"ecosystem":"Packagist","package":"sylius/sylius","purl":"pkg:composer/sylius/sylius","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"2.0.0","fixed":"2.0.16"},{"status":"affected","introduced":"2.1.0","fixed":"2.1.12"},{"status":"affected","introduced":"2.2.0","fixed":"2.2.3"}],"vendor":"sylius","product":"sylius","cpe":"cpe:2.3:a:sylius:sylius:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/Sylius/Sylius/security/advisories/GHSA-wjmg-4cq5-m8hg","tags":["mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-31821","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/Sylius/Sylius","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-03-11T15:09:13.238Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-31821","url":"https://www.cve.org/CVERecord?id=CVE-2026-31821","licence":"CVE Terms of Use","modified":"2026-03-11T15:19:28.880Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-wjmg-4cq5-m8hg","url":"https://github.com/advisories/GHSA-wjmg-4cq5-m8hg","licence":"CC-BY-4.0","modified":"2026-03-13T05:56:20.944Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-31821","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-31821","licence":"Public domain","modified":"2026-06-17T10:34:31.280Z"}],"updatedAt":"2026-11-25T22:59:15.675Z","epss":{"score":0.00211,"percentile":0.1198,"date":"2026-12-01T12:00:22.000Z"}}