Where
AND
-Infinity
0
Severity
5.3
EPSS
0.04%
SQL Injection
AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N

Impact Sylius API filters ProductPriceOrderFilter and TranslationOrderNameAndLocaleFilter pass user-supplied order direction values directly to Doctrine's orderBy() without validation. An attacker can inject arbitrary DQL:

GET /api/v2/shop/products?order[price]=ASC,%20variant.code%20DESC

Patches The issue is fixed in versions: 1.9.12, 1.10.16, 1.11.17, 1.12.23, 1.13.15, 1.14.18, 2.0.16, 2.1.12, 2.2.3 and above.

Workarounds

An EventSubscriber that sanitizes order query parameters only on API routes before they reach the vulnerable filters.

The subscriber accepts an $apiRoute constructor parameter (default /api/v2) and skips non-API requests entirely — so there is zero overhead on shop/admin page requests.

This follows the same pattern used by Sylius's own KernelRequestEventSubscriber (src/Sylius/Bundle/ApiBundle/EventSubscriber/KernelRequestEventSubscriber.php), which also uses strcontains($pathInfo, $this->apiRoute) to scope logic to API routes.

---

Step 1 — Create the EventSubscriber

src/EventSubscriber/SanitizeOrderDirectionSubscriber.php:

php <?php

declare(stricttypes=1);

namespace App\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents;

final class SanitizeOrderDirectionSubscriber implements EventSubscriberInterface { private const ALLOWEDDIRECTIONS = ['asc', 'desc'];

public function construct( private string $apiRoute, ) { }

public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => ['sanitizeOrderParameters', 64], ]; }

public function sanitizeOrderParameters(RequestEvent $event): void { if (!strcontains($event->getRequest()->getPathInfo(), $this->apiRoute)) { return; }

$request = $event->getRequest();

/ @var mixed $order / $order = $request->query->all()['order'] ?? null; if (!isarray($order)) { return; }

$needsSanitization = false; $sanitized = []; foreach ($order as $field => $direction) { if (isstring($direction) && inarray(strtolower($direction), self::ALLOWEDDIRECTIONS, true)) { $sanitized[$field] = $direction; } else { $needsSanitization = true; } }

if (!$needsSanitization) { return; }

$all = $request->query->all(); $all['order'] = $sanitized; $request->query->replace($all);

$request->server->set('QUERYSTRING', httpbuildquery($all)); $request->attributes->set('apifilters', $all); } }

Step 2 — Register the service

Option A — If your config/services.yaml already has App\ autowiring (Symfony default):

yaml Nothing to do — autoconfigure picks up EventSubscriberInterface automatically. Optionally bind the API route prefix: services: App\EventSubscriber\SanitizeOrderDirectionSubscriber: arguments: $apiRoute: '%sylius.security.newapiroute%'

Option B — If there is no App\ autowiring:

yaml services: App\EventSubscriber\SanitizeOrderDirectionSubscriber: arguments: $apiRoute: '%sylius.security.newapiroute%' tags: ['kernel.eventsubscriber']

Using %sylius.security.newapiroute% ties the subscriber to the same prefix Sylius uses (/api/v2 by default). If the parameter is not available, hardcode '/api/v2' instead.

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: - Chris Alupului (@Neosprings) - Bartłomiej Nowiński (@bnBart)

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

1 / 2
Source: GitHub
First published (updated )
Severity
8.2
EPSS
0.05%
Race Condition
AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:L

Impact A Time-of-Check To Time-of-Use (TOCTOU) race condition was discovered in the promotion usage limit enforcement. The same class of vulnerability affects three independent limits:

1. Promotion usage limit - the global used counter on Promotion entities 2. Coupon usage limit - the global used counter on PromotionCoupon entities 3. Coupon per-customer usage limit - the per-customer redemption count on PromotionCoupon entities

In all three cases, the eligibility check reads the used counter (or order count) from an in-memory Doctrine entity during validation, while the actual usage increment in OrderPromotionsUsageModifier happens later during order completion — with no database-level locking or atomic operations between the two phases.

Because Doctrine flushes an absolute value (SET used = 1) rather than an atomic increment (SET used = used + 1), and because the affected entities lack optimistic locking, concurrent requests all read the same stale usage counts and pass the eligibility checks simultaneously.

An attacker can exploit this by preparing multiple carts with the same limited-use promotion or coupon and firing simultaneous PATCH /api/v2/shop/orders/{token}/complete requests. All requests pass the usage limit checks and complete successfully, allowing a single-use promotion or coupon to be redeemed an arbitrary number of times. The per-customer limit can be bypassed in the same way by a single customer completing multiple orders concurrently. No authentication is required to exploit this vulnerability.

This may lead to direct financial loss through unlimited redemption of limited-use promotions and discount coupons.

Patches The issue is fixed in versions: 1.9.12, 1.10.16, 1.11.17, 1.12.23, 1.13.15, 1.14.18, 2.0.16, 2.1.12, 2.2.3 and above.

Workarounds

Decoration of the OrderPromotionsUsageModifier service to use atomic operations based on actual database-synchronized values.

The decorated service id in Sylius >=2.0 is sylius.modifier.promotion.orderusage, while <2.0 it's sylius.promotionusagemodifier; The following instruction uses the latter, but it needs to be changed depending on the Sylius version.

Step 1. Create the decorator service

src/Modifier/AtomicOrderPromotionsUsageModifier.php:

php <?php

declare(stricttypes=1);

namespace App\Modifier;

use Doctrine\DBAL\Connection; use Doctrine\ORM\OptimisticLockException; use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\PromotionCouponInterface; use Sylius\Component\Core\Promotion\Modifier\OrderPromotionsUsageModifierInterface; use Sylius\Component\Promotion\Model\PromotionInterface; // use Symfony\Component\DependencyInjection\Attribute\AsDecorator;

// #[AsDecorator(decorates: 'sylius.promotionusagemodifier')] final class AtomicOrderPromotionsUsageModifier implements OrderPromotionsUsageModifierInterface { / @var Connection / private $connection;

public function construct(Connection $connection) { $this->connection = $connection; }

public function increment(OrderInterface $order): void { foreach ($order->getPromotions() as $promotion) { $this->incrementPromotionUsage($promotion); }

/ @var PromotionCouponInterface|null $coupon / $coupon = $order->getPromotionCoupon(); if (null === $coupon) { return; }

$this->incrementCouponUsage($coupon, $order); }

public function decrement(OrderInterface $order): void { foreach ($order->getPromotions() as $promotion) { $this->decrementPromotionUsage($promotion); }

/ @var PromotionCouponInterface|null $coupon / $coupon = $order->getPromotionCoupon(); if (null === $coupon) { return; }

if (OrderInterface::STATECANCELLED === $order->getState() && !$coupon->isReusableFromCancelledOrders()) { return; }

$this->decrementCouponUsage($coupon); }

private function incrementPromotionUsage(PromotionInterface $promotion): void { $affected = $this->doExecuteStatement( 'UPDATE syliuspromotion SET used = used + 1 WHERE id = :id AND (usagelimit IS NULL OR used < usagelimit)', ['id' => $promotion->getId()] );

if (0 === $affected) { throw new OptimisticLockException(sprintf('Promotion "%s" is no longer applicable.', $promotion->getCode()), $promotion); }

$newUsed = (int) $this->doFetchOne( 'SELECT used FROM syliuspromotion WHERE id = :id', ['id' => $promotion->getId()] );

$promotion->setUsed($newUsed); }

private function decrementPromotionUsage(PromotionInterface $promotion): void { $this->doExecuteStatement( 'UPDATE syliuspromotion SET used = GREATEST(used - 1, 0) WHERE id = :id', ['id' => $promotion->getId()] );

$newUsed = (int) $this->doFetchOne( 'SELECT used FROM syliuspromotion WHERE id = :id', ['id' => $promotion->getId()] );

$promotion->setUsed($newUsed); }

private function incrementCouponUsage(PromotionCouponInterface $coupon, OrderInterface $order): void { $row = $this->doFetchAssociative( 'SELECT used, usagelimit, percustomerusagelimit FROM syliuspromotioncoupon WHERE id = :id FOR UPDATE', ['id' => $coupon->getId()] );

if (false === $row) { throw new OptimisticLockException(sprintf('Promotion coupon "%s" is no longer applicable.', $coupon->getCode()), $coupon); }

if (null !== $row['usagelimit'] && (int) $row['used'] >= (int) $row['usagelimit']) { throw new OptimisticLockException(sprintf('Promotion coupon "%s" is no longer applicable.', $coupon->getCode()), $coupon); }

if (null !== $row['percustomerusagelimit']) { $this->assertPerCustomerCouponUsageLimitNotReached( $coupon, $order, (int) $row['percustomerusagelimit'] ); }

$this->doExecuteStatement( 'UPDATE syliuspromotioncoupon SET used = used + 1 WHERE id = :id', ['id' => $coupon->getId()] );

$coupon->setUsed((int) $row['used'] + 1); }

private function assertPerCustomerCouponUsageLimitNotReached( PromotionCouponInterface $coupon, OrderInterface $order, int $perCustomerUsageLimit ): void { $customer = $order->getCustomer(); if (null === $customer || null === $customer->getId()) { return; }

$sql = 'SELECT o.id FROM syliusorder o WHERE o.customerid = :customerId AND o.promotioncouponid = :couponId AND o.state != :stateCart'; $params = [ 'customerId' => $customer->getId(), 'couponId' => $coupon->getId(), 'stateCart' => OrderInterface::STATECART, ];

if ($coupon->isReusableFromCancelledOrders()) { $sql .= ' AND o.state != :stateCancelled'; $params['stateCancelled'] = OrderInterface::STATECANCELLED; }

$sql .= ' FOR UPDATE';

$count = count($this->doFetchAllAssociative($sql, $params));

if ($count >= $perCustomerUsageLimit) { throw new OptimisticLockException(sprintf('Promotion coupon "%s" is no longer applicable.', $coupon->getCode()), $coupon); } }

private function decrementCouponUsage(PromotionCouponInterface $coupon): void { $this->doExecuteStatement( 'UPDATE syliuspromotioncoupon SET used = GREATEST(used - 1, 0) WHERE id = :id', ['id' => $coupon->getId()] );

$newUsed = (int) $this->doFetchOne( 'SELECT used FROM syliuspromotioncoupon WHERE id = :id', ['id' => $coupon->getId()] );

$coupon->setUsed($newUsed); }

/ @return int Number of affected rows / private function doExecuteStatement(string $sql, array $params): int { if (methodexists($this->connection, 'executeStatement')) { return $this->connection->executeStatement($sql, $params); }

return $this->connection->executeUpdate($sql, $params); }

/ @return mixed|false / private function doFetchOne(string $sql, array $params) { if (methodexists($this->connection, 'fetchOne')) { return $this->connection->fetchOne($sql, $params); }

return $this->connection->fetchColumn($sql, $params); }

/ @return array|false / private function doFetchAssociative(string $sql, array $params) { if (methodexists($this->connection, 'fetchAssociative')) { return $this->connection->fetchAssociative($sql, $params); }

return $this->connection->fetchAssoc($sql, $params); }

/ @return array[] / private function doFetchAllAssociative(string $sql, array $params): array { if (methodexists($this->connection, 'fetchAllAssociative')) { return $this->connection->fetchAllAssociative($sql, $params); }

return $this->connection->fetchAll($sql, $params); } }

Step 2. Register the service

Option A: If your app uses autowiring and supports the #[AsDecorator] attribute, uncomment it in the class and no further configuration is necessary.

Option B: Manually register the service in config/services.yaml:

yaml services: App\Modifier\AtomicOrderPromotionsUsageModifier: decorates: 'sylius.promotionusagemodifier' arguments: ['@doctrine.dbal.defaultconnection']

Step 3. Update exception mapping (optional)

Check if your apiplatform configuration maps OptimisticLockException to a code and update it if not: yaml apiplatform: ... exceptiontostatus: ... Doctrine\ORM\OptimisticLockException: 409

Step 4. 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: - Djibril Mounkoro (@whiteov3rflow) - Bartłomiej Nowiński (@bnBart)

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

1 / 2
Source: GitHub
First published (updated )
Severity
6.9
EPSS
0.04%
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:L/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Impact CurrencySwitchController::switchAction(), ImpersonateUserController::impersonateAction() and StorageBasedLocaleSwitcher::handle() use the HTTP Referer header directly when redirecting.

The attack requires the victim to click a legitimate application link placed on an attacker-controlled page. The browser automatically sends the attacker's site as the Referer, and the application redirects back to it. This can be used for phishing or credential theft, as the redirect originates from a trusted domain.

The severity varies by endpoint; public endpoints require no authentication and are trivially exploitable, while admin-only endpoints require an authenticated session but remain vulnerable if an admin follows a link from an external source such as email or chat.

Affected classes: - CurrencySwitchController::switchAction() - public - StorageBasedLocaleSwitcher::handle() - public, used in locale switching without having locale in the url - ImpersonateUserController::impersonateAction() - admin-only

Patches The issue is fixed in versions: 1.9.12, 1.10.16, 1.11.17, 1.12.23, 1.13.15, 1.14.18, 2.0.16, 2.1.12, 2.2.3 and above.

Workarounds If you cannot update Sylius immediately, copy the affected classes from vendor to your project's src/ directory, apply the fix, and override the service definitions.

Step 1 - CurrencySwitchController

Copy from vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Controller/CurrencySwitchController.php to src/Controller/CurrencySwitchController.php and apply the following changes:

diff -namespace Sylius\Bundle\ShopBundle\Controller; +namespace App\Controller;

use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Core\Currency\CurrencyStorageInterface; use Sylius\Component\Core\Model\ChannelInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\RouterInterface;

final class CurrencySwitchController { public function construct( private Environment $templatingEngine, // for 1.x version private CurrencyStorageInterface $currencyStorage, private ChannelContextInterface $channelContext, + private RouterInterface $router, ) { }

public function switchAction(Request $request, string $code): Response { / @var ChannelInterface $channel / $channel = $this->channelContext->getChannel();

$this->currencyStorage->set($channel, $code);

- return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost())); + return new RedirectResponse($this->router->generate('syliusshophomepage')); } }

Step 2 - ImpersonateUserController

Copy from vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/Controller/ImpersonateUserController.php to src/Controller/Admin/ImpersonateUserController.php and apply the following changes:

diff -namespace Sylius\Bundle\AdminBundle\Controller; +namespace App\Controller\Admin;

// ... (keep all existing use statements)

public function impersonateAction(Request $request, string $username): Response { // ... (keep authorization check and impersonation logic)

$this->addFlash($request, $username);

- $redirectUrl = $request->headers->get( - 'referer', + return new RedirectResponse( $this->router->generate('syliusadmincustomershow', ['id' => $user->getId()]) ); - - return new RedirectResponse($redirectUrl); }

Step 3 - StorageBasedLocaleSwitcher (only if you use localeswitcher: storage)

Note: Skip this step if you use the default localeswitcher: url mode.

Copy from vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Locale/StorageBasedLocaleSwitcher.php to src/Locale/StorageBasedLocaleSwitcher.php and apply the following changes:

For Sylius 1.9 – 2.1.2:

diff -namespace Sylius\Bundle\ShopBundle\Locale; +namespace App\Locale;

use Sylius\Bundle\ShopBundle\Locale\LocaleSwitcherInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Core\Locale\LocaleStorageInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\RouterInterface;

final class StorageBasedLocaleSwitcher implements LocaleSwitcherInterface { public function construct( private LocaleStorageInterface $localeStorage, private ChannelContextInterface $channelContext, + private RouterInterface $router, ) { }

public function handle(Request $request, string $localeCode): RedirectResponse { $this->localeStorage->set($this->channelContext->getChannel(), $localeCode);

- return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost())); + return new RedirectResponse($this->router->generate('syliusshophomepage')); } }

For Sylius 2.1.3 and later:

In Sylius 2.1.3 the class was refactored to use UrlMatcherInterface. While this adds partial validation, it still passes the full referer URL to RedirectResponse, so the open redirect remains exploitable.

diff -namespace Sylius\Bundle\ShopBundle\Locale; +namespace App\Locale;

use Sylius\Bundle\ShopBundle\Locale\LocaleSwitcherInterface; use Sylius\Component\Channel\Context\ChannelContextInterface; use Sylius\Component\Core\Locale\LocaleStorageInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Exception\ResourceNotFoundException; -use Symfony\Component\Routing\Matcher\UrlMatcherInterface; +use Symfony\Component\Routing\RouterInterface;

final class StorageBasedLocaleSwitcher implements LocaleSwitcherInterface { public function construct( private LocaleStorageInterface $localeStorage, private ChannelContextInterface $channelContext, - private ?UrlMatcherInterface $urlMatcher = null, + private RouterInterface $router, ) { - if (null === $this->urlMatcher) { - triggerdeprecation( - 'sylius/shop-bundle', - '2.1', - 'Not passing a "%s" to "%s" is deprecated and will be required in Sylius 3.0.', - UrlMatcherInterface::class, - self::class, - ); - } }

public function handle(Request $request, string $localeCode): RedirectResponse { $this->localeStorage->set($this->channelContext->getChannel(), $localeCode); - $url = $request->headers->get('referer', $request->getSchemeAndHttpHost()); - - if ($this->urlMatcher) { - try { - $this->urlMatcher->match($url); - } catch (ResourceNotFoundException) { - return new RedirectResponse($request->getSchemeAndHttpHost()); - } - } - - return new RedirectResponse($url); + return new RedirectResponse($this->router->generate('syliusshophomepage')); } }

Step 4 - Override the services

Add to config/services.yaml.

Sylius 1.x (1.9 – 1.14):

yaml services: # ... your existing services ...

sylius.controller.shop.currencyswitch: class: App\Controller\CurrencySwitchController public: true arguments: $templatingEngine: '@twig' $currencyStorage: '@sylius.storage.currency' $channelContext: '@sylius.context.channel' $router: '@router'

sylius.controller.shop.impersonateuser: class: App\Controller\Admin\ImpersonateUserController public: true arguments: $impersonator: '@sylius.admin.security.userimpersonator' $authorizationChecker: '@security.authorizationchecker' $userProvider: '@sylius.adminuserprovider.emailornamebased' $router: '@router' $authorizationRole: 'ROLEADMINISTRATIONACCESS'

# Only if you use localeswitcher: storage sylius.shop.localeswitcher: class: App\Locale\StorageBasedLocaleSwitcher public: false arguments: $localeStorage: '@sylius.storage.locale' $channelContext: '@sylius.context.channel' $router: '@router'

Sylius 2.x (2.0 – 2.1):

yaml services: # ... your existing services ...

syliusshop.controller.currencyswitch: class: App\Controller\CurrencySwitchController public: true arguments: $currencyStorage: '@sylius.storage.currency' $channelContext: '@sylius.context.channel' $router: '@router'

syliusadmin.controller.impersonateuser: class: App\Controller\Admin\ImpersonateUserController public: true arguments: $impersonator: '@syliusadmin.security.shopuserimpersonator' $authorizationChecker: '@security.authorizationchecker' $userProvider: '@sylius.shopuserprovider.emailornamebased' $router: '@router' $authorizationRole: 'ROLEADMINISTRATIONACCESS'

# Only if you use localeswitcher: storage syliusshop.localeswitcher: class: App\Locale\StorageBasedLocaleSwitcher public: false arguments: $localeStorage: '@sylius.storage.locale' $channelContext: '@sylius.context.channel' $router: '@router'

Step 5 - Clear cache

bash bin/console cache:clear

---

Customizing the redirect target

If you need a different redirect target, override the route definition with the sylius.redirect attribute:

yaml config/routes/syliusshop.yaml (AFTER the syliusshop resource import) syliusshopswitchcurrency: path: /{locale}/switch-currency/{code} methods: [GET] defaults: controller: sylius.controller.shop.currencyswitch:switchAction sylius: redirect: syliusshopproductindex # or any route name

Reporters

We would like to extend our gratitude to the following individuals for their detailed reporting and responsible disclosure of this vulnerability: - Bartłomiej Nowiński (@bnBart)

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

1 / 2
Source: GitHub
First published (updated )

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