Software Security Training
Exercise: The Integer Trap
In this activity, you will identify and fix a business logic vulnerability related to input validation.
Scenario:
You are a backend developer for an e-commerce site. A user discovered that if they enter a negative quantity for an item, the website calculates a negative price—effectively paying the user to "buy" the item!
Your Task
- Examine the code in the editor.
- Click "Run Security Test" to see the vulnerability output in the console.
- Modify the
calculate_total function to reject negative numbers.
- If input < 0, return
0 or print an error.
- When finished, click "Export PDF" to submit your work.
Why This Matters
Input validation is the first line of defense. Ensuring that data conforms to expected bounds prevents logic errors that attackers can exploit for financial gain.