Checkout pages like a promo field that updates the total before the customer clicks Pay. The usual shortcut is a map of codes to percent-off, SKU gates, and stacking rules in a JavaScript chunk or a /promos.json next to the cart.
The browser can only apply a code it already has. This article is about what a client-side promo table actually exposes, which decisions should go back to a server, and how to protect an offline estimate without treating the table as a secret.
The codes are a public download
A typical "instant discount" helper looks like this:
export function applyPromo(code, cart) {
const rule = PROMOS[code.trim().toUpperCase()];
if (!rule || Date.parse(rule.expires) < Date.now()) return cart;
if (!eligible(cart, rule)) return cart;
return { ...cart, discount: stack(cart, rule) };
}
After a production build, PROMOS lives in the same origin or CDN as the rest of the checkout: every code, the percent or fixed amount, the minimum subtotal, the SKU allow-list, whether two codes can stack, and often a hidden or partner flag the UI uses to keep a row out of the "available offers" list.
A visitor can:
- Pretty-print the chunk or download
/promos.jsonand read every code, including ones the banner never mentions. - Call
applyPromofrom the console with a staff or influencer code the form would have rejected. - Patch
eligibleorrule.minSubtotaland screenshot a fake total. - Harvest "expired" rows that the client still honors because nobody trimmed the file.
A content hash in the filename is a cache-busting token, not an access token. If the checkout chunk mentions the file, the table is public.
A hidden row is not an access control
Minifying the bundle will rename applyPromo. It will not hide LAUNCH30, a partner code reserved for one retailer, or a distinctive stacking function that decides whether free shipping combines with a percent off.
Showing a crossed-out price in the tab is a convenience. The number that is charged has to be computed — or at least confirmed — after the server has checked the account, the inventory, and the real promo ledger. A plan check that "unlocks" a VIP code is a UI branch; if the code is already in PROMOS, a visitor does not need to pass your if.
Client-side estimates are still the right call for a lot of work: a rough "this might apply" hint, a public storewide code you print on a billboard, a shipping preview that the API will recompute. The problem starts when the table is the campaign — unpublished influencer codes, employee discounts, first-order stacks, or a one-time code whose mere existence tells a competitor what you are testing.
What to leave on the server
Some pieces should never ship in a public asset directory:
- Unpublished, partner, employee, or single-use codes, and any ledger that reveals a campaign you have not announced.
- The authoritative discount, tax, and payable total that you will charge or print on an invoice.
- Stacking, eligibility, and expiry rules that must stay consistent with billing.
- Gift-card or store-credit balances that you were tempted to cache in the cart chunk.
The browser can still let the user type a code, show a pending state, and render the total the API returns. The amount you commit to does not have to be computed in the tab.
What to protect in the client
You may still need a slice of logic on the device: an offline preview for a kiosk that must work with a cached public catalog, or a compact formatter that turns an already-approved discount into a line item. For that slice:
- Keep the real promo ledger, unpublished codes, and the payable total on the server.
- Minify the app as usual; leave the cart or payments SDK alone.
- Extract the public estimate helper if you must ship one, and apply a real protection pass — identifier renaming and string tables as a floor, VM-style protection if wholesale reuse of the stacking function is the risk you care about.
- Keep production source maps and unused promo files off the public CDN.
A JS VM obfuscator compiles that function to a custom bytecode and ships a small interpreter. Pretty-printing the chunk no longer reconstructs the original stack; you get bytecode and a dispatcher. That is slower than a bare lookup, which is why you protect a proprietary estimator, not the checkout SDK, and why protection is not a substitute for a server-side redeem.
VEILVM is a browser-based JSVMP workspace you can point at one extracted function before you wire protection into CI. Protection raises the cost of casual inspection and wholesale reuse. It does not make a downloadable promo table a secret, and it does not replace a server-side redeem for anything that affects what you charge.
Checklist
- [ ] Unpublished, partner, and employee codes are not sitting in a public
/promos.jsonnext to the cart. - [ ] Payable totals, tax, and stacking are computed or re-checked on the server after entitlements.
- [ ] The payments or cart SDK is left alone; only your estimate helper is a candidate for protection.
- [ ] UI flags that "hide" a row are not treated as access control for the file that contains it.
- [ ] Production source maps are not downloadable from the CDN.
- [ ] End-to-end tests redeem a fixture code against the minified (and, if applicable, protected) production checkout and the real API.
If you want to try VM protection on a single extracted function, VEILVM runs in the browser with no sign-up: 3 free runs a day, up to 5 KB per file (resets at 00:00 UTC). A free account raises the input limit to 30 KB. Pro is $9/month or $79/year and adds an API so the protection step can run in CI. Standard requests are processed in memory and are not written to logs. Start at https://vm.ldvmp.com.
Top comments (0)