mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
fix(share): stop serving shared documents once the documents module is off
A share link gated its report on the doctorReport module but listed and served its attached documents unconditionally, although the comment beside the gate said the documents kept a gate of their own. An owner who switched the documents module off still had every attached file decrypted for anyone holding the link and its passphrase. The share page lists no document while the module is off, and the document route answers 404, the same as for an unknown document, before it looks the membership up.
This commit is contained in:
1 parent
d1fcbca63b
commit
989381b3f6
4 files changed
+46
-2
No files matched your search
@@ -49,6 +49,9 @@ vi.mock("@/lib/rate-limit", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/logging/transports", () => ({ emitIfSampled: vi.fn() }));
|
||||
vi.mock("@/lib/modules/gate", () => ({
|
||||
isModuleEnabled: vi.fn(async () => true),
|
||||
}));
|
||||
vi.mock("@/lib/db-compat", () => ({
|
||||
ensureDbCompatibility: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
@@ -70,6 +73,7 @@ import {
|
||||
import { verifyUnlockValue } from "@/lib/clinician-share/unlock-cookie";
|
||||
import { checkRateLimit } from "@/lib/rate-limit";
|
||||
import { encryptDocumentToBytes } from "@/lib/documents/store";
|
||||
import { isModuleEnabled } from "@/lib/modules/gate";
|
||||
|
||||
const TOKEN = "hls_000000000000000000000000000000000000000000000000";
|
||||
const OWNER = "owner-1";
|
||||
@@ -164,6 +168,17 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
describe("GET /c/[token]/d/[id] — share document serve", () => {
|
||||
it("answers 404 once the owner switched the documents module off", async () => {
|
||||
seedMembership({ mimeType: "application/pdf", bytes: PDF_BYTES });
|
||||
vi.mocked(isModuleEnabled).mockResolvedValueOnce(false);
|
||||
|
||||
const res = await callGet(makeReq("doc-1"), ctx("doc-1"));
|
||||
|
||||
expect(res.status).toBe(404);
|
||||
expect(isModuleEnabled).toHaveBeenCalledWith(OWNER, "inboundDocuments");
|
||||
expect(prisma.clinicianShareLinkDocument.findUnique).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("serves a PDF inline through the token, confined to the frozen set", async () => {
|
||||
seedMembership({ mimeType: "application/pdf", bytes: PDF_BYTES });
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import { prisma } from "@/lib/db";
|
||||
import { decryptDocumentContent } from "@/lib/documents/store";
|
||||
import { servingClassFor } from "@/lib/documents/upload-policy";
|
||||
import { annotate } from "@/lib/logging/context";
|
||||
import { isModuleEnabled } from "@/lib/modules/gate";
|
||||
import { checkRateLimit, rateLimitHeaders } from "@/lib/rate-limit";
|
||||
|
||||
type RouteParams = { params: Promise<{ token: string; id: string }> };
|
||||
@@ -169,6 +170,11 @@ export const GET = apiHandler(
|
||||
// access counters are bumped fire-and-forget.
|
||||
const context = await resolveShareToken(token);
|
||||
if (!context) return notFound();
|
||||
// The owner switched the documents module off: no document leaves, the
|
||||
// same answer as an unknown one.
|
||||
if (!(await isModuleEnabled(context.ownerUserId, "inboundDocuments"))) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
// 5. Confine to the frozen set: the document must be a member of THIS
|
||||
// link, owned by the link's owner, and live. The composite lookup ties
|
||||
|
||||
Reference in new issue
Block a user