Reading diagrams / Topic 35 of 42

The access check: where each key comes from

The rule

Every read, write and delete of a table names a key: the row it touches. Some tables keep one row per user, and the rule for them is that a caller touches only their own row. The route tree reported the access check's problems on a route's paths. This picture shows the same check from the side of the data: for each operation, it follows the key back through the code to where it comes from.

Read it left to right. The left column, “Where the key comes from”, names each source: “The signed-in caller”, a “Fixed value” written into the code, an input of the handler, or what a database read returned. The middle column names each operation by its handler and verb, such as “list_notes · db_read”, with the check's verdict under it. The right column is the table and its rule: OwnerScoped means each row belongs to one user. A line joins each source to every operation whose key it feeds, and each operation to its table.

Red marks an operation whose key the check cannot tie to the caller, and the table it touches. In this notes service before the fix, list_notes reads with the key “other-user” written into the code, so every caller reads that one user's notes. Press After the fix to see the picture once the read uses the caller's key. Press any box to follow its key step by step, with the line of code for each step.

The words above the frame, such as the title over the picture, are written by people. Inside the frame is the check's own output, except the line that begins “Recorded run”: what one run answered Alice in each version, recorded beside the check to show the leak happening. Handler and table names are the program author's labels: the check reads what the code does with a key, never what it is called.

The check reads table operations and their keys. It proves a key is the caller's; it does not say what the handler does with the row, or that there is no other way in.

notes: a small service that keeps each user’s notes in one table, before and after a fix. The buttons switch versions.

Loading the recorded example.

Loading the worked examples and practice.