Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Serve thumbnails without browser caching, and pin each to its own file

Claudeef80ece453fb
diff --git a/e2e/signing-flow.spec.ts b/e2e/signing-flow.spec.ts
index 0ab8826..4744156 100644
--- a/e2e/signing-flow.spec.ts
+++ b/e2e/signing-flow.spec.ts
@@ -385,13 +385,16 @@ test("a new install is set up, a sender sends a PDF and a recipient signs it", a
.toBeGreaterThan(0);
// The picture is stored beside the PDF, as a JPEG, and only the account
- // that sent the document can read it.
+ // that sent the document can read it. The browser is told to keep no
+ // copy, as it is for the document itself.
await expect
.poll(async () => (await page.request.get(thumbnailPath)).status())
.toBe(200);
- expect(
- (await page.request.get(thumbnailPath)).headers()["content-type"],
- ).toBe("image/jpeg");
+
+ const thumbnailHeaders = (await page.request.get(thumbnailPath)).headers();
+
+ expect(thumbnailHeaders["content-type"]).toBe("image/jpeg");
+ expect(thumbnailHeaders["cache-control"]).toBe("private, no-store");
const anonymousContext = await browser.newContext();
diff --git a/src/app/api/envelopes/[id]/thumbnail/route.ts b/src/app/api/envelopes/[id]/thumbnail/route.ts
index 7e5de29..52949ee 100644
--- a/src/app/api/envelopes/[id]/thumbnail/route.ts
+++ b/src/app/api/envelopes/[id]/thumbnail/route.ts
@@ -47,10 +47,10 @@ export async function GET(
database: getDb(),
});
const headers = new Headers({
- // The original PDF of an envelope never changes, so neither does this.
- // An hour keeps the dashboard quick without holding a deleted draft's
- // picture in the browser for long.
- "cache-control": "private, max-age=3600",
+ // As private as the document it was drawn from, and served the same
+ // way: the browser keeps no copy, so showing it always takes a
+ // signed-in request from the account that owns the envelope.
+ ...privateNoStore,
"content-disposition": "inline",
// Stored as a JPEG whatever the upload claimed to be, and served as
// nothing else.
diff --git a/src/components/envelopes/upload-shell.tsx b/src/components/envelopes/upload-shell.tsx
index 725b7f4..2da7925 100644
--- a/src/components/envelopes/upload-shell.tsx
+++ b/src/components/envelopes/upload-shell.tsx
@@ -484,6 +484,11 @@ export function UploadShell({ directUploadPrefix = null }: UploadShellProps) {
setIsCreatingDraft(true);
setErrorMessage(null);
+ // Taken now, with the file. The file can still be removed and another
+ // chosen while the draft is being created, and that one's picture must
+ // not end up on this draft.
+ const thumbnailForDraft = thumbnailRef.current;
+
try {
try {
await assertPdfPreviewRenderable(summary.file);
@@ -532,7 +537,7 @@ export function UploadShell({ directUploadPrefix = null }: UploadShellProps) {
// Not waited for: the dashboard draws one later if this is lost.
const createdEnvelopeId = payload.data.envelopeId;
- void thumbnailRef.current?.then((thumbnail) =>
+ void thumbnailForDraft?.then((thumbnail) =>
thumbnail
? uploadEnvelopeThumbnail(createdEnvelopeId, thumbnail)
: false,