# Why We Treat _bundlePrice as Attacker Input

Canonical: https://joinagentready.com/blog/why-we-treat-bundleprice-as-attacker-input

[By Dylan Hunt](https://joinagentready.com/authors/dylan-hunt) August 28th, 2026 [Checkout and Functions](https://joinagentready.com/blog/topics/checkout-functions)

Written by the Caffeine and Commerce team. For build work, see [caffeinecommerce.com](https://caffeinecommerce.com/).

Open DevTools on almost any Shopify store running a themed bundle builder and look at the cart payload. Somewhere in the line-item properties you'll find the theme talking to itself: `_bundlePrice: 2499`, `_starterSet: 1724631882`, `_bundleSize: 3`. Hints the storefront leaves so that something downstream (a script, an app, a discount) knows what the shopper built.

Here's the uncomfortable truth: **every one of those values is attacker-controllable.** Line-item properties and cart attributes are written by client-side code, which means they're written by whoever's holding the client. A shopper doesn't need a proxy or any real skill. `fetch('/cart/add.js', ...)` with a doctored `_bundlePrice` is a paste-into-console operation. If your discount logic _trusts_ that number, you've shipped a pricing API where the customer names their own discount.

We've reviewed setups where exactly that was live. Not because anyone was careless, really, because the theme and the discount grew up together, and the property started life as an internal note between two pieces of code the same developer controlled. Then the discount side started believing it.

## The rule

Our discount functions follow one rule, everywhere, no exceptions:

> **Client-written data may select an offer. Only merchant-owned data may price it.**

Concretely, in a Shopify Function:

-   `_bundlePrice` (client) says _what the shopper is asking for_. The function recovers the requested discount from it, and then **validates the amount against a trusted cap** stored in a variant metafield that only the merchant's admin (or our portal, with an authenticated Admin API token) can write. Request ≤ cap: the discount applies. Request > cap: the line is refused. A tampered cart can, at absolute worst, award itself the discount the merchant already approved.
-   `_starterSet` + the bundle's expected line count (client) say _these items came in together_. The function checks the **whole set is still in the cart** before any line qualifies. Remove one item and the rest stop pretending. Integrity, not pricing.
-   Matched quantities are computed as the **minimum across the bundle's lines**, so inflating one line's quantity can't over-claim. Same trick as in the [subscription-aware bundle](https://joinagentready.com/blog/subscription-aware-bundle-discounts-shopify-functions).
-   The trusted side (caps, pairings, campaign state) lives in metafields with reserved namespaces (`$app:`), which storefront code _cannot write at all_. That's the property that makes the whole design hold: the validation data has a different write-permission class than the claim data.

And because the logic runs as a Shopify Function, compiled WebAssembly executing inside Shopify's checkout, not a script tag a shopper can read or block, the validation isn't advisory. It's the only path to the discount. [What Shopify Functions can actually do](https://joinagentready.com/blog/what-shopify-functions-can-do-when-you-need-developer) covers the APIs; this is the security posture we put on every one of them.

This is also why a [Checkout Suite](https://caffeinecommerce.com/checkout-suite) build is not "the same widget, cheaper." The function is written against your metafields, your caps, your campaigns. A rented upsell app cannot make that write-permission split, because it does not own your admin.

## Test the binary, not the source

One more habit worth stealing: our fixture suites run against the **compiled `function.wasm`**, through the same runner Shopify uses, not just the JavaScript source. Unit tests prove the logic; the wasm fixtures prove the artifact, including the tampered-cart cases (`03-tampered-price-blocked.json` is our favorite filename in the repo). When the input query, the toolchain, or an API version changes, the thing that gets re-verified is the thing that actually runs at checkout.

None of this is exotic. It's the same lesson web security learned twenty years ago (never trust the client) applied to a place where the client is unusually well-dressed: your own theme, talking about money.

Caffeine and Commerce builds and audits custom discount functions for Shopify stores. If your bundle pricing trusts a line-item property, we'd genuinely love to look at it, before someone else does. Start a project.

Quick answers

## Frequently asked questions

**Can a shopper change \_bundlePrice from the browser?**

Yes. Line-item properties and cart attributes are written by client-side code. fetch('/cart/add.js', ...) with a doctored \_bundlePrice is a paste-into-console operation.

**What should a discount function trust instead?**

Merchant-owned metafields in reserved namespaces ($app:), which storefront code cannot write. Client-written data may select an offer. Only merchant-owned data may price it.

**Why test the compiled WASM instead of just the source?**

Unit tests prove the logic. Fixtures against function.wasm prove the artifact Shopify actually executes at checkout, including tampered-cart cases.

Dylan Hunt

Author

[Dylan Hunt](https://joinagentready.com/authors/dylan-hunt)

Builds Shopify catalog readability and AI answer visibility at AgentReady and Caffeine and Commerce.

[About Dylan →](https://joinagentready.com/authors/dylan-hunt)

## Comments

Every comment here comes from a verified email. Write yours, confirm from your inbox, and it's live.

Loading comments…

Share [X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fjoinagentready.com%2Fblog%2Fwhy-we-treat-bundleprice-as-attacker-input&text=Why%20We%20Treat%20_bundlePrice%20as%20Attacker%20Input) [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fjoinagentready.com%2Fblog%2Fwhy-we-treat-bundleprice-as-attacker-input) [Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fjoinagentready.com%2Fblog%2Fwhy-we-treat-bundleprice-as-attacker-input)

Written by [Dylan Hunt](https://joinagentready.com/authors/dylan-hunt), Founder, AgentReady. AgentReady audits Shopify structured data and checks approved changes on the live storefront. [See plans](https://joinagentready.com/pricing).

For Shopify today

### Schema for AI

Make your Shopify catalog easier for AI to understand.

From $9/mo

[Run free audit →](https://joinagentready.com/tools/shopify-ai-readiness-checker) [Explore Schema for AI](https://joinagentready.com/features/structured-data)

Free guide

### The Shopify Functions Playbook

25 real things you can build with Functions, with the plan requirements and limits stated plainly. Emailed to you, readable immediately.

More in Checkout and Functions

-   [Subscription-Aware Bundle Discounts with Shopify Functions](https://joinagentready.com/blog/subscription-aware-bundle-discounts-shopify-functions)
-   [What Rebuy's Monthly Fee Actually Pays For (and When a Custom Function Is Cheaper)](https://joinagentready.com/blog/what-rebuys-monthly-fee-actually-pays-for)
-   [Shopify Scripts Are Gone for Good: How to Replace Your Discount Scripts](https://joinagentready.com/blog/shopify-scripts-gone-replace-discount-scripts)
-   [Post-Purchase Upsells on Shopify: How They Work and When They Don't](https://joinagentready.com/blog/post-purchase-upsells-shopify-extensions)

[See all in Checkout and Functions →](https://joinagentready.com/blog/topics/checkout-functions)
