Tax rate is applied correctly based on customer location jurisdiction
Why it matters
A single hardcoded tax rate applied to every location — 8.5% regardless of whether the customer is in California, a no-sales-tax state like Oregon, or a VAT jurisdiction in the EU — is both a CWE-682 calculation error and a regulatory compliance failure. South Dakota v. Wayfair (2018) established economic nexus, meaning multi-state sellers must collect destination-state rates. EU VAT Directive 2006/112/EC imposes separate VAT obligations for digital and physical goods sold in EU member states. Overcharging customers in no-tax jurisdictions exposes the business to refund liability; undercharging in mandatory-tax states exposes it to audit penalties and back-tax assessments.
Severity rationale
Critical because applying a flat tax rate to all jurisdictions produces regulatory non-compliance with Wayfair nexus rules and EU VAT obligations, exposing the business to both back-tax liability and customer overcharge disputes.
Remediation
Implement jurisdiction-aware tax lookup in lib/tax.ts using a tax service API or a local rate table with at least 5 distinct jurisdiction entries:
// lib/tax.ts
async function getTaxRate(address: Address): Promise<number> {
// Option 1: TaxJar (handles Wayfair nexus + VAT automatically)
const result = await taxjar.rates.get(address.zip, {
state: address.state,
country: address.country,
})
return result.combined_rate
// Option 2: Local table (must cover all states you serve)
const key = `${address.country}-${address.state}`
return TAX_RATES[key] ?? 0
}
Never return a hardcoded constant from getTaxRate. If using a local table, ensure it includes at least your nexus states and correctly maps zero-rate jurisdictions (OR, MT, NH, DE, AK) to 0.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Shipping & Tax Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-682 — Incorrect Calculation
- iso-25010:2011 · functional-correctness — Functional Correctness (Functional Suitability)
- external · south-dakota-v-wayfair-2018 — South Dakota v. Wayfair, Inc. — US economic nexus standard requiring destination-based sales tax collection
- external · eu-vat-directive-2006-112-ec — EU VAT Directive 2006/112/EC — jurisdiction-based VAT rate determination for digital and physical goods
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ecommerce-shipping-tax·automated