Practise this: Break in, then lock the door
Clone the starter: https://github.com/codeprepdev/agentic-engineering-lab-7-break-in-then-lock-the-door. It is the hire counter: a tool-hire yard's app in Node, with nothing to install. Counter staff mark gear returned. Since last month customers can sign in to a page of their own, see their hires with the site address the gear went to, and extend a hire. An agent built that page in a week, and its tests pass. Run node --test and node scripts/scan.js, read the README (it has the sign-in details), then start the app with node server.js.
1. Break in, twice, before you fix anything. Sign in as a customer and look at the cookie the app sets. Then:
- change the cookie so that the app takes you for counter staff, and mark a hire returned;
- open one of your own hires on the customer page, change the number in the address, and read another customer's hire. Then extend it.
Point the app at a scratch copy of data/ first (HIRE_COUNTER_DATA=/tmp/yard node server.js, after copying the folder there), because the second break-in writes. Record both in BREAK-IN.md: the cookie and the address you used, what came back, and what each one reached. You will test your fix against this evidence.
2. Write the refused tests first. One test sends a cookie you wrote yourself, session=<id>, and expects 401. One signs in as one customer, asks for another customer's hire at /my/hires/<id>, and expects 404. Watch both fail against the starter, then brief the agent with them.
3. Fix both. The cookie must be something only the server can issue: a cookie naming a user, or a real one with any character changed, signs nobody in. On the customer page, every hire is loaded with the signed-in customer in the same call, through a finder named …ForCustomer (for example db.findHireForCustomer(id, customer.id)), and someone else's hire answers 404, the same as one that does not exist. That goes for opening a hire and for extending one. Keep signing in, the staff routes and every existing test working, and leave lib/passwords.js and the shape of data/ alone.
4. Add the scanner rule. In scripts/scan.js, add a rule with the id record-by-id-without-owner. In any file whose name starts with customer, it reports each call to db.<name>(…) that is given an id from the address, either ctx.params itself or a variable assigned from it, unless the name ends in ForCustomer. Its message names the fix: load with a …ForCustomer finder and answer 404. scanSource(file, text) keeps returning { file, line, rule, message } for every rule, and node scripts/scan.js [folder] keeps printing file:line and exiting 1 when there are findings. Run the rule on the starter's lib/customer-handlers.js and see it report the lines you broke in through. Then run it on your fix and see it pass. Keep the secret rule as it is.
Get node --test and node scripts/scan.js passing, with the output in front of you, then upload the repository folder. The .git folder is left out, so the hidden tests mark your files. They call the app with users and hires of their own: forged and changed cookies, staff and customers signing in for real, another customer's hire opened and extended, and your own hires still working. They run your scanner on code it has never seen, with and without the flaw, and as a command on a planted folder and on your repo. They also check your tests, the starter's tests (all there, none skipped) and BREAK-IN.md.
Open the lab · needs a free Tarmac account to have your work marked