Skip to content

Commit 9b9e964

Browse files
1 parent 8cb1b4a commit 9b9e964

5 files changed

Lines changed: 751 additions & 0 deletions

File tree

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-7mp4-25j8-hp5q",
4+
"modified": "2026-03-11T00:13:29Z",
5+
"published": "2026-03-11T00:13:29Z",
6+
"aliases": [
7+
"CVE-2026-31824"
8+
],
9+
"summary": "Sylius has a Promotion Usage Limit Bypass via Race Condition",
10+
"details": "### Impact\nA 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:\n\n1. **Promotion usage limit** - the global `used` counter on `Promotion` entities\n2. **Coupon usage limit** - the global `used` counter on `PromotionCoupon` entities\n3. **Coupon per-customer usage limit** - the per-customer redemption count on `PromotionCoupon` entities\n\nIn 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.\n\nBecause 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.\n\nAn 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.\n\nThis may lead to direct financial loss through unlimited redemption of limited-use promotions and discount coupons.\n\n### Patches\nThe 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.\n\n### Workarounds\n\nDecoration of the `OrderPromotionsUsageModifier` service to use atomic operations based on actual database-synchronized values.\n\nThe decorated service id in Sylius >=2.0 is `sylius.modifier.promotion.order_usage`, while <2.0 it's `sylius.promotion_usage_modifier`; The following instruction uses the latter, but it needs to be changed depending on the Sylius version.\n\n#### Step 1. Create the decorator service\n\n`src/Modifier/AtomicOrderPromotionsUsageModifier.php`:\n\n```php\n<?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Modifier;\n\nuse Doctrine\\DBAL\\Connection;\nuse Doctrine\\ORM\\OptimisticLockException;\nuse Sylius\\Component\\Core\\Model\\OrderInterface;\nuse Sylius\\Component\\Core\\Model\\PromotionCouponInterface;\nuse Sylius\\Component\\Core\\Promotion\\Modifier\\OrderPromotionsUsageModifierInterface;\nuse Sylius\\Component\\Promotion\\Model\\PromotionInterface;\n// use Symfony\\Component\\DependencyInjection\\Attribute\\AsDecorator;\n\n// #[AsDecorator(decorates: 'sylius.promotion_usage_modifier')]\nfinal class AtomicOrderPromotionsUsageModifier implements OrderPromotionsUsageModifierInterface\n{\n /** @var Connection */\n private $connection;\n\n public function __construct(Connection $connection)\n {\n $this->connection = $connection;\n }\n\n public function increment(OrderInterface $order): void\n {\n foreach ($order->getPromotions() as $promotion) {\n $this->incrementPromotionUsage($promotion);\n }\n\n /** @var PromotionCouponInterface|null $coupon */\n $coupon = $order->getPromotionCoupon();\n if (null === $coupon) {\n return;\n }\n\n $this->incrementCouponUsage($coupon, $order);\n }\n\n public function decrement(OrderInterface $order): void\n {\n foreach ($order->getPromotions() as $promotion) {\n $this->decrementPromotionUsage($promotion);\n }\n\n /** @var PromotionCouponInterface|null $coupon */\n $coupon = $order->getPromotionCoupon();\n if (null === $coupon) {\n return;\n }\n\n if (OrderInterface::STATE_CANCELLED === $order->getState() && !$coupon->isReusableFromCancelledOrders()) {\n return;\n }\n\n $this->decrementCouponUsage($coupon);\n }\n\n private function incrementPromotionUsage(PromotionInterface $promotion): void\n {\n $affected = $this->doExecuteStatement(\n 'UPDATE sylius_promotion\n SET used = used + 1\n WHERE id = :id AND (usage_limit IS NULL OR used < usage_limit)',\n ['id' => $promotion->getId()]\n );\n\n if (0 === $affected) {\n throw new OptimisticLockException(sprintf('Promotion \"%s\" is no longer applicable.', $promotion->getCode()), $promotion);\n }\n\n $newUsed = (int) $this->doFetchOne(\n 'SELECT used FROM sylius_promotion WHERE id = :id',\n ['id' => $promotion->getId()]\n );\n\n $promotion->setUsed($newUsed);\n }\n\n private function decrementPromotionUsage(PromotionInterface $promotion): void\n {\n $this->doExecuteStatement(\n 'UPDATE sylius_promotion SET used = GREATEST(used - 1, 0) WHERE id = :id',\n ['id' => $promotion->getId()]\n );\n\n $newUsed = (int) $this->doFetchOne(\n 'SELECT used FROM sylius_promotion WHERE id = :id',\n ['id' => $promotion->getId()]\n );\n\n $promotion->setUsed($newUsed);\n }\n\n private function incrementCouponUsage(PromotionCouponInterface $coupon, OrderInterface $order): void\n {\n $row = $this->doFetchAssociative(\n 'SELECT used, usage_limit, per_customer_usage_limit FROM sylius_promotion_coupon WHERE id = :id FOR UPDATE',\n ['id' => $coupon->getId()]\n );\n\n if (false === $row) {\n throw new OptimisticLockException(sprintf('Promotion coupon \"%s\" is no longer applicable.', $coupon->getCode()), $coupon);\n }\n\n if (null !== $row['usage_limit'] && (int) $row['used'] >= (int) $row['usage_limit']) {\n throw new OptimisticLockException(sprintf('Promotion coupon \"%s\" is no longer applicable.', $coupon->getCode()), $coupon);\n }\n\n if (null !== $row['per_customer_usage_limit']) {\n $this->assertPerCustomerCouponUsageLimitNotReached(\n $coupon,\n $order,\n (int) $row['per_customer_usage_limit']\n );\n }\n\n $this->doExecuteStatement(\n 'UPDATE sylius_promotion_coupon SET used = used + 1 WHERE id = :id',\n ['id' => $coupon->getId()]\n );\n\n $coupon->setUsed((int) $row['used'] + 1);\n }\n\n private function assertPerCustomerCouponUsageLimitNotReached(\n PromotionCouponInterface $coupon,\n OrderInterface $order,\n int $perCustomerUsageLimit\n ): void {\n $customer = $order->getCustomer();\n if (null === $customer || null === $customer->getId()) {\n return;\n }\n\n $sql = 'SELECT o.id FROM sylius_order o\n WHERE o.customer_id = :customerId\n AND o.promotion_coupon_id = :couponId\n AND o.state != :stateCart';\n $params = [\n 'customerId' => $customer->getId(),\n 'couponId' => $coupon->getId(),\n 'stateCart' => OrderInterface::STATE_CART,\n ];\n\n if ($coupon->isReusableFromCancelledOrders()) {\n $sql .= ' AND o.state != :stateCancelled';\n $params['stateCancelled'] = OrderInterface::STATE_CANCELLED;\n }\n\n $sql .= ' FOR UPDATE';\n\n $count = count($this->doFetchAllAssociative($sql, $params));\n\n if ($count >= $perCustomerUsageLimit) {\n throw new OptimisticLockException(sprintf('Promotion coupon \"%s\" is no longer applicable.', $coupon->getCode()), $coupon);\n }\n }\n\n private function decrementCouponUsage(PromotionCouponInterface $coupon): void\n {\n $this->doExecuteStatement(\n 'UPDATE sylius_promotion_coupon SET used = GREATEST(used - 1, 0) WHERE id = :id',\n ['id' => $coupon->getId()]\n );\n\n $newUsed = (int) $this->doFetchOne(\n 'SELECT used FROM sylius_promotion_coupon WHERE id = :id',\n ['id' => $coupon->getId()]\n );\n\n $coupon->setUsed($newUsed);\n }\n\n /** @return int Number of affected rows */\n private function doExecuteStatement(string $sql, array $params): int\n {\n if (method_exists($this->connection, 'executeStatement')) {\n return $this->connection->executeStatement($sql, $params);\n }\n\n return $this->connection->executeUpdate($sql, $params);\n }\n\n /** @return mixed|false */\n private function doFetchOne(string $sql, array $params)\n {\n if (method_exists($this->connection, 'fetchOne')) {\n return $this->connection->fetchOne($sql, $params);\n }\n\n return $this->connection->fetchColumn($sql, $params);\n }\n\n /** @return array|false */\n private function doFetchAssociative(string $sql, array $params)\n {\n if (method_exists($this->connection, 'fetchAssociative')) {\n return $this->connection->fetchAssociative($sql, $params);\n }\n\n return $this->connection->fetchAssoc($sql, $params);\n }\n\n /** @return array[] */\n private function doFetchAllAssociative(string $sql, array $params): array\n {\n if (method_exists($this->connection, 'fetchAllAssociative')) {\n return $this->connection->fetchAllAssociative($sql, $params);\n }\n\n return $this->connection->fetchAll($sql, $params);\n }\n}\n```\n\n#### Step 2. Register the service\n\n**Option A:** If your app uses autowiring and supports the `#[AsDecorator]` attribute, uncomment it in the class and no further configuration is necessary.\n\n**Option B:** Manually register the service in `config/services.yaml`:\n\n```yaml\nservices:\n App\\Modifier\\AtomicOrderPromotionsUsageModifier:\n decorates: 'sylius.promotion_usage_modifier'\n arguments: ['@doctrine.dbal.default_connection']\n```\n\n#### Step 3. Update exception mapping (optional)\n\nCheck if your `api_platform` configuration maps `OptimisticLockException` to a code and update it if not:\n```yaml\napi_platform:\n ...\n exception_to_status:\n ...\n Doctrine\\ORM\\OptimisticLockException: 409\n```\n\n#### Step 4. 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- @whiteov3rflow\n- Bartłomiej Nowiński\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n\n- Open an issue in [Sylius issues](https://github.com/Sylius/Sylius/issues)\n- Email us at [security@sylius.com](mailto:security@sylius.com)",
11+
"severity": [
12+
{
13+
"type": "CVSS_V3",
14+
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:L"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "Packagist",
21+
"name": "sylius/sylius"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "1.9.12"
32+
}
33+
]
34+
}
35+
],
36+
"database_specific": {
37+
"last_known_affected_version_range": "<= 1.9.11"
38+
}
39+
},
40+
{
41+
"package": {
42+
"ecosystem": "Packagist",
43+
"name": "sylius/sylius"
44+
},
45+
"ranges": [
46+
{
47+
"type": "ECOSYSTEM",
48+
"events": [
49+
{
50+
"introduced": "1.10.0"
51+
},
52+
{
53+
"fixed": "1.10.16"
54+
}
55+
]
56+
}
57+
],
58+
"database_specific": {
59+
"last_known_affected_version_range": "<= 1.10.15"
60+
}
61+
},
62+
{
63+
"package": {
64+
"ecosystem": "Packagist",
65+
"name": "sylius/sylius"
66+
},
67+
"ranges": [
68+
{
69+
"type": "ECOSYSTEM",
70+
"events": [
71+
{
72+
"introduced": "1.11.0"
73+
},
74+
{
75+
"fixed": "1.11.17"
76+
}
77+
]
78+
}
79+
],
80+
"database_specific": {
81+
"last_known_affected_version_range": "<= 1.11.16"
82+
}
83+
},
84+
{
85+
"package": {
86+
"ecosystem": "Packagist",
87+
"name": "sylius/sylius"
88+
},
89+
"ranges": [
90+
{
91+
"type": "ECOSYSTEM",
92+
"events": [
93+
{
94+
"introduced": "1.12.0"
95+
},
96+
{
97+
"fixed": "1.12.23"
98+
}
99+
]
100+
}
101+
],
102+
"database_specific": {
103+
"last_known_affected_version_range": "<= 1.12.22"
104+
}
105+
},
106+
{
107+
"package": {
108+
"ecosystem": "Packagist",
109+
"name": "sylius/sylius"
110+
},
111+
"ranges": [
112+
{
113+
"type": "ECOSYSTEM",
114+
"events": [
115+
{
116+
"introduced": "1.13.0"
117+
},
118+
{
119+
"fixed": "1.13.15"
120+
}
121+
]
122+
}
123+
],
124+
"database_specific": {
125+
"last_known_affected_version_range": "<= 1.13.14"
126+
}
127+
},
128+
{
129+
"package": {
130+
"ecosystem": "Packagist",
131+
"name": "sylius/sylius"
132+
},
133+
"ranges": [
134+
{
135+
"type": "ECOSYSTEM",
136+
"events": [
137+
{
138+
"introduced": "1.14.0"
139+
},
140+
{
141+
"fixed": "1.14.18"
142+
}
143+
]
144+
}
145+
],
146+
"database_specific": {
147+
"last_known_affected_version_range": "<= 1.14.17"
148+
}
149+
},
150+
{
151+
"package": {
152+
"ecosystem": "Packagist",
153+
"name": "sylius/sylius"
154+
},
155+
"ranges": [
156+
{
157+
"type": "ECOSYSTEM",
158+
"events": [
159+
{
160+
"introduced": "2.0.0"
161+
},
162+
{
163+
"fixed": "2.0.16"
164+
}
165+
]
166+
}
167+
],
168+
"database_specific": {
169+
"last_known_affected_version_range": "<= 2.0.15"
170+
}
171+
},
172+
{
173+
"package": {
174+
"ecosystem": "Packagist",
175+
"name": "sylius/sylius"
176+
},
177+
"ranges": [
178+
{
179+
"type": "ECOSYSTEM",
180+
"events": [
181+
{
182+
"introduced": "2.1.0"
183+
},
184+
{
185+
"fixed": "2.1.12"
186+
}
187+
]
188+
}
189+
],
190+
"database_specific": {
191+
"last_known_affected_version_range": "<= 2.1.11"
192+
}
193+
},
194+
{
195+
"package": {
196+
"ecosystem": "Packagist",
197+
"name": "sylius/sylius"
198+
},
199+
"ranges": [
200+
{
201+
"type": "ECOSYSTEM",
202+
"events": [
203+
{
204+
"introduced": "2.2.0"
205+
},
206+
{
207+
"fixed": "2.2.3"
208+
}
209+
]
210+
}
211+
],
212+
"database_specific": {
213+
"last_known_affected_version_range": "<= 2.2.2"
214+
}
215+
}
216+
],
217+
"references": [
218+
{
219+
"type": "WEB",
220+
"url": "https://github.com/Sylius/Sylius/security/advisories/GHSA-7mp4-25j8-hp5q"
221+
},
222+
{
223+
"type": "PACKAGE",
224+
"url": "https://github.com/Sylius/Sylius"
225+
}
226+
],
227+
"database_specific": {
228+
"cwe_ids": [
229+
"CWE-362",
230+
"CWE-367"
231+
],
232+
"severity": "HIGH",
233+
"github_reviewed": true,
234+
"github_reviewed_at": "2026-03-11T00:13:29Z",
235+
"nvd_published_at": null
236+
}
237+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-hqmh-ppp3-xvm7",
4+
"modified": "2026-03-11T00:14:02Z",
5+
"published": "2026-03-11T00:14:02Z",
6+
"aliases": [
7+
"CVE-2026-31826"
8+
],
9+
"summary": "pypdf: manipulated stream length values can exhaust RAM",
10+
"details": "### Impact\n\nAn attacker who uses this vulnerability can craft a PDF which leads to large memory usage. This requires parsing a content stream with a rather large `/Length` value, regardless of the actual data length inside the stream.\n\n### Patches\nThis has been fixed in [pypdf==6.8.0](https://github.com/py-pdf/pypdf/releases/tag/6.8.0).\n\n### Workarounds\nIf you cannot upgrade yet, consider applying the changes from PR [#3675](https://github.com/py-pdf/pypdf/pull/3675).\n\nAs far as we are aware, this mostly affects reading from buffers of unknown size, as returned by `open(\"file.pdf\", mode=\"rb\")` for example. Passing a file path or a `BytesIO` buffer to *pypdf* instead does not seem to trigger the vulnerability.",
11+
"severity": [
12+
{
13+
"type": "CVSS_V4",
14+
"score": "CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "PyPI",
21+
"name": "pypdf"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "6.8.0"
32+
}
33+
]
34+
}
35+
]
36+
}
37+
],
38+
"references": [
39+
{
40+
"type": "WEB",
41+
"url": "https://github.com/py-pdf/pypdf/security/advisories/GHSA-hqmh-ppp3-xvm7"
42+
},
43+
{
44+
"type": "WEB",
45+
"url": "https://github.com/py-pdf/pypdf/pull/3675"
46+
},
47+
{
48+
"type": "WEB",
49+
"url": "https://github.com/py-pdf/pypdf/commit/3c550b3196adeba1506a26e57c09c09fac75e9aa"
50+
},
51+
{
52+
"type": "PACKAGE",
53+
"url": "https://github.com/py-pdf/pypdf"
54+
},
55+
{
56+
"type": "WEB",
57+
"url": "https://github.com/py-pdf/pypdf/releases/tag/6.8.0"
58+
}
59+
],
60+
"database_specific": {
61+
"cwe_ids": [
62+
"CWE-770"
63+
],
64+
"severity": "MODERATE",
65+
"github_reviewed": true,
66+
"github_reviewed_at": "2026-03-11T00:14:02Z",
67+
"nvd_published_at": null
68+
}
69+
}

0 commit comments

Comments
 (0)