npm install express pg bcrypt @types/bcrypt
docker run -p 5432:5432 -e POSTGRES_PASSWORD=dev postgres:16
Create an intentionally vulnerable Express API with SQL injection, IDOR, and weak password storage to learn by seeing the attack surface.
1 import { Router } from 'express'; 2 import { pool } from '../db'; 3 4 const router = Router(); 5 6 // A03: Injection — VULNERABLE (for demonstration only) 7 router.get('/user', async (req, res) => { 8 const query = `SELECT * FROM users WHERE id = ${req.query.id}`; 9 console.log('Executing:', query); // Log the injection 10 const { rows } = await pool.query(query); 11 res.json(rows); 12 }); 13 14 export default router; 15
GET /user?id=1 OR 1=1-- returns all rows
Sign in to share your feedback and join the discussion.