Part of #59.
Part of the broken-access-control remediation epic. Depends on Phase 0. This is the foundation — most findings are fixed by applying this one helper.
Goal
Add a single reusable object-level authorization primitive and a regression test harness, so every user-scoped route enforces access consistently instead of each handler reinventing (or omitting) the check.
Work
- Authorization helper — e.g. a dependency
require_object_access(db_user, target_student_id) encapsulating the Phase‑0 policy:
db_user.id == target_student_id, OR
role == "tutor" AND a matching TutorStudentAssignment exists (src/models/tutor_student.py), OR
role == "parent" AND a matching parent link exists (per Phase 0), OR
role == "admin"
- else raise
403.
- Model it on the existing correct checks in
enhancements.get_conversation_history and messaging.get_thread.
- Red-first test harness — a parametrized test asserting that a second, unrelated authenticated user receives
403 for every user-scoped route. Land these red before the Phase 2–4 fixes turn them green (per repo TDD norm).
Definition of Done
Affected / reference files
- New helper (location TBD, e.g.
src/api/middleware/authz.py)
src/models/tutor_student.py (existing, currently unused)
- Patterns:
src/api/handlers/enhancements.py:57, src/api/handlers/messaging.py:320
Part of #59.
Part of the broken-access-control remediation epic. Depends on Phase 0. This is the foundation — most findings are fixed by applying this one helper.
Goal
Add a single reusable object-level authorization primitive and a regression test harness, so every user-scoped route enforces access consistently instead of each handler reinventing (or omitting) the check.
Work
require_object_access(db_user, target_student_id)encapsulating the Phase‑0 policy:db_user.id == target_student_id, ORrole == "tutor"AND a matchingTutorStudentAssignmentexists (src/models/tutor_student.py), ORrole == "parent"AND a matching parent link exists (per Phase 0), ORrole == "admin"403.enhancements.get_conversation_historyandmessaging.get_thread.403for every user-scoped route. Land these red before the Phase 2–4 fixes turn them green (per repo TDD norm).Definition of Done
Affected / reference files
src/api/middleware/authz.py)src/models/tutor_student.py(existing, currently unused)src/api/handlers/enhancements.py:57,src/api/handlers/messaging.py:320