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

Whose bookmark may this request read? Caller Identity Owner filter Result

Scroll sideways to see the full diagram.

  1. A request names a bookmark.

    Step 1 of 4
  2. The application obtains a trusted caller identity.

    Step 2 of 4
  3. The database query includes the owner.

    Step 3 of 4
  4. Only 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

Run the browser experiment

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.

Open the local exercise files

Check yourself

Which owner should a write use?

Not quite. A body field can name another person. Re-read that part ↑

Right. Every read and write needs an ownership decision based on the authenticated caller.

Why should an ownership test inspect Ada's row after Ben receives a refusal?

Not quite. Verify the protected effect as well as the response. Re-read that part ↑

Right. Verify the protected effect as well as the response.

How can both owners store a bookmark called river?

Right. The pair distinguishes two different owners' rows.

Not quite. The pair distinguishes two different owners' rows. Re-read that part ↑

Sources

What you now know

Every read and write needs an ownership decision based on the authenticated caller.