CoursesBackend engineering from first request to production
Puzzle 9 · 10 of 18
Whose bookmark may this request read?
Trace identity from the caller to the storage query.
All puzzles in this course
The problem
Two people save a bookmark named river. Your route receives that name. Which row belongs to the person making the request?
See it
Scroll sideways to see the full diagram.
A request names a bookmark.
Step 1 of 4The application obtains a trusted caller identity.
Step 2 of 4The database query includes the owner.
Step 3 of 4Only matching rows are returned.
Step 4 of 4
The building block
Authentication establishes the caller identity. Authorization decides which action that caller may perform on a resource. In the offline drill the trusted caller is an explicit test input. In a service it would come from a verified session. Filter database reads and updates by both that identity and the resource name. A unique key over owner and name lets two people reuse a name. An owner typed into a request body is ordinary input. It cannot establish who sent the request. The existing single-user loopback lab has no login system.
Trace a denied deletion
Ada owns river. Ben is signed in and asks to delete river. Construct the database condition from two facts: the resource name is river and the verified caller is Ben. No row belonging to Ben matches. The model returns 403 and a later read by Ada still finds river. Now give both accounts a bookmark called river. A delete scoped to Ben removes only his copy. Checking only the name would make correctness depend on who happened to pick a name first.
Try it
Optional local lab
Extend the offline exercise with a delete operation. Check that Ben cannot remove Ada’s row and that Ada can remove her own. Test both postconditions.
Check yourself
Sources
What you now know
Every read and write needs an ownership decision based on the authenticated caller.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.