A customer can sign in, but that shouldn't let them read another customer's invoice. This example gives Duo a short request path to trace so you can see whether its explanation separates identity from permission.
Share the request path
Use the original prompt for a signed-in customer reading an invoice, along with this simplified code. It starts after session middleware has handled sign-in and supplied user_id as the established identity. The handler relies on that middleware to identify the user; it doesn't take user_id from a request parameter.
INVOICES = {42: {"owner_id": 8, "total_cents": 1200}}
def read_invoice(user_id, invoice_id):
"""Return an HTTP-style status and body for a supplied authenticated identity.
None means the session middleware found no signed-in user. Reads an in-memory
invoice mapping without changing it. Returns 401, 404, or 403 for rejected
requests and 200 with the total for the owner. This example does no I/O.
"""
if user_id is None:
return 401, {"error": "Sign in first"}
invoice = INVOICES.get(invoice_id)
if invoice is None:
return 404, {"error": "Invoice not found"}
if invoice["owner_id"] != user_id:
return 403, {"error": "You can't read this invoice"}
return 200, {"total_cents": invoice["total_cents"]}
Trace three requests
A clear answer should point to where each request stops:
| Request | Result | Why |
|---|---|---|
read_invoice(None, 42) |
401 |
No signed-in identity reached the handler. |
read_invoice(7, 42) |
403 |
The user is signed in but doesn't own invoice 42. |
read_invoice(8, 42) |
200 |
The signed-in user owns the invoice. |
If the answer says that signing in grants access, ask it to trace the ownership comparison. If it describes password checks or token validation, ask where those appear: they're outside the supplied code, so we'd need to inspect the middleware to explain them.
Ask about a change in requirements
Suppose support staff need to investigate billing questions. Ask Duo:
Support staff may need access to invoices, but this handler only checks ownership.
What additional information would you want before recommending a change?
To recommend staff access, Duo would need more context than this ownership check provides. Look for questions about how staff identity and access are managed, which invoices they may view, and how that access is recorded. A proposal should explain how staff would gain the appropriate access while preserving the ownership check for customers; any support-role check would be new behavior to discuss.