Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

fix(core): reject client-supplied prices when adding store cart line items (#1546)

Viktor Holikb4678b2f7ed1
diff --git a/integration-tests/http/offer/cart/cart.spec.ts b/integration-tests/http/offer/cart/cart.spec.ts
index f0674783b..9772bac94 100644
--- a/integration-tests/http/offer/cart/cart.spec.ts
+++ b/integration-tests/http/offer/cart/cart.spec.ts
@@ -220,6 +220,37 @@ medusaIntegrationTestRunner({
expect(line.quantity).toEqual(2)
})
+ it.each([
+ { unit_price: 1 },
+ { unit_price: 0 },
+ { compare_at_unit_price: 1 },
+ ])("should reject a client-supplied price %p", async (price) => {
+ const seed: SellerSeed = await seedSellerOffer({
+ email: `client-price-${Object.values(price)[0]}-${Object.keys(price)[0]}@test.com`,
+ name: "Client Price",
+ stocked: 10,
+ offerPrice: 5700,
+ })
+
+ const cart = await createCart()
+
+ const response = await api
+ .post(
+ `/store/carts/${cart.id}/line-items`,
+ { offer_id: seed.offer.id, quantity: 1, ...price },
+ storeHeaders
+ )
+ .catch((e) => e.response)
+
+ expect(response.status).toEqual(400)
+
+ const { data } = await api.get(
+ `/store/carts/${cart.id}`,
+ storeHeaders
+ )
+ expect(data.cart.items).toHaveLength(0)
+ })
+
// SPEC-007: buybox preselection guarantees one offer per
// variant per cart. Medusa's default add-to-cart merges
// same-variant lines into a single line, which is the
diff --git a/packages/core/src/api/store/carts/[id]/line-items/validators.ts b/packages/core/src/api/store/carts/[id]/line-items/validators.ts
index 28e8fa27f..b7a0493b1 100644
--- a/packages/core/src/api/store/carts/[id]/line-items/validators.ts
+++ b/packages/core/src/api/store/carts/[id]/line-items/validators.ts
@@ -4,8 +4,6 @@ export const StoreAddCartLineItem = z
.object({
offer_id: z.string().min(1, "offer_id is required"),
quantity: z.number().int().positive(),
- unit_price: z.number().optional(),
- compare_at_unit_price: z.number().optional(),
metadata: z.record(z.unknown()).optional(),
additional_data: z.record(z.unknown()).optional(),
})