Authorization and output shaping solve different problems. A caller who may read a review still does not need internal audit fields, session tokens or other people’s identifiers.
Read, predict, run
This projection returns the fields needed by the public review card. Add an internal field to the input and observe that it stays out. Test the exact output shape, not only the existence of title, because extra fields can be the vulnerability:
Before pressing Run, predict what run returns for {"id": 1, "title": "Review", "version": 2, "sessionToken": "fixture"}, from the
code above. Write your answers down first: after Run, the case table shows the
expected values beside the actual ones.
The case table computes these results on the server side of the simulation.
It compares values; it does not prove a production deployment or database works.
The failure to avoid
Passing an entire database row to a Client Component exposes it even when JSX does not display every field. The same applies to JSON responses and metadata.
Compare two projections of the row
{"id": 1, "title": "Review", "version": 2, "ownerId": "ada", "auditNote": "flagged"}.
A denylist that removes only auditNote still sends ownerId, and next
month's new column too. The allowlist above sends exactly id, title and
version. Write the exact JSON each puts on the wire.
Exercise
Extend the contract
Include a canEdit capability computed from a trusted actorId and the row owner. Do not include ownerId itself. Here actorId stands for the id the server took from the session and joined to the row, never a value the client sent. Deny by default: a missing or empty actorId can't edit anything, even a row with no owner.
Design the contract first: add one case of your own where actorId is an empty
string and ownerId is empty too, and decide its result before running.
Edit lib/contract.js, then rerun the original cases. If the requested rule
changes an earlier result, update that expected value deliberately. Keep the
other cases. Add the acceptance cases to examples so the preview checks them too.
Runs with real Next.js on your computer: unzip, then npm install and npm run dev.
Hint 1: the idea
The client needs to know what it may do, not why. A capability is a fact the
server works out from private data and sends as a boolean, so the private data
itself stays behind.
Hint 2: a first step
Compute the boolean server-side and keep the explicit output allowlist.
Show one solution
Replace the exported run function and any constants shown here; keep the
examples export underneath it. Compare the result with your own approach.
row.actorId === row.ownerId alone would be true when both are missing
(undefined === undefined), granting edit to an anonymous caller on an
unowned row. Checking for a real id first keeps the capability deny-by-default.
canEdit is computed on the server and leaves as a plain boolean, so the
browser learns the answer but not whose row it is. The presence checks come
first: without them, a row with no owner and a request with no actor would
compare undefined === undefined and allow editing. It's a display hint only;
the action that performs the edit must still check on the server.
Explain it without the code
List what a review card's JSON would reveal if it included ownerId, and one
attack that information helps.
Going further
Read the Next.js guide for the framework boundary around this rule.
The preview runs code-playpad's Next.js simulation. Real caching, hydration,
authentication and persistence require the real-server checks described on Day 7.
Completion is saved in this browser only. It does not measure mastery.