LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
← Build a login system
BUILD → VERIFY → EXPLAIN · STEP 4 OF 6

Protect an endpoint and check ownership

A valid login is only the first check before returning a private record.

UNDERSTAND

Bring these concepts with you

BUILD

Your implementation

  1. Implement readInvoice by authenticating first and comparing the server-loaded invoice owner and tenant with the authenticated identity.
  2. Read /invoices/mine, then try /invoices/other and /invoices/external with the same cookie. These are fixed fixtures, not a real invoice database.
  3. Return only the intended invoice fields. Do not accept ownerId or organizationId from request input as proof of permission.
function readInvoice(token, invoice) {
  // Authenticate, check server-owned policy fields, return allowed data.
}
Need a hint?
  • Check both ownerId and organizationId; one check alone leaves a boundary unprotected.
  • Use the authenticated user returned by authenticate, not a user ID claimed by the client.

Saved on this device · 0 / 6000 · Do not include passwords or private data.

VERIFY

Acceptance checks

From the folder containing your downloaded files, run:

node checks.mjs ./starter.mjs 4

This runs checks up to this step. Earlier steps must work first. Mark each result only after checking your implementation; the website does not run or grade it.

Record your attempt to enable the checklist and reference comparison.

Compare with the reference

Attempt the step first, then compare decisions and behavior. There can be more than one correct implementation.

EXPLAIN

Your interviewer asks

An attacker changes a URL to another invoice ID. Where should the request be denied, and which inputs can you trust?

Say your answer aloud, then record the trade-offs and evidence in your notes above.

LOCAL VOICE REHEARSAL

Rehearse your step walkthrough aloud

Target pacing: 02:00 · Stays in this browser only; never uploaded.

00:00/ 02:00
AlifBay Prep