Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Endpoints that authenticate but don't authorize
card 4 of 6
Where the guard really lived
builds on: Trust boundaries and untrusted input, What the agent cannot see
The view handler the agent copied loads `findFirst({ where: { id } })`, with no owner in sight. It looked unguarded and worked, so the agent mirrored it. The real guard was in `routes/index.ts`: `app.use("/invoices", requireLogin, ownInvoice, invoices)`. The agent added its route to the exports router, mounted as `app.use("/exports", requireLogin, exports)`. Its summary, "mirrors the existing invoice view", was true of the code and false of the protection.
Terms on this card
- router
- An object grouping routes. Middleware attached where it is mounted applies to every route on it, but not to routes on other routers.
- requireLogin
- In the example, a middleware that only checks that the caller is logged in (authentication), not which records they may access.
- ownInvoice
- In the example, the middleware that checks the requested invoice belongs to the caller's organisation.
- findFirst
- A database query method (Prisma, a TypeScript ORM) that returns the first row matching the `where` filter, or null if none matches.
- the agent
- The AI coding system doing the work: a chat assistant, IDE agent or terminal agent.
Lesson goal: Spot new endpoints or queries that check who the caller is but not whether they may access this record (insecure direct object references). Explain why agents copying a nearby handler often miss ownership checks that are enforced elsewhere in the codebase. ·
the whole lesson