security: medication/appointment write + delete paths don't check ownership #12
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Any authenticated user can update or delete any other user's medication or appointment by id. The
update_*anddelete_*handlers take the authClaimsbut don't use them — there is no ownership check before mutating the document.Surfaced while wiring the Phase B share-gate into the read paths (PR #11). Filing separately because it's a pre-existing security gap, independent of the sharing work.
Evidence
In
backend/src/handlers/medications.rsandbackend/src/handlers/appointments.rs, the write handlers bind_claims(underscore-prefixed = unused):Same shape for
delete_medication,update_appointment,delete_appointment. A logged-in user who guesses/learns another user'smedication_id(a UUID, but exposed in API responses) can rewrite or remove it.For contrast, the read paths now check ownership-or-share via
authorize_profile_read(landed in PR #11, Phase B). The write paths were left unchecked because writes-by-recipients are explicitly out of scope for Phase B (recipients are read-only), but that decision left the owner-vs-other-owner hole unaddressed too.Also affected
log_dose(medications) — same pattern; needs an ownership check on the parent medication.update_health_stat/delete_health_stat—updatechecksuser_idvia a direct comparison in the handler (not the repo), so it may be OK;deleteshould be audited. Worth confirming all four data types uniformly.Fix
Mirror the read-path gate but owner-only (not share-aware, since recipients are read-only):
authorize_profile_readadmits owners (and share recipients); to enforce owner-only on writes, either add anauthorize_profile_writevariant that rejects shares, or checkitem.user_id == claims.subdirectly. The latter is simpler and unambiguous for write paths.Severity
Suggested priority
High. Small, localized fix (a few lines per handler). Should land before any production deployment.
Labels:
bug.