From 69343c88201f22b345d9b08fb96c44fb75b9b7ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?=
Date: Tue, 4 Aug 2026 12:30:01 +0200
Subject: [PATCH] Stop a delegate deferring somebody else's medication
reminders
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Found by an adversarial pass over the release candidate before it was tagged,
and it is the reason the tag waited.
`POST /api/medications/intake` is admitted for delegates because a caregiver
standing next to the patient has to be able to say the tablet went down. It is
an update, though, and the same body can carry two other things. Snoozing
writes `snoozedUntil` on the OWNER's medication row, and the reminder cron
skips that medication for as long as the stamp is in the future. The field
takes any future instant. So somebody with write access could stop another
person's medication reminders for years, and three things made it quiet: the
owner is deliberately not notified of a delegated snooze, the activity feed
renders the whole family as "marked a dose", and the only accurate trace was a
line in the admin audit log.
The second was flipping a dose the owner had already recorded — taken to
skipped and back, which rewrites their compliance history and refunds
inventory. The consent screen promises that changing what is already there
stays with the owner.
Both refuse for a delegate now and stay open to the owner, who is the only
person either was ever for. A refused attempt is filed under the owner and gets
its own sentence in the activity panel rather than borrowing the one for
marking a dose, because folding them together is what made the gap dangerous.
Two more from the same pass:
The consent notice named allergies among the things a delegate may add. That
left the admitted set before this release shipped, and it said so in six
languages on the one screen where somebody decides who may write into their
health record. It also omitted half of what IS admitted. The copy now matches
the frozen list, and the test asserts the withdrawal rather than only the
presence of the rest.
The banner told a WRITE delegate nothing at all — the mode line rendered only
in the read case, guarded by a comment stating that write grants did not exist
yet. This is the release that made them exist. It matters that the banner say
it, because the rule that a refused control is absent rather than disabled
rests on the banner naming the mode globally.
And a third instance of the substitution this release already fixed twice: the
BMI chart divided the owner's weights by the height of whoever was looking.
Inside a shared record it draws nothing now rather than a number belonging to
two different people.
---
CHANGELOG.md | 12 +-
messages/de.json | 6 +-
messages/en.json | 6 +-
messages/es.json | 6 +-
messages/fr.json | 6 +-
messages/it.json | 6 +-
messages/pl.json | 6 +-
src/app/api/medications/intake/route.ts | 60 +++++++++-
src/components/charts/health-chart.tsx | 18 ++-
.../layout/shared-record-banner.tsx | 20 ++--
.../__tests__/grant-access-level.test.tsx | 11 +-
src/hooks/use-record-capabilities.ts | 10 +-
src/lib/notifications/delegated-intake.ts | 12 +-
src/lib/record-activity/activity-verb.ts | 10 ++
.../sharing-delegable-writes.test.ts | 103 ++++++++++++++++++
15 files changed, 260 insertions(+), 32 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e77c2f6d..f601ee0b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -71,9 +71,19 @@
- The activity feed showed a blank line when a delegate marked a dose, because
the sentence was keyed on a name the route does not use.
+- Marking a dose and deferring a reminder went through the same request, so
+ somebody with write access could postpone one of your medication reminders
+ rather than only record a dose. There was no upper bound on how far, you were
+ not told, and the activity feed described it as marking a dose. Deferring a
+ reminder is yours alone now, and so is changing a dose you already recorded.
+
+- Inside somebody else's record the BMI chart divided their weights by the
+ height of whoever was looking. It draws nothing there now rather than a
+ number belonging to two different people.
+
### Internal
-- Two high-severity advisories on the outbound HTTP path, published after the
+- Three high-severity advisories on the outbound HTTP path, published after the
last release, are closed. One of them is in the client that backs the
application's single documented egress boundary, so the dispatcher's own suite
was re-run against the new version rather than assumed.
diff --git a/messages/de.json b/messages/de.json
index 0fc8904c9..3f53604d5 100644
--- a/messages/de.json
+++ b/messages/de.json
@@ -9391,6 +9391,7 @@
"banner": {
"viewing": "Du bist in der Akte von {name}",
"readOnly": "Du kannst sie lesen, nicht ändern.",
+ "canAdd": "Du kannst etwas hinzufügen, aber nichts ändern oder löschen.",
"leave": "Zurück zu meiner Akte"
},
"switcher": {
@@ -9437,7 +9438,7 @@
"accessReadLabel": "Darf lesen",
"accessReadCapability": "Sie kann alles lesen, was von dieser Akte geteilt wird. Hinzufügen oder ändern kann sie nichts.",
"accessWriteLabel": "Darf lesen und hinzufügen",
- "accessWriteCapability": "Sie kann außerdem etwas zur Akte hinzufügen: Messwerte, Laborergebnisse, Allergien und andere Beobachtungen, ein neues Medikament und eine als genommen markierte Dosis. Ändern oder löschen kann sie nichts, auch nicht das, was sie selbst eingetragen hat. Das kannst nur du.",
+ "accessWriteCapability": "Sie kann außerdem etwas zur Akte hinzufügen: Messwerte, Laborergebnisse, einen neuen Laborwert, einen Krankheitseintrag, einen Wert auf einer selbst angelegten Messgröße, eine Nebenwirkung zu einem Medikament, ein neues Medikament und eine Dosis als genommen oder ausgelassen markieren. Ändern oder löschen kann sie nichts, auch nicht das, was sie selbst eingetragen hat, und eine deiner Erinnerungen verschieben kann sie auch nicht. Das kannst nur du.",
"expiresLabel": "Zugriff endet am (optional)",
"expiresHint": "Leer lassen für Zugriff, der gilt, bis ihn jemand beendet. Ein Datum wird bei jeder Anfrage geprüft, der Zugriff endet also am Ende dieses Tages von selbst.",
"submit": "Einladung senden",
@@ -9513,7 +9514,8 @@
"customMetricEntryCreate": "{name} hat einen eigenen Messwert eingetragen",
"medicationSideEffectCreate": "{name} hat eine Nebenwirkung notiert",
"medicationCreate": "{name} hat ein Medikament angelegt",
- "medicationIntake": "{name} hat eine Dosis eingetragen"
+ "medicationIntake": "{name} hat eine Dosis eingetragen",
+ "medicationIntakeRefused": "{name} wollte eine Dosis ändern oder eine Erinnerung verschieben und wurde abgewiesen"
}
}
}
diff --git a/messages/en.json b/messages/en.json
index 0862555c9..ab6c98451 100644
--- a/messages/en.json
+++ b/messages/en.json
@@ -9391,6 +9391,7 @@
"banner": {
"viewing": "You are in {name}'s record",
"readOnly": "You can read it, not change it.",
+ "canAdd": "You can add to it, but not change or delete what is there.",
"leave": "Back to my record"
},
"switcher": {
@@ -9437,7 +9438,7 @@
"accessReadLabel": "Can view",
"accessReadCapability": "They can read everything this record shares. They cannot add or change anything.",
"accessWriteLabel": "Can view and add",
- "accessWriteCapability": "They can also add to the record: readings, lab results, allergies and other observations, a new medication, and marking a dose as taken. They cannot edit or delete anything, not even what they added. Only you can.",
+ "accessWriteCapability": "They can also add to the record: readings, lab results, a new analyte to track, an illness entry, a value on a metric you track yourself, a side effect against a drug, a new medication, and marking a dose taken or skipped. They cannot edit or delete anything, not even what they added, and they cannot defer one of your reminders. Only you can.",
"expiresLabel": "Access ends on (optional)",
"expiresHint": "Leave this empty for access that lasts until somebody ends it. A date here is checked on every request, so access stops on its own at the end of that day.",
"submit": "Send invitation",
@@ -9513,7 +9514,8 @@
"customMetricEntryCreate": "{name} logged a tracked value",
"medicationSideEffectCreate": "{name} noted a side effect",
"medicationCreate": "{name} added a medication",
- "medicationIntake": "{name} marked a dose"
+ "medicationIntake": "{name} marked a dose",
+ "medicationIntakeRefused": "{name} tried to change a dose or defer a reminder, and was refused"
}
}
}
diff --git a/messages/es.json b/messages/es.json
index e43bd86cb..e4a1d2dfc 100644
--- a/messages/es.json
+++ b/messages/es.json
@@ -9391,6 +9391,7 @@
"banner": {
"viewing": "Estás en el historial de {name}",
"readOnly": "Puedes leerlo, no modificarlo.",
+ "canAdd": "Puedes añadir cosas, pero no cambiar ni borrar lo que hay.",
"leave": "Volver a mi historial"
},
"switcher": {
@@ -9437,7 +9438,7 @@
"accessReadLabel": "Puede ver",
"accessReadCapability": "Puede leer todo lo que este historial comparte. No puede añadir ni cambiar nada.",
"accessWriteLabel": "Puede ver y añadir",
- "accessWriteCapability": "También puede añadir cosas al historial: mediciones, resultados de laboratorio, alergias y otras observaciones, un medicamento nuevo y una dosis marcada como tomada. No puede editar ni eliminar nada, tampoco lo que ha añadido. Solo tú puedes.",
+ "accessWriteCapability": "También puede añadir a la ficha: mediciones, resultados de laboratorio, un nuevo analito a seguir, una entrada de enfermedad, un valor en una métrica propia, un efecto secundario de un medicamento, un medicamento nuevo, y marcar una dosis como tomada u omitida. No puede editar ni borrar nada, ni siquiera lo que añadió, ni aplazar uno de tus recordatorios. Solo tú puedes.",
"expiresLabel": "El acceso termina el (opcional)",
"expiresHint": "Déjalo vacío para un acceso que dure hasta que alguien lo termine. Una fecha aquí se comprueba en cada petición, así que el acceso se detiene solo al final de ese día.",
"submit": "Enviar invitación",
@@ -9513,7 +9514,8 @@
"customMetricEntryCreate": "{name} registró un valor propio",
"medicationSideEffectCreate": "{name} anotó un efecto secundario",
"medicationCreate": "{name} añadió un medicamento",
- "medicationIntake": "{name} registró una dosis"
+ "medicationIntake": "{name} registró una dosis",
+ "medicationIntakeRefused": "{name} intentó cambiar una dosis o aplazar un recordatorio, y fue rechazado"
}
}
}
diff --git a/messages/fr.json b/messages/fr.json
index 8a1ea5002..5063784bf 100644
--- a/messages/fr.json
+++ b/messages/fr.json
@@ -9391,6 +9391,7 @@
"banner": {
"viewing": "Vous êtes dans le dossier de {name}",
"readOnly": "Vous pouvez le lire, pas le modifier.",
+ "canAdd": "Vous pouvez y ajouter, mais pas modifier ni supprimer ce qui s'y trouve.",
"leave": "Revenir à mon dossier"
},
"switcher": {
@@ -9437,7 +9438,7 @@
"accessReadLabel": "Peut consulter",
"accessReadCapability": "Elle peut lire tout ce que ce dossier partage. Elle ne peut rien ajouter ni rien modifier.",
"accessWriteLabel": "Peut consulter et ajouter",
- "accessWriteCapability": "Elle peut aussi ajouter des choses au dossier : des mesures, des résultats d'analyses, des allergies et d'autres observations, un nouveau médicament, et une prise marquée comme faite. Elle ne peut rien modifier ni supprimer, pas même ce qu'elle a ajouté. Vous êtes la seule personne à pouvoir le faire.",
+ "accessWriteCapability": "Elle peut aussi ajouter au dossier : des mesures, des résultats de laboratoire, un nouvel analyte à suivre, une entrée de maladie, une valeur sur une mesure que vous suivez vous-même, un effet indésirable lié à un médicament, un nouveau médicament, et marquer une dose comme prise ou sautée. Elle ne peut rien modifier ni supprimer, pas même ce qu'elle a ajouté, et elle ne peut pas reporter un de vos rappels. Vous seul le pouvez.",
"expiresLabel": "L'accès prend fin le (facultatif)",
"expiresHint": "Laissez ce champ vide pour un accès qui dure jusqu'à ce que quelqu'un y mette fin. Une date ici est vérifiée à chaque requête, l'accès s'arrête donc de lui-même à la fin de cette journée.",
"submit": "Envoyer l'invitation",
@@ -9513,7 +9514,8 @@
"customMetricEntryCreate": "{name} a enregistré une valeur personnalisée",
"medicationSideEffectCreate": "{name} a noté un effet indésirable",
"medicationCreate": "{name} a ajouté un médicament",
- "medicationIntake": "{name} a enregistré une prise"
+ "medicationIntake": "{name} a enregistré une prise",
+ "medicationIntakeRefused": "{name} a tenté de modifier une dose ou de reporter un rappel, et a été refusé"
}
}
}
diff --git a/messages/it.json b/messages/it.json
index c6a371967..b49f25c5d 100644
--- a/messages/it.json
+++ b/messages/it.json
@@ -9391,6 +9391,7 @@
"banner": {
"viewing": "Sei nella cartella di {name}",
"readOnly": "Puoi leggerla, non modificarla.",
+ "canAdd": "Puoi aggiungere qualcosa, ma non modificare né eliminare ciò che c'è.",
"leave": "Torna alla mia cartella"
},
"switcher": {
@@ -9437,7 +9438,7 @@
"accessReadLabel": "Può vedere",
"accessReadCapability": "Può leggere tutto ciò che questa cartella condivide. Non può aggiungere né modificare nulla.",
"accessWriteLabel": "Può vedere e aggiungere",
- "accessWriteCapability": "Può anche aggiungere qualcosa alla cartella: misurazioni, risultati di laboratorio, allergie e altre osservazioni, un nuovo farmaco e una dose segnata come presa. Non può modificare né eliminare nulla, nemmeno ciò che ha aggiunto. Puoi farlo solo tu.",
+ "accessWriteCapability": "Può anche aggiungere alla cartella: misurazioni, risultati di laboratorio, un nuovo analita da seguire, una voce di malattia, un valore su una metrica che segui tu, un effetto collaterale di un farmaco, un nuovo farmaco e segnare una dose come presa o saltata. Non può modificare né eliminare nulla, nemmeno ciò che ha aggiunto, e non può rimandare uno dei tuoi promemoria. Solo tu puoi.",
"expiresLabel": "L'accesso termina il (facoltativo)",
"expiresHint": "Lascia vuoto per un accesso che dura finché qualcuno non lo termina. Una data qui viene controllata a ogni richiesta, quindi l'accesso si interrompe da solo alla fine di quel giorno.",
"submit": "Invia invito",
@@ -9513,7 +9514,8 @@
"customMetricEntryCreate": "{name} ha registrato un valore personalizzato",
"medicationSideEffectCreate": "{name} ha annotato un effetto collaterale",
"medicationCreate": "{name} ha aggiunto un farmaco",
- "medicationIntake": "{name} ha registrato una dose"
+ "medicationIntake": "{name} ha registrato una dose",
+ "medicationIntakeRefused": "{name} ha provato a modificare una dose o a rimandare un promemoria, ed è stato rifiutato"
}
}
}
diff --git a/messages/pl.json b/messages/pl.json
index 27135a58e..e6d13a1e2 100644
--- a/messages/pl.json
+++ b/messages/pl.json
@@ -9391,6 +9391,7 @@
"banner": {
"viewing": "Jesteś w karcie użytkownika {name}",
"readOnly": "Możesz ją czytać, nie zmieniać.",
+ "canAdd": "Możesz coś dodać, ale nie zmieniać ani usuwać tego, co już jest.",
"leave": "Wróć do mojej karty"
},
"switcher": {
@@ -9437,7 +9438,7 @@
"accessReadLabel": "Może przeglądać",
"accessReadCapability": "Może czytać wszystko, co ta karta udostępnia. Nie może niczego dodać ani zmienić.",
"accessWriteLabel": "Może przeglądać i dodawać",
- "accessWriteCapability": "Może też dodawać do karty: pomiary, wyniki badań, alergie i inne obserwacje, nowy lek oraz oznaczenie dawki jako przyjętej. Nie może niczego edytować ani usuwać, także własnych wpisów. Możesz to zrobić tylko ty.",
+ "accessWriteCapability": "Może też dodawać do kartoteki: pomiary, wyniki badań, nowy analit do śledzenia, wpis o chorobie, wartość we własnej mierze, działanie niepożądane leku, nowy lek oraz oznaczyć dawkę jako przyjętą lub pominiętą. Nie może niczego edytować ani usuwać, nawet tego, co sama dodała, ani odłożyć żadnego z Twoich przypomnień. Tylko Ty możesz.",
"expiresLabel": "Dostęp kończy się (opcjonalnie)",
"expiresHint": "Zostaw puste, aby dostęp trwał, dopóki ktoś go nie zakończy. Data jest sprawdzana przy każdym żądaniu, więc dostęp kończy się sam z końcem tego dnia.",
"submit": "Wyślij zaproszenie",
@@ -9513,7 +9514,8 @@
"customMetricEntryCreate": "{name} zapisał własny pomiar",
"medicationSideEffectCreate": "{name} zanotował działanie niepożądane",
"medicationCreate": "{name} dodał lek",
- "medicationIntake": "{name} zapisał przyjęcie dawki"
+ "medicationIntake": "{name} zapisał przyjęcie dawki",
+ "medicationIntakeRefused": "{name} próbował(a) zmienić dawkę lub odłożyć przypomnienie i został(a) odrzucony(-a)"
}
}
}
diff --git a/src/app/api/medications/intake/route.ts b/src/app/api/medications/intake/route.ts
index 91f3839fa..cc3023de6 100644
--- a/src/app/api/medications/intake/route.ts
+++ b/src/app/api/medications/intake/route.ts
@@ -283,6 +283,61 @@ export const POST = apiHandler(async (request: NextRequest) => {
return apiError("Intake event not found", 404);
}
+ // v1.36.1 — this route is admitted for delegates because marking a dose is
+ // the thing a person standing next to the patient needs to do. It is an
+ // UPDATE, though, and two of the transitions it can express are not that.
+ //
+ // Snoozing writes `snoozedUntil` on the OWNER's medication row, and the
+ // reminder cron skips a medication for as long as that stamp is in the
+ // future. The field is unbounded, the owner is deliberately not notified of
+ // a delegated snooze (there is nothing useful to say about a thirty-minute
+ // deferral), and the activity feed renders the whole family as "marked a
+ // dose". So a delegate could switch the owner's medication reminders off for
+ // years, and every surface that exists to make delegation visible would
+ // describe it as marking a dose. In an adherence product that is the worst
+ // thing on this route.
+ //
+ // Flipping an already-resolved event is the other one: taken to skipped and
+ // back rewrites the owner's compliance history and refunds inventory. The
+ // shipped promise, on the consent screen and in the release notes, is that
+ // editing what is already there stays with the owner. Marking a dose that is
+ // still open is a contribution; changing a decision the owner already
+ // recorded is an edit.
+ //
+ // Both refuse for a delegate and stay open to the owner, who is the only
+ // person the snooze and the correction were ever for.
+ if (actor.id !== user.id) {
+ const alreadyResolved = existing.takenAt !== null || existing.skipped;
+ const refusal =
+ status === "snoozed"
+ ? "snooze"
+ : alreadyResolved
+ ? "resolved_event"
+ : null;
+ if (refusal) {
+ annotate({
+ action: { name: "medications.intake.update.refused" },
+ meta: { reason: refusal },
+ });
+ // Filed under the OWNER. `auditLog` stamps the actor itself from the
+ // request's acting context, which is what puts this on the trail the
+ // owner's activity panel reads — a refused attempt to change their
+ // record is worth as much to them as a successful one.
+ await auditLog("medications.intake.update.refused", {
+ userId: user.id,
+ ipAddress: getClientIp(request),
+ details: { intakeId, status, reason: refusal },
+ });
+ return apiError(
+ refusal === "snooze"
+ ? "Snoozing a reminder is not part of shared access"
+ : "Changing a dose that is already recorded is not part of shared access",
+ 403,
+ { errorCode: "sharing.not_permitted" },
+ );
+ }
+ }
+
// v1.8.5 — resolve + server-validate the optional injection site for a
// "taken" toggle. A site outside the medication's effective allowed
// set is a hard 422; non-injection / tracking-off / non-taken drops it.
@@ -557,9 +612,8 @@ export const POST = apiHandler(async (request: NextRequest) => {
}
// v1.36.x — "somebody else marked your dose". The helper refuses on self and
- // on a snooze, resolves both names itself, and never throws; awaited because
- // the latency it adds lands on the caregiver's request and never on the
- // owner's own hot path.
+ // on a snooze, resolves both names itself, and never throws.
+ //
// Fire and forget, like every neighbour above. The dispatcher awaits each
// channel in the cascade, so an unreachable one would have added its whole
// timeout to the caregiver's request — the person standing next to the
diff --git a/src/components/charts/health-chart.tsx b/src/components/charts/health-chart.tsx
index 55938706b..2e68cfcfb 100644
--- a/src/components/charts/health-chart.tsx
+++ b/src/components/charts/health-chart.tsx
@@ -2,6 +2,7 @@
import { useQuery } from "@tanstack/react-query";
import { useAuth } from "@/hooks/use-auth";
+import { useRecordCapabilities } from "@/hooks/use-record-capabilities";
import { queryKeys } from "@/lib/query-keys";
import { apiGet } from "@/lib/api/api-fetch";
import {
@@ -684,8 +685,23 @@ export function HealthChart({
// every chart card.
const viewportWidth = useViewportWidth();
+ // v1.36.1 — `useAuth()` answers about the person at the keyboard, and under a
+ // switch that is the delegate. Dividing the OWNER's weights by the
+ // DELEGATE's height squared produces a plausible-looking BMI that is simply
+ // somebody else's, shaded by fixed category bands, on a page that names the
+ // owner. The same substitution was fixed for the reference bands in this
+ // release; this is the same mistake one component over, and a wrong health
+ // figure is worse than an absent one.
+ //
+ // Inside a shared record the chart therefore draws no BMI at all rather than
+ // a wrong one. Publishing the owner's height to every client that can read
+ // their weights is a bigger decision than this fix, and it belongs with the
+ // per-module scope work rather than here.
+ const { inSharedRecord } = useRecordCapabilities();
const bmiDivisor =
- valueMode === "bmi" && user?.heightCm ? (user.heightCm / 100) ** 2 : null;
+ valueMode === "bmi" && !inSharedRecord && user?.heightCm
+ ? (user.heightCm / 100) ** 2
+ : null;
// v1.4.28 FB-D2 (R1.2 H0) — derive a bounded date window from the
// active range selector so the chart fetches only what it will
diff --git a/src/components/layout/shared-record-banner.tsx b/src/components/layout/shared-record-banner.tsx
index 610a11144..63651d3ef 100644
--- a/src/components/layout/shared-record-banner.tsx
+++ b/src/components/layout/shared-record-banner.tsx
@@ -75,13 +75,19 @@ export function SharedRecordBanner() {
{t("recordSharing.banner.viewing", { name })}
{" "}
- {/* Resolved server-side. `canWrite` is false for every grant in v1, and
- the day it is not, this line stops claiming otherwise on its own. */}
- {!active.canWrite && (
-
- {t("recordSharing.banner.readOnly")}
-
- )}
+ {/* Resolved server-side, and it says something at BOTH levels now.
+ v1.36.1 is the release that made `canWrite` true, and until this
+ line changed the write case rendered nothing at all: a delegate who
+ could add to somebody's health record was told only whose record it
+ was. That matters more than the read case, not less, and the rest of
+ the product leans on it — a control the record refuses is absent
+ rather than disabled, on the stated grounds that the banner names
+ the mode globally. It has to actually do that. */}
+
+ {active.canWrite
+ ? t("recordSharing.banner.canAdd")
+ : t("recordSharing.banner.readOnly")}
+