How do you prevent users from accessing other users' records?
Reveal the answer and explore the explanation.
02MediumCoreHow do you prevent users from accessing other users' records?
Answer
MediumCore
How do you prevent users from accessing other users' records?
Answer
Authorize every object access using the verified identity and applicable permissions; never trust a client-supplied owner ID.
Practical example
Filter saved assessments by the authenticated user's identity.
PythonRelated concept example
def can_read(session, record):
return bool(session) and session['user_id'] == record['user_id']
# In production, obtain session from verified authentication.The caller cannot authorize access by supplying a different user ID.
Reference: Further reading ↗