Backend Developer · Projects

Project 1: A secure orders API

Marking guide version 1 · Lessons: BE1 lessons 2 and 4, BE2 lessons 2–3, BE5 lessons 2–4, BE6 lessons 1–3, BE10 lesson 2

The problem and who it's for

TiffinBox's API works when everyone behaves. It reads tokens without checking their signature, shows any customer's orders if you change a number in the address, trusts the total the app sends, makes two orders when a phone retries, and lets one caller send thousands of requests. Meera orders lunch every weekday; she shouldn't be charged twice when her network drops, and nobody else should see her address.

Scope

Not included

Before you start

Starter files

Download everything at once: starter/backend-starter.zip.

Milestones

  1. Run npm run test:api and note which of the 13 tests fail and why.
  2. Verify tokens in api/auth.js with the sign-in server's JWKS (tests 2 to 5).
  3. Add scope checks and take the customer from the token (tests 6 and 7).
  4. Validate orders, price them on the server and return problem details (tests 8 to 10).
  5. Add idempotency keys with a unique constraint (test 11).
  6. Move the rate limit to Redis (test 12), then run all 13 three times in a row.

Expected outputs

Acceptance tests

# Input Expected result
1 npm run test:api 13 of 13 pass, three runs in a row
2 A token signed with a different key, sent to GET /v1/me/orders 401 (test 5)
3 Test customer 1's token with ?customer_id=2 Only customer 1's orders (test 7)
4 A valid order with "total_paise": 1 201, with the total computed from database prices (test 10)
5 The same Idempotency-Key sent 5 times at once Exactly one order; every reply refers to it (test 11)
6 41 order-list requests in a minute with RATE_LIMIT=40 Request 41 gets 429 with Retry-After; another customer is unaffected (test 12)

Failure and recovery exercises

  1. Change your token check to skip the audience. Run test 4 and explain what an attacker could do with a token meant for another API. Then put the check back.
  2. Remove the unique constraint's ON CONFLICT handling and run test 11 a few times. Explain the race you see, then restore it.
  3. Stop Redis and call GET /v1/me/orders. Write two sentences on why the kit's rate limiter lets requests through (fails open) here, and name one route where you'd fail closed instead.

Evidence to submit

Marking guide and self-check

Pass rule: every Safety-critical (S) and Mandatory (M) item must be met. A single unmet safety item means the project is not complete, whatever else is done. Quality items are for your own improvement.

Your answers are saved in this browser on this device. Self-checked means you checked your own work against this guide; it is not a reviewer's approval. Never paste passwords, keys, tokens or real customer data here.

Checklist (marking guide version 1)
Evidence

← PreviousAll projects
ProLearners Assist