CVE-2026-31821: Sylius is Missing Authorization in API v2 Add Item Endpoint

Published Mar 10, 2026
·
Updated

Impact 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.

POST /api/v2/shop/orders/{tokenValue}/items

Other 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.

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), potentially leaking:

- Customer email address - Cart contents (products, quantities, prices) - Address data (billing and shipping if set) - Payment and shipment IDs - Order totals and tax breakdown - Checkout state

Patches The issue is fixed in versions: 2.0.16, 2.1.12, 2.2.3, and above.

Workarounds Add an ownership check in AddItemToCartHandler by injecting UserContextInterface and verifying the current user matches the cart owner before adding items.

Step 1. Patch the handler

Create new src/CommandHandler/Cart/AddItemToCartHandler.php:

php <?php

declare(stricttypes=1);

namespace App\CommandHandler\Cart;

use Sylius\Bundle\ApiBundle\Command\Cart\AddItemToCart; use Sylius\Bundle\ApiBundle\Context\UserContextInterface; use Sylius\Component\Core\Factory\CartItemFactoryInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemInterface; use Sylius\Component\Core\Model\ProductVariantInterface; use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface; use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface; use Sylius\Component\Order\Modifier\OrderModifierInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler] final readonly class AddItemToCartHandler { public function construct( private OrderRepositoryInterface $orderRepository, private ProductVariantRepositoryInterface $productVariantRepository, private OrderModifierInterface $orderModifier, private CartItemFactoryInterface $cartItemFactory, private OrderItemQuantityModifierInterface $orderItemQuantityModifier, private UserContextInterface $userContext, ) { }

public function invoke(AddItemToCart $addItemToCart): OrderInterface { / @var ProductVariantInterface|null $productVariant / $productVariant = $this->productVariantRepository->findOneBy(['code' => $addItemToCart->productVariantCode]);

if ($productVariant === null) { throw new \InvalidArgumentException('Product variant with given code has not been found.'); }

/ @var OrderInterface|null $cart / $cart = $this->orderRepository->findCartByTokenValue($addItemToCart->orderTokenValue);

if ($cart === null) { throw new \InvalidArgumentException('Cart with given token has not been found.'); }

$this->assertCartAccessible($cart);

/ @var OrderItemInterface $cartItem / $cartItem = $this->cartItemFactory->createNew(); $cartItem->setVariant($productVariant);

$this->orderItemQuantityModifier->modify($cartItem, $addItemToCart->quantity); $this->orderModifier->addToOrder($cart, $cartItem);

return $cart; }

private function assertCartAccessible(OrderInterface $cart): void { if ($cart->isCreatedByGuest()) { return; }

$cartCustomer = $cart->getCustomer();

if (null === $cartCustomer || null === $cartCustomer->getUser()) { return; }

$currentUser = $this->userContext->getUser();

if ( $currentUser instanceof ShopUserInterface && $currentUser->getCustomer()?->getId() === $cartCustomer->getId() ) { return; }

throw new NotFoundHttpException('Cart not found.'); } }

Step 2. Override the service

diff config/services.yaml

services: App\: resource: '../src/' - exclude: '../src/{Entity,Kernel.php}' + exclude: '../src/{Entity,Kernel.php,CommandHandler}'

syliusapi.commandhandler.cart.additemtocart: class: App\CommandHandler\Cart\AddItemToCartHandler arguments: $orderRepository: '@sylius.repository.order' $productVariantRepository: '@sylius.repository.productvariant' $orderModifier: '@sylius.modifier.order' $cartItemFactory: '@sylius.factory.orderitem' $orderItemQuantityModifier: '@sylius.modifier.orderitemquantity' $userContext: '@Sylius\Bundle\ApiBundle\Context\UserContextInterface' tags: - { name: messenger.messagehandler, bus: sylius.commandbus }

Step 3. Clear cache

bash bin/console cache:clear

Reporters

We would like to extend our gratitude to the following individuals for their detailed reporting and responsible disclosure of this vulnerability: - @rokorolov

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

Other sources

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.

— MITRE

Affected Software

7 affected componentsFixes available
sylius/sylius<2.0.16, <2.1.12, <2.2.3
composer/sylius/sylius>=2.2.0<=2.2.2
2.2.3
composer/sylius/sylius>=2.1.0<=2.1.11
2.1.12
composer/sylius/sylius>=2.0.0<=2.0.15
2.0.16
Sylius Sylius>=2.0.0<2.0.16
Sylius Sylius>=2.1.0<2.1.12
Sylius Sylius>=2.2.0<2.2.3

Event History

Mar 10, 2026
CVE Published
via MITRE·09:25 PM
Data Sourced
via MITRE·09:25 PM
DescriptionWeakness
Data Sourced
via NVD·10:16 PM
DescriptionSeverityWeaknessAffected Software
Mar 11, 2026
Advisory Published
via GitHub·12:12 AM
Data Sourced
via GitHub·12:12 AM
DescriptionWeaknessAffected Software
May 6, 58175
Event
via FIRST·10:06 AM

Frequently Asked Questions

1

What is the severity of CVE-2026-31821?

CVE-2026-31821 has a high severity due to its potential for unauthorized access to other users' shopping carts.

2

How do I fix CVE-2026-31821?

To fix CVE-2026-31821, upgrade to Sylius version 2.2.3, 2.1.12, or 2.0.16 as per your installation.

3

What types of systems are affected by CVE-2026-31821?

CVE-2026-31821 affects Sylius versions below 2.2.3, 2.1.12, and 2.0.16 that use the API v2 Add Item Endpoint.

4

Can unauthorized users exploit CVE-2026-31821?

Yes, unauthorized users can exploit CVE-2026-31821 to add items to other users' carts if they have the tokenValue.

5

What is the impact of CVE-2026-31821 on user data?

CVE-2026-31821 allows attackers to manipulate other users' carts, potentially leading to unauthorized purchases and data breaches.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203