Assignment
1. Node tasks
Setup
snippetsRouter.get("/", async (req, res) => {
let query = knexInstance.select("*").from("snippets");
if ("sort" in req.query) {
const orderBy = req.query.sort.toString();
if (orderBy.length > 0) {
query = query.orderByRaw(orderBy); // Vulnerable!
}
}
console.log("SQL", query.toSQL().sql);
try {
const data = await query;
res.json({ data });
} catch (e) {
console.error(e);
res.status(500).json({ error: "Internal server error" });
}
});Part A – Demonstrate and fix SQL injection
Part B – Extend the Snippets API
Part C – Error handling and validation
Part D – Document your API with OpenAPI/Swagger
Part E – Advanced Postman collection and tests
Week 2 assignment objective
2. Events Startup Project
Last updated