Cybersecurity Essentials for Developers · Chapter 9 of 10 · ~15 min
Project: Isolated Vulnerability Lab
Exploit and patch three classic flaws in an isolated local toy app: Broken Object-Level Authorization (IDOR), SQL Injection, and Stored XSS.
- Test authorization boundaries against IDOR enumeration
- Eliminate SQL injection using bound query parameters
- Neutralize Stored XSS with escaping and strict CSP
- Verify fixes against adversarial payloads
Project: Isolated Vulnerability Lab: learn it visually
Build and patch an isolated local toy app in-browser: fix broken object-level authorization (IDOR), parameterized SQL queries, and output escaping.
1Defense-in-Depth Across Auth, SQL & DOM
Most real-world breaches chain simple mistakes: missing ownership checks, concatenated SQL, and unescaped HTML.
Wrong idea: Trust the ?invoiceId=1024 parameter because the user is logged in
Authentication only proves who you are—not which invoice you are allowed to read.
Real system: Scope every query to the authenticated session user
Include AND owner_id = session.userId in every read/write query so attackers cannot enumerate IDs.
2Live Project Lab: Exploit & Patch Toy App
Test each attack in Vulnerable Mode, then click Apply Security Patch and re-run the payload.
Predict first
A route checks `if (!req.session.userId) return 401;` before running `SELECT * FROM invoices WHERE id = ?`. Is it safe from IDOR?
if (!req.session.userId) return 401;
return db.query("SELECT * FROM invoices WHERE id = ?", [req.params.id]);3Bug Hunt · Patch getInvoice()
Patch getInvoice so it uses parameterized placeholders and enforces owner_id = sessionUserId.
🎯 Find and fix the bugs in the code above, then press Run & verify to test your solution.
Need a hint?
Return db.query("SELECT * FROM invoices WHERE id = ? AND owner_id = ?", [invoiceId, sessionUserId]).
4Knowledge Check
Which change prevents Broken Object-Level Authorization (IDOR) on a private invoice endpoint?
Why do parameterized SQL queries defeat SQL injection?
5Recap
- IDOR: Always bind queries to
session.userIdon the server. - SQLi: Use parameterized placeholders; never interpolate user strings into SQL.
- XSS: Escape untrusted text by default and enforce a strict Content Security Policy.
Completed the vulnerability lab and bug hunt?