mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
Close the delegated-access gaps the release audit left open
Seven findings from the adversarial pass before v1.36.1 was tagged. One
blocking defect shipped in that release; these did not, and they are all places
where somebody looking after another person's health record meets a wall with
no explanation, or where a guard cannot fail.
The document vault was the largest. `/documents` is marked as a shared
destination, so the shell offers it under a switch, and every read behind it
resolved the caller instead of the record: the vault painted a query-error card
and the illness view painted another beside it. That is the same failure the
release describes as fixed on the dashboard. Five GET arms move to the record
resolver now, and only the GET arms: the list, one document, its file, its
thumbnail and the vault's usage payload, which the filter bar is built from.
Uploading, retyping, deleting, linking a document to an illness and every AI
verb stay with the owner, and the two reads that spend decryption CPU key
their quota on the person calling rather than the record, the rule
`medications/compliance` already follows.
Logging a value on a metric you track yourself leaves the admitted set. It was
admitted, named on the consent screen in six languages, and unreachable: the
only form that posts one sits on a page a shared record does not open, and the
component that renders it says so in its own comment while returning null. It
is the third route the rule that withdrew allergies and family history fitted
exactly, and it was applied to two of the three. Reading those values stays.
Two guards could not fail, and both were proved by mutation before and after.
The prefetch guard checked rule three with two regexes: one was satisfied by
the doc comment every page carries, the other missed an aliased import, and
the pair stayed green with the dashboard genuinely prefetching off the
switch-blind session. It reads the AST now, resolves aliases through the
module's own import table, and pins the five prefetching pages by name so a
page that stops being detected is loud. The activity verb map decided
membership on a literal `requireRecordAuth("write")`, so putting the argument
on its own line, which is what the formatter does the moment the call grows,
dropped a route out of the scan and turned a genuinely-red run green. Both
counts are of matches now rather than of files walked.
The rest are single instances of rules applied everywhere else. "Take all due"
was withheld on a note saying it rides the bulk intake route; it does not, and
its own docblock says why not, so a helper with five morning tablets tapped
five times for nothing. Marking a dose skipped is offered wherever marking it
taken is. A form could be opened in the frame before the app knew whose record
was on screen and then stood there once the answer arrived, on the capture
sheet and on the dashboard's quick-entry sheets. Two more copies of the intake
toast were still building their own, one of them with an Undo pointing at a
route no delegate may call. The customise link on the mood page led to a page
that exists to say it is not part of what was shared. And the access-level
radios on the invitation screen are hidden by design with no focus ring on
their label, so keyboard focus moved invisibly across the one screen where
somebody grants write access to their record.
Three new structural guards, each watched fail first: the customise link sits
inside a capability branch on every surface a delegate can reach, every intake
surface confirms through the one shared decision, and the batch sweep is
offered at the level that admits it.
This commit is contained in:
1 parent
80ecbd7454
commit
25e86b36b3
38 files changed
+1750
-128
No files matched your search
@@ -28,7 +28,7 @@
|
||||
*/
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { apiHandler, requireRecordAuth } from "@/lib/api-handler";
|
||||
import { apiError } from "@/lib/api-response";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { decryptDocumentContent } from "@/lib/documents/store";
|
||||
@@ -107,15 +107,23 @@ function safeDownloadName(
|
||||
return cleaned.length > 0 ? cleaned : `document-${id}.${ext}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* v1.36.x — delegable, and the read the rest of the vault exists to reach: a
|
||||
* caregiver looking at a discharge letter needs the letter, not its filing
|
||||
* card. Same file, same 1:1 owner-scoped lookup, resolved against the record.
|
||||
*
|
||||
* The bucket keys on the ACTOR for the reason the thumbnail's does — this one
|
||||
* decrypts a whole document per call, so it is the tighter of the two.
|
||||
*/
|
||||
export const GET = apiHandler(
|
||||
async (_request: Request, { params }: RouteParams) => {
|
||||
const { user } = await requireAuth();
|
||||
const { user, actor } = await requireRecordAuth("read");
|
||||
|
||||
const gate = await requireModuleEnabled(user.id, "inboundDocuments");
|
||||
if (!gate.enabled) return gate.response;
|
||||
|
||||
const rl = await checkRateLimit(
|
||||
`documents-original:${user.id}`,
|
||||
`documents-original:${actor.id}`,
|
||||
ORIGINAL_READ_LIMIT_PER_HOUR,
|
||||
ORIGINAL_READ_WINDOW_MS,
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { apiHandler, requireAuth, requireRecordAuth } from "@/lib/api-handler";
|
||||
import {
|
||||
apiError,
|
||||
apiSuccess,
|
||||
@@ -61,9 +61,22 @@ async function enforceWriteRateLimit(userId: string): Promise<Response | null> {
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET — one document of the record, with its facts and condition links.
|
||||
*
|
||||
* v1.36.x — delegable. The list beside it is; opening a row from that list is
|
||||
* the same read one document deeper, and a vault whose rows cannot be opened
|
||||
* is a vault the delegate can only count. The row is fetched under the
|
||||
* resolved user id before anything is serialised, so the substitution reaches
|
||||
* the query rather than a filter after it.
|
||||
*
|
||||
* The PATCH and DELETE below keep `requireAuth()`. Retyping a document,
|
||||
* relabelling it and deleting it are edits, and an edit stays with the owner —
|
||||
* including of a document the delegate has just read.
|
||||
*/
|
||||
export const GET = apiHandler(
|
||||
async (_request: NextRequest, { params }: RouteParams) => {
|
||||
const { user } = await requireAuth();
|
||||
const { user } = await requireRecordAuth("read");
|
||||
const gate = await requireModuleEnabled(user.id, "inboundDocuments");
|
||||
if (!gate.enabled) return gate.response;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { apiHandler, requireRecordAuth } from "@/lib/api-handler";
|
||||
import { apiError } from "@/lib/api-response";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { decryptThumbnail } from "@/lib/documents/store";
|
||||
@@ -40,15 +40,25 @@ export const dynamic = "force-dynamic";
|
||||
const THUMBNAIL_READ_LIMIT_PER_HOUR = 3000;
|
||||
const THUMBNAIL_READ_WINDOW_MS = 60 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* v1.36.x — delegable. The vault grid is a wall of thumbnails, so a list a
|
||||
* delegate may read whose tiles all 403 is the list without the part that
|
||||
* makes it browsable. The thumbnail carries no more than the document it
|
||||
* belongs to, which the same delegate may open.
|
||||
*
|
||||
* The bucket keys on the ACTOR, following `medications/compliance`: this read
|
||||
* spends decryption CPU, so a delegate burns their own allowance rather than
|
||||
* the owner's, and cannot collect a fresh one by switching records.
|
||||
*/
|
||||
export const GET = apiHandler(
|
||||
async (_request: Request, { params }: RouteParams) => {
|
||||
const { user } = await requireAuth();
|
||||
const { user, actor } = await requireRecordAuth("read");
|
||||
|
||||
const gate = await requireModuleEnabled(user.id, "inboundDocuments");
|
||||
if (!gate.enabled) return gate.response;
|
||||
|
||||
const rl = await checkRateLimit(
|
||||
`documents-thumbnail:${user.id}`,
|
||||
`documents-thumbnail:${actor.id}`,
|
||||
THUMBNAIL_READ_LIMIT_PER_HOUR,
|
||||
THUMBNAIL_READ_WINDOW_MS,
|
||||
);
|
||||
|
||||
@@ -27,7 +27,12 @@ import { createHash } from "node:crypto";
|
||||
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
import { apiHandler, requireAuth, type AuthContext } from "@/lib/api-handler";
|
||||
import {
|
||||
apiHandler,
|
||||
requireAuth,
|
||||
requireRecordAuth,
|
||||
type AuthContext,
|
||||
} from "@/lib/api-handler";
|
||||
import { apiError, apiSuccess, getClientIp } from "@/lib/api-response";
|
||||
import { auditLog } from "@/lib/auth/audit";
|
||||
import { prisma } from "@/lib/db";
|
||||
@@ -437,9 +442,23 @@ async function postUpload(request: Request): Promise<Response> {
|
||||
|
||||
export const POST = apiHandler(withIdempotency<[Request]>(postUpload));
|
||||
|
||||
/** GET — list the caller's documents (search / filter / sort / paginate). */
|
||||
/**
|
||||
* GET — list the record's documents (search / filter / sort / paginate).
|
||||
*
|
||||
* v1.36.x — delegable. `/documents` carries `sharedRecord: true` in the nav
|
||||
* model, so the shell offers the destination under a switch and every read
|
||||
* behind it refused: the vault rendered a query-error card, and the illness
|
||||
* page's episode-documents tile rendered another one beside it. A clinical
|
||||
* letter is health data belonging to the record, and reading it is the whole
|
||||
* point of handing somebody the record.
|
||||
*
|
||||
* The POST above is NOT delegable and keeps `requireAuth()`. Uploading is not
|
||||
* a verb the grant admits, and the module-level split matters here: the
|
||||
* resolver escalates any non-safe method to `"write"`, so the two arms have to
|
||||
* declare separately rather than share one line.
|
||||
*/
|
||||
export const GET = apiHandler(async (request: Request) => {
|
||||
const { user } = await requireAuth();
|
||||
const { user } = await requireRecordAuth("read");
|
||||
|
||||
const gate = await requireModuleEnabled(user.id, "inboundDocuments");
|
||||
if (!gate.enabled) return gate.response;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* still hold TOAST bytes until the purge job reclaims them, so "deleted"
|
||||
* bytes are never invisible weight and an undo never changes usage.
|
||||
*/
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { apiHandler, requireRecordAuth } from "@/lib/api-handler";
|
||||
import { apiSuccess } from "@/lib/api-response";
|
||||
import { prisma } from "@/lib/db";
|
||||
import {
|
||||
@@ -21,8 +21,20 @@ import type { DocumentUsageDto } from "@/lib/validations/inbound-documents";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* v1.36.x — delegable. The quota gauge is the least of it: this payload also
|
||||
* carries the filter bar's condition chips (the record's episodes that hold a
|
||||
* live document link) and the index-coverage counts, so without it the vault a
|
||||
* delegate may read loses its filters and reads as a flat pile. Every figure is
|
||||
* the record's own. The `assistAvailable` flag is an availability boolean of
|
||||
* the same integration-adjacent kind `nutrients` already returns — no
|
||||
* credential, endpoint or token crosses the wire, and every AI action it would
|
||||
* gate stays refused under a switch.
|
||||
*
|
||||
* No write arm exists on this route.
|
||||
*/
|
||||
export const GET = apiHandler(async () => {
|
||||
const { user } = await requireAuth();
|
||||
const { user } = await requireRecordAuth("read");
|
||||
const gate = await requireModuleEnabled(user.id, "inboundDocuments");
|
||||
if (!gate.enabled) return gate.response;
|
||||
|
||||
|
||||
Reference in new issue
Block a user