mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
fix(api): enforce range and source guards on the measurement edit path
PUT /api/measurements/[id] was the one write surface that skipped the per-type plausibility bands — POST, batch, CSV import, Apple export, Telegram and MCP all enforce VALUE_RANGES — so an implausible edited value flowed unchecked into rollups, the health score, the BP gates and the Coach snapshot. The route now validates the new value against the row's own type after the lookup and returns the standard multi-issue 422 envelope on violation. Value edits on server-owned sources (anything outside WRITABLE_MEASUREMENT_SOURCES: connector, import, computed rows) are refused with 409 and the stable errorCode measurement.update.server_owned_source — editing a provider-attributed number forges a reading the server never received. Timestamp and note edits stay allowed, and the edit sheet shows a localised message for the new code. The schema's generic min(0).max(500000) bound is dropped: the per-type band is stricter where it matters, and min(0) blocked legitimate edits of the signed types (ANS_CHARGE, BODY_TEMPERATURE_DEVIATION). Route tests cover out-of-range 422, negative signed-type accept, the server-owned 409, a timestamp-only edit on a server-owned row, and the happy path. The PUT endpoint is not part of the published OpenAPI surface — the generated contract is unchanged.
This commit is contained in:
1 parent
4846dcb478
commit
4b36d5ba52
10 files changed
+193
-10
No files matched your search
@@ -654,6 +654,15 @@ export function MeasurementList({
|
||||
setEditError(t("measurements.duplicateTimestamp"));
|
||||
return;
|
||||
}
|
||||
// v1.27.5 (di-001) — value edits on server-owned sources
|
||||
// (connector / import / computed rows) are refused with a 409.
|
||||
if (
|
||||
err instanceof ApiError &&
|
||||
err.meta?.errorCode === "measurement.update.server_owned_source"
|
||||
) {
|
||||
setEditError(t("measurements.serverOwnedSource"));
|
||||
return;
|
||||
}
|
||||
setEditError(
|
||||
err instanceof Error ? err.message : t("measurements.saveError"),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user