Fix the access check on an account delete route
Your task
An AI added POST /account/delete, which deleted whatever userId the request body named. Any caller could delete someone else's account. The fixed route takes the caller's id from the session and refuses a body id that names a different account. Your team tests that decision as a function.
An assistant wrote screen_delete_requests(request_lines). It is in the editor. It has a bug. Find it and fix it.
Input and output:
request_lines: one per request, with fields joined by|, such assession=u1|body=u1.sessionis the user id the server proved from the session cookie.bodyis the id the client asked to delete. Either can be missing or empty.- Return one decision per request, in order.
Rules the tests check:
- Split a line on
|and trim each part. A part that starts withsession=sets the session id, and one that starts withbody=sets the body id, each to the rest of the part, trimmed. When a field appears twice, the last one wins. Other parts are ignored, and a missing field is empty. - No session id:
"deny:unauthenticated", whatever the body says. - A body id that is not empty and is not the session id:
"deny:forbidden". Ids compare exactly. Case matters, soaliceandAliceare different accounts, andu10is notu1. - Otherwise:
"allow:delete:<session id>".
Examples
screen_delete_requests(request_lines: list[str]) -> list[str]Example 1
Input
screen_delete_requests(["session=u1|body=u1", "session=u1|body=u2", "session=|body=u1"])Output
["allow:delete:u1", "deny:forbidden", "deny:unauthenticated"]Example 2
Input
screen_delete_requests(["session=u7"])Output
["allow:delete:u7"]Example 3
Input
screen_delete_requests([])Output
[]