MEDIUM: No input validation on subscription amount — negative and NaN values accepted #9

Closed
opened 2026-05-09 00:02:36 +00:00 by Mark · 0 comments
Owner

Severity: Medium

Location

backend/src/controllers/SubscriptionController.ts lines 69–83

Description

The create method only checks if amount === undefined, allowing negative numbers, NaN, Infinity, and extremely large values:

if (!name || !billingDate || amount === undefined) {
  res.status(400).json({ error: 'Name, billing date, and amount are required' });
  return;
}
// ...
amount: Number(amount),

Number(amount) will silently convert strings like '' to 0, and Number(undefined) to NaN. There is no check that amount is a positive finite number.

Impact

  • Users could accidentally create subscriptions with negative or NaN amounts, crashing the dashboard display
  • A subscription with amount 0 or negative would skew financial calculations

Suggested Fix

Add proper validation:

const numAmount = Number(amount);
if (isNaN(numAmount) || numAmount < 0 || !isFinite(numAmount)) {
  res.status(400).json({ error: 'Amount must be a valid positive number' });
  return;
}
## Severity: Medium ## Location `backend/src/controllers/SubscriptionController.ts` lines 69–83 ## Description The `create` method only checks if `amount === undefined`, allowing negative numbers, NaN, Infinity, and extremely large values: ```typescript if (!name || !billingDate || amount === undefined) { res.status(400).json({ error: 'Name, billing date, and amount are required' }); return; } // ... amount: Number(amount), ``` `Number(amount)` will silently convert strings like `''` to 0, and `Number(undefined)` to NaN. There is no check that `amount` is a positive finite number. ## Impact - Users could accidentally create subscriptions with negative or NaN amounts, crashing the dashboard display - A subscription with amount 0 or negative would skew financial calculations ## Suggested Fix Add proper validation: ```typescript const numAmount = Number(amount); if (isNaN(numAmount) || numAmount < 0 || !isFinite(numAmount)) { res.status(400).json({ error: 'Amount must be a valid positive number' }); return; } ```
Mark closed this issue 2026-05-17 21:11:55 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/subvault#9
No description provided.