Frontend Calculation Manipulation

Client-side price manipulation vulnerabilities and the critical importance of server-side validation.

Overview

Frontend calculation manipulation occurs when applications perform sensitive calculations like pricing, discounts, or totals in the browser. Attackers can modify these calculations by manipulating JavaScript code, intercepting requests, or using browser developer tools.

Type: Client-Side Manipulation
Affected: E-commerce, Financial Applications
Impact: Price manipulation, unauthorized discounts
CVSS: 6.5 (Medium)

The Vulnerability

Many web applications calculate final prices, discounts, and totals in the browser using JavaScript. While this provides a smooth user experience, it creates a critical security flaw. Attackers can easily modify these calculations using browser developer tools, browser extensions, or by intercepting and modifying requests.

Technical Details

The vulnerable application calculated discounts client-side and sent the final discounted price to the server. The server accepted this price without recalculating or validating that the discount was legitimate.

// Vulnerable client-side code function applyDiscount(originalPrice, discountCode) { const discounts = { 'SAVE10': 0.10, 'SAVE20': 0.20 }; const discountPercent = discounts[discountCode] || 0; const finalPrice = originalPrice * (1 - discountPercent); // Send discounted price to server fetch('/api/checkout', { method: 'POST', body: JSON.stringify({ finalPrice }) }); }

Attack Scenario

// Intercepted and modified request POST /api/checkout HTTP/1.1 Host: example-shop.com { "items": [/* cart items */], "finalPrice": 10.00, // Manipulated from 90.00 "discountCode": "SAVE10" }

Real-World Examples

Root Cause

Remediation

// Secure server-side implementation app.post('/api/checkout', authenticate, async (req, res) => { const userId = req.user.id; // Get cart from server-side session/database const cart = await getCartFromDatabase(userId); const originalTotal = calculateCartTotal(cart); // Validate discount code server-side let finalTotal = originalTotal; if (req.body.discountCode) { const discount = await validateDiscountCode( req.body.discountCode, originalTotal ); finalTotal = applyDiscount(originalTotal, discount); } // Process payment with server-calculated total const payment = await processPayment(userId, finalTotal); res.json({ success: true, total: finalTotal }); });

Timeline

Secure your application