Skip to content

Commit

Permalink
Disallow NaN in transactions
Browse files Browse the repository at this point in the history
Creating a transaction with NaN will set the user's balance to NaN, giving them infinite money due to the following behaviours:
NaN can be stored in the database
anything.lt(NaN) = false
NaN.lt(anything) = false
  • Loading branch information
Mingy123 authored Oct 29, 2024
1 parent 1c90118 commit 309df87
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/src/api/student.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ router.post("/createTransaction", async (req, res) => {
if (amountToDP.lte(0)) {
return res.status(400).json({ message: "Amount must be positive" })
}
if (!amountToDP.isFinite()) {
return res.status(400).json({ message: "Invalid Amount" })
}

const transId = getRandom()

Expand Down

0 comments on commit 309df87

Please sign in to comment.