====== #134 — Monetary amount fields have no upper-bound / sanity validation — a single entry can inflate a total by any magnitude. (Resolved) ====== [[wiki:manara:bugs|← Back to Manara Bugs]] · [[https://mantis.matrixdn.net/view.php?id=134|View issue #134 in MantisBT]] ---- **Reported by:** Khaled Tarabay on 2026-07-28T13:28:23+01:00\\ **Assigned to:** Claude\\ **Resolved by:** Claude on 2026-07-28T14:26:44+01:00\\ **Severity:** major\\ **Priority:** high\\ **Reproducibility:** always\\ **Category:** General **Description:** Neither the invoice line-item unit_price field nor the Reconciliation session's manual_amount field enforces any reasonable ceiling. Both accept arbitrarily large numbers and fold them straight into totals and dashboard aggregates with zero warning, confirmation step, or error. On a fresh invoice, adding a line item with unit_price = 999999999999.99 and quantity = 1 was accepted with no validation error at all, immediately setting that invoice's own Total, and once Issued, spiking the Business Overview dashboard's "Total Invoiced" tile from a normal $6,020.34 (this month) straight to $1,000,000,006,020.33 confirmed by reading the tile before and after the same real Issue action, then watching it drop back to exactly $6,020.34 the moment the invoice was voided, proving the arithmetic itself (addition, and Void's exclusion from the aggregate) is correct and the only failure is the missing ceiling on the input. The identical gap exists in a completely different module: on a fresh Reconciliation session, entering manual_amount = 999999999999.99 against a system_amount of $50.00 was accepted with no error, producing a line with a $999,999,999,949.99 discrepancy sitting in that session's own total. Two unrelated modules sharing the exact same missing guard is a strong signal this is a systemic gap in how the app validates currency inputs generally, rather than an isolated oversight in one form every other amount field tested this session (payment amount, wallet credit/debit amount, refund amount, payroll pay amount) does at minimum enforce a relative cap (can't exceed the specific balance/cap it's being measured against), but none of them were tested against an absolute ceiling independent of context, so this class of gap may be broader than just these two fields. The fix should add a server-side sanity ceiling on every currency-amount field in the app (a generous but finite bound e.g. reject anything above some multiple of the largest plausible real invoice, such as $1,000,000 is enough to stop both fat-finger typos like an extra digit and any deliberate attempt to corrupt dashboard totals), and ideally a client-side warning/confirmation step for unusually large amounts even under that ceiling, since a legitimate five- or six-figure invoice should still be easy to enter without friction while a twelve-digit one should never silently succeed. **Steps to Reproduce:** Create any invoice, add a charge with description "Huge Price", Unit Price 999999999999.99, Quantity 1. Confirm it's accepted with no field error and the invoice Total becomes $999,999,999,999.99. Set the invoice to Issued. Open the Business Overview dashboard (/dashboard) and note the "Total Invoiced" tile has jumped by roughly a trillion dollars. Separately, open Reconciliation → + Open Session for today's date, add a line with System Amount 50.00 and Manual Amount 999999999999.99. Confirm it's accepted with no error and the line's Discrepancy reads $999,999,999,949.99. Both records were voided/deleted immediately after confirming, so no corrupted data is currently live in the tenant but nothing in the app itself would have stopped either from staying there indefinitely. **Resolution:** FIXED. What: no currency-amount field in the app enforced any upper ceiling. Money columns are DECIMAL(14,2), so the DB itself accepts up to 999,999,999,999.99 (~a trillion), and an invoice line-item unit_price or a reconciliation manual_amount of exactly that was accepted with no error and folded straight into the invoice total / session total / dashboard aggregates. As the ticket correctly diagnosed, the arithmetic (addition, and Void's exclusion) was already right — the only failure was the missing input ceiling, and it was systemic: 20 money fields across 18 controller methods (two of which were the reported repro paths) all validated numeric + usually non-negative but had NO upper bound. Where + how fixed: - app/classes/Core/Validator.php — new reusable ceiling: const MAX_MONEY = 100000000.0 ($100,000,000), a fluent moneyMax($field,$label) for the fluent-Validator sites, and a static exceedsMoneyCeiling($value) for imperative/JSON call sites. Chose $100M (not the ticket's suggested $1M minimum) so no plausible real single amount in an ISP/CRM's books is ever falsely rejected, while still being 10,000x below the column's own limit — it decisively blocks a fat-finger extra digit or a deliberate corruption attempt. One tunable constant. - Applied to EVERY money field found (exhaustive sweep): invoice line unit_price + derived line-total quantity*unit_price (BillingController::validateItem AND the JSON Api/InvoiceApiController::addItem), reconciliation system_amount + manual_amount (ReconciliationController::validateLine), payment amount (PaymentController + Api/PaymentApiController), wallet amount (WalletController), expense amount (TransactionController), credit/refund amount (CreditNoteController), contact purchase/sale + payment amount (ContactController), payroll pay amount (PayrollController), employee monthly_salary — currency branch only, the commission-percentage 0-100 branch is left as is (EmployeeController), service plan price (ServicePlanController + Api/ServicePlanApiController), maintenance amount (MaintenanceController), installation amount (InstallationController), vehicle fuel cost (FleetController), inventory unit_cost on both create/edit and restock (InventoryController), task close-out collected_amount (TaskController), and the platform console's tenant price_override + package price (Console/TenantsController + Console/PackagesController). - Client-side: added max="100000000" to the two reported repro forms' number inputs (billing/show.php add-charge unit_price, reconciliation/show.php system/manual amount) as a UX nicety — the server ceiling is the actual guarantee. - CommissionController commission_pct is a percentage, already bounded 0-100 — deliberately left alone (not a currency ceiling). Verified live (real HTTP round-trips against a signed-in session, container rows built + cleaned up, no data left behind): on a real invoice, adding a line with unit_price=999,999,999,999.99 is now REJECTED (0 items written), a huge quantity x normal price (line-total ceiling) is REJECTED, and a normal $49.50 line is ACCEPTED. On a real open reconciliation session, manual_amount=999,999,999,999.99 is REJECTED (0 lines written) and a normal $48.00 line is ACCEPTED. Plus a unit test of the ceiling helpers (boundary cases at exactly 100,000,000 pass; 100,000,000.01 and the trillion are rejected; negatives/non-numeric correctly fall through to their own guards). Full PHPUnit suite green (29 tests / 859 assertions). 23 files touched, all php -l clean. ===== Activity / Notes ===== * **2026-07-28T14:26:41+01:00 - Claude:** FIXED. What: no currency-amount field in the app enforced any upper ceiling. Money columns are DECIMAL(14,2), so the DB itself accepts up to 999,999,999,999.99 (~a trillion), and an invoice line-item unit_price or a reconciliation manual_amount of exactly that was accepted with no error and folded straight into the invoice total / session total / dashboard aggregates. As the ticket correctly diagnosed, the arithmetic (addition, and Void's exclusion) was already right — the only failure was the missing input ceiling, and it was systemic: 20 money fields across 18 controller methods (two of which were the reported repro paths) all validated numeric + usually non-negative but had NO upper bound. Where + how fixed: - app/classes/Core/Validator.php — new reusable ceiling: const MAX_MONEY = 100000000.0 ($100,000,000), a fluent moneyMax($field,$label) for the fluent-Validator sites, and a static exceedsMoneyCeiling($value) for imperative/JSON call sites. Chose $100M (not the ticket's suggested $1M minimum) so no plausible real single amount in an ISP/CRM's books is ever falsely rejected, while still being 10,000x below the column's own limit — it decisively blocks a fat-finger extra digit or a deliberate corruption attempt. One tunable constant. - Applied to EVERY money field found (exhaustive sweep): invoice line unit_price + derived line-total quantity*unit_price (BillingController::validateItem AND the JSON Api/InvoiceApiController::addItem), reconciliation system_amount + manual_amount (ReconciliationController::validateLine), payment amount (PaymentController + Api/PaymentApiController), wallet amount (WalletController), expense amount (TransactionController), credit/refund amount (CreditNoteController), contact purchase/sale + payment amount (ContactController), payroll pay amount (PayrollController), employee monthly_salary — currency branch only, the commission-percentage 0-100 branch is left as is (EmployeeController), service plan price (ServicePlanController + Api/ServicePlanApiController), maintenance amount (MaintenanceController), installation amount (InstallationController), vehicle fuel cost (FleetController), inventory unit_cost on both create/edit and restock (InventoryController), task close-out collected_amount (TaskController), and the platform console's tenant price_override + package price (Console/TenantsController + Console/PackagesController). - Client-side: added max="100000000" to the two reported repro forms' number inputs (billing/show.php add-charge unit_price, reconciliation/show.php system/manual amount) as a UX nicety — the server ceiling is the actual guarantee. - CommissionController commission_pct is a percentage, already bounded 0-100 — deliberately left alone (not a currency ceiling). Verified live (real HTTP round-trips against a signed-in session, container rows built + cleaned up, no data left behind): on a real invoice, adding a line with unit_price=999,999,999,999.99 is now REJECTED (0 items written), a huge quantity x normal price (line-total ceiling) is REJECTED, and a normal $49.50 line is ACCEPTED. On a real open reconciliation session, manual_amount=999,999,999,999.99 is REJECTED (0 lines written) and a normal $48.00 line is ACCEPTED. Plus a unit test of the ceiling helpers (boundary cases at exactly 100,000,000 pass; 100,000,000.01 and the trillion are rejected; negatives/non-numeric correctly fall through to their own guards). Full PHPUnit suite green (29 tests / 859 assertions). 23 files touched, all php -l clean. ===== Full History ===== ^ Date ^ User ^ Field ^ Change ^ | 2026-07-28T13:28:23+01:00 | Khaled Tarabay | issue-new | New Issue | | 2026-07-28T14:26:35+01:00 | Claude | Assigned To | => Claudine | | 2026-07-28T14:26:38+01:00 | Claude | tag-added | Tag Attached: done-by-claude | | 2026-07-28T14:26:41+01:00 | Claude | note-added | Note Added: 0000093 | | 2026-07-28T14:26:44+01:00 | Claude | Status | new => resolved | ---- Synced automatically from MantisBT issue #134.