Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Keep teammates from setting an envelope's shared thumbnail
Matthew Jacksonf7c7252efee7
diff --git a/src/app/api/envelopes/[id]/thumbnail/route.ts b/src/app/api/envelopes/[id]/thumbnail/route.tsindex 82dd190..d98986e 100644--- a/src/app/api/envelopes/[id]/thumbnail/route.ts+++ b/src/app/api/envelopes/[id]/thumbnail/route.ts@@ -164,15 +164,25 @@ export async function PUT();}- // An administrator's or a teammate's browser draws a missing picture- // too, and keeps it for everyone, so it is not drawn again on every- // visit.+ // An administrator's browser draws a missing picture too, and keeps it+ // for everyone, so it is not drawn again on every visit. A teammate's+ // browser draws one for itself but cannot keep it: the picture is+ // checked to be a JPEG, not to be this document, and whoever stores it+ // first decides what everyone sees, which a teammate with read-only+ // access should not.const access = await resolveEnvelopeViewerAccess(session.user.id,id,getDb(),);+ if (access && !access.viewerIsOwner && !access.viewerIsAdmin) {+ return NextResponse.json(+ { error: "Only the sender can save this thumbnail." },+ { headers: privateNoStore, status: 403 },+ );+ }+await saveEnvelopeThumbnailForUser(access?.ownerUserId ?? session.user.id,id,diff --git a/src/lib/envelope-access.dbtest.ts b/src/lib/envelope-access.dbtest.tsindex a0905a3..5ccc567 100644--- a/src/lib/envelope-access.dbtest.ts+++ b/src/lib/envelope-access.dbtest.ts@@ -76,6 +76,7 @@ test("the sender sees their own envelope", async () => {ownerEmail: sender.email,ownerName: "Sam Sender",ownerUserId: sender.userId,+ viewerIsAdmin: false,viewerIsOwner: true,},);@@ -92,6 +93,7 @@ test("an administrator sees another member's envelope, and whose it is", async (ownerEmail: sender.email,ownerName: "Sam Sender",ownerUserId: sender.userId,+ viewerIsAdmin: true,viewerIsOwner: false,},);diff --git a/src/lib/envelope-access.ts b/src/lib/envelope-access.tsindex 6925d49..2058f42 100644--- a/src/lib/envelope-access.ts+++ b/src/lib/envelope-access.ts@@ -12,6 +12,8 @@ export type EnvelopeViewerAccess = {ownerEmail: string;ownerName: string | null;ownerUserId: string;+ /** Whether the viewer is an administrator of the install. */+ viewerIsAdmin: boolean;/*** False when an administrator, or someone on a team with the sender, is* looking at someone else's envelope.@@ -94,6 +96,7 @@ export async function resolveEnvelopeViewerAccess(ownerEmail: row.ownerEmail,ownerName: row.ownerName,ownerUserId: row.ownerUserId,+ viewerIsAdmin: row.viewerRole === "admin",viewerIsOwner,};}diff --git a/src/lib/team-access.dbtest.ts b/src/lib/team-access.dbtest.tsindex 2a9122c..aaba085 100644--- a/src/lib/team-access.dbtest.ts+++ b/src/lib/team-access.dbtest.ts@@ -313,6 +313,9 @@ test("a teammate and an administrator see a sent envelope as someone else's", asassert.equal(access?.ownerUserId, owner.id);assert.equal(access?.viewerIsOwner, false);+ // Only an administrator may keep a thumbnail drawn for someone+ // else's envelope.+ assert.equal(access?.viewerIsAdmin, viewer === admin);}assert.equal(