Skip to content

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

TypeScript

fix(signer-privacy): match built-in notice to deployment host and storage (#227)

Kevin Rose854ac34976bb
diff --git a/src/app/signer-privacy/page.tsx b/src/app/signer-privacy/page.tsx
index 21b1833..1c1cb3b 100644
--- a/src/app/signer-privacy/page.tsx
+++ b/src/app/signer-privacy/page.tsx
@@ -3,13 +3,14 @@ import { redirect } from "next/navigation";
import { connection } from "next/server";
import { PublicDocumentShell } from "@/components/layout/public-document-shell";
+import { STALE_DRAFT_RETENTION_DAYS } from "@/lib/retention";
import { ServiceConfigurationError } from "@/lib/services/service-config";
import {
getSettings,
resolveSettings,
type ResolvedSettings,
} from "@/lib/settings";
-import { STALE_DRAFT_RETENTION_DAYS } from "@/lib/retention";
+import { resolveSignerPrivacyPage } from "@/lib/signer-privacy";
import { isHostedMode } from "@/lib/utils/env";
export const metadata: Metadata = {
@@ -40,25 +41,17 @@ export default async function SignerPrivacyPage() {
}
const settings = await loadSignerPrivacySettings();
+ const resolved = resolveSignerPrivacyPage(settings);
- if (settings.hosted) {
- redirect("/privacy");
- }
-
- if (settings.privacyUrl) {
- redirect(settings.privacyUrl);
+ if (resolved.kind === "redirect") {
+ redirect(resolved.destination);
}
- const organization =
- settings.organizationName?.trim() || "The organization that runs this site";
- const contact = settings.supportAddress;
- const retention = settings.retentionDays
- ? `Finished documents and their audit trails are deleted ${String(settings.retentionDays)} days after they are finished.`
- : "Finished documents and their audit trails are kept until the organization deletes them, because they are evidence of an agreement and many must be kept for years by law.";
+ const { notice } = resolved;
return (
<PublicDocumentShell
- description={`${organization} uses this site to send documents for electronic signature. This notice says what is collected about you when you sign, why, and what you can do about it.`}
+ description={notice.description}
lastUpdated="2026-11-13"
title="Privacy notice for signers"
>
@@ -67,13 +60,13 @@ export default async function SignerPrivacyPage() {
Who is responsible
</h2>
<p>
- {organization} is responsible for your information (the
+ {notice.organizationSubject} is responsible for your information (the
&ldquo;controller&rdquo;).{" "}
- {contact ? (
+ {notice.contact ? (
<>
Contact them at{" "}
- <a className="underline" href={`mailto:${contact}`}>
- {contact}
+ <a className="underline" href={notice.contact.href}>
+ {notice.contact.address}
</a>
.
</>
@@ -120,15 +113,7 @@ export default async function SignerPrivacyPage() {
<h2 className="text-xl font-extrabold tracking-[-0.02em] text-(--fg)">
Who else handles it
</h2>
- <p>
- The other parties to the document see your name, email and signature.
- The services that run this site process it for {organization}: the
- hosting provider (Vercel), the database provider (such as Neon), file
- storage (Vercel Blob) and the email provider (Resend). Some are based
- in the United States; where information leaves the European Economic
- Area, it is protected by the EU-US Data Privacy Framework or by
- standard contractual clauses.
- </p>
+ <p>{notice.processors}</p>
</section>
<section className="space-y-3">
@@ -136,7 +121,7 @@ export default async function SignerPrivacyPage() {
How long it is kept
</h2>
<p>
- {retention} Unsent drafts are deleted after{" "}
+ {notice.retention} Unsent drafts are deleted after{" "}
{String(STALE_DRAFT_RETENTION_DAYS)} days without changes.
</p>
</section>
@@ -145,13 +130,7 @@ export default async function SignerPrivacyPage() {
<h2 className="text-xl font-extrabold tracking-[-0.02em] text-(--fg)">
Your rights
</h2>
- <p>
- You can ask {organization} for a copy of your information, to correct
- it, to restrict or object to its use, or to erase it. A signed record
- may be kept despite a request to erase it while it is needed as
- evidence or by law (GDPR Article 17(3)). You can also complain to the
- data protection authority where you live or work.
- </p>
+ <p>{notice.rights}</p>
</section>
</PublicDocumentShell>
);
diff --git a/src/lib/signer-privacy.test.ts b/src/lib/signer-privacy.test.ts
new file mode 100644
index 0000000..b9ecc09
--- /dev/null
+++ b/src/lib/signer-privacy.test.ts
@@ -0,0 +1,308 @@
+import assert from "node:assert/strict";
+import { test } from "node:test";
+
+import {
+ buildSignerPrivacyNotice,
+ buildSignerPrivacyProcessorsText,
+ resolveSignerPrivacyDeployment,
+ resolveSignerPrivacyPage,
+ type SignerPrivacySettings,
+} from "./signer-privacy.ts";
+
+const baseSettings: SignerPrivacySettings = {
+ hosted: false,
+ organizationName: "Acme Documents",
+ privacyUrl: null,
+ retentionDays: null,
+ supportAddress: "[email protected]",
+};
+
+test("resolveSignerPrivacyDeployment detects hosting and storage combinations", () => {
+ assert.deepEqual(resolveSignerPrivacyDeployment({}), {
+ hosting: "self-hosted",
+ storage: "local",
+ });
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({ STORAGE_DRIVER: "local" }),
+ {
+ hosting: "self-hosted",
+ storage: "local",
+ },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({
+ BLOB_READ_WRITE_TOKEN: "vercel_blob_rw_secret",
+ STORAGE_DRIVER: "local",
+ }),
+ {
+ hosting: "self-hosted",
+ storage: "local",
+ },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({
+ BLOB_READ_WRITE_TOKEN: "vercel_blob_rw_secret",
+ }),
+ {
+ hosting: "self-hosted",
+ storage: "blob",
+ },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({ BLOB_STORE_ID: "store_123" }),
+ {
+ hosting: "self-hosted",
+ storage: "blob",
+ },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({ STORAGE_DRIVER: " Blob " }),
+ {
+ hosting: "self-hosted",
+ storage: "blob",
+ },
+ );
+ assert.deepEqual(resolveSignerPrivacyDeployment({ VERCEL: "1" }), {
+ hosting: "vercel",
+ storage: "blob",
+ });
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({
+ BLOB_READ_WRITE_TOKEN: "vercel_blob_rw_secret",
+ VERCEL: "1",
+ }),
+ {
+ hosting: "vercel",
+ storage: "blob",
+ },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({ STORAGE_DRIVER: "local", VERCEL: "1" }),
+ {
+ hosting: "vercel",
+ storage: "local",
+ },
+ );
+});
+
+test("resolveSignerPrivacyDeployment falls back cleanly when STORAGE_DRIVER is unrecognized", () => {
+ assert.deepEqual(resolveSignerPrivacyDeployment({ STORAGE_DRIVER: "r2" }), {
+ hosting: "self-hosted",
+ storage: "local",
+ });
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({
+ BLOB_READ_WRITE_TOKEN: "vercel_blob_rw_secret",
+ STORAGE_DRIVER: "r2",
+ }),
+ {
+ hosting: "self-hosted",
+ storage: "blob",
+ },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyDeployment({ STORAGE_DRIVER: "r2", VERCEL: "1" }),
+ {
+ hosting: "vercel",
+ storage: "blob",
+ },
+ );
+});
+
+test("self-hosted local-storage notice describes the organization's own host and storage without naming Vercel or Neon", () => {
+ const notice = buildSignerPrivacyNotice(baseSettings, {});
+
+ assert.deepEqual(notice.deployment, {
+ hosting: "self-hosted",
+ storage: "local",
+ });
+ assert.equal(notice.organizationSubject, "Acme Documents");
+ assert.deepEqual(notice.contact, {
+ address: "[email protected]",
+ href: "mailto:[email protected]",
+ });
+ assert.doesNotMatch(notice.processors, /Vercel|Neon/);
+ assert.match(
+ notice.processors,
+ /Acme Documents hosts this site and stores documents on its own storage alongside its database/,
+ );
+ assert.match(notice.processors, /email provider \(Resend\)/);
+ assert.match(
+ notice.processors,
+ /process your information for Acme Documents/,
+ );
+ assert.match(notice.processors, /EU-US Data Privacy Framework/);
+
+ // Explicit STORAGE_DRIVER=local still avoids Vercel Blob even if Blob creds exist.
+ const explicitLocal = buildSignerPrivacyNotice(baseSettings, {
+ BLOB_READ_WRITE_TOKEN: "vercel_blob_rw_secret",
+ STORAGE_DRIVER: "local",
+ });
+
+ assert.equal(explicitLocal.processors, notice.processors);
+});
+
+test("self-hosted notice with Vercel Blob names Vercel Blob for storage but not Vercel as host", () => {
+ const notice = buildSignerPrivacyNotice(baseSettings, {
+ BLOB_READ_WRITE_TOKEN: "vercel_blob_rw_secret",
+ });
+
+ assert.deepEqual(notice.deployment, {
+ hosting: "self-hosted",
+ storage: "blob",
+ });
+ assert.doesNotMatch(notice.processors, /hosting provider \(Vercel\)|Neon/);
+ assert.match(
+ notice.processors,
+ /Acme Documents hosts this site alongside its database/,
+ );
+ assert.match(notice.processors, /file storage \(Vercel Blob\)/);
+ assert.match(notice.processors, /email provider \(Resend\)/);
+ assert.match(
+ notice.processors,
+ /process your information for Acme Documents/,
+ );
+});
+
+test("Vercel + Vercel Blob notice names Vercel, Neon, Vercel Blob and Resend", () => {
+ const notice = buildSignerPrivacyNotice(baseSettings, { VERCEL: "1" });
+
+ assert.deepEqual(notice.deployment, {
+ hosting: "vercel",
+ storage: "blob",
+ });
+ assert.match(notice.processors, /process it for Acme Documents:/);
+ assert.match(notice.processors, /hosting provider \(Vercel\)/);
+ assert.match(notice.processors, /database provider \(such as Neon\)/);
+ assert.match(notice.processors, /file storage \(Vercel Blob\)/);
+ assert.match(notice.processors, /email provider \(Resend\)/);
+});
+
+test("Vercel deployment with explicit STORAGE_DRIVER=local does not attribute storage to Vercel Blob", () => {
+ const text = buildSignerPrivacyProcessorsText("Acme Documents", {
+ hosting: "vercel",
+ storage: "local",
+ });
+
+ assert.match(text, /hosting provider \(Vercel\)/);
+ assert.doesNotMatch(text, /Vercel Blob/);
+ assert.match(text, /configured file storage/);
+});
+
+test("blank or unset organization name reads grammatically across all deployment combinations", () => {
+ for (const env of [
+ {},
+ { BLOB_STORE_ID: "store_123" },
+ { VERCEL: "1" },
+ ] as const) {
+ const notice = buildSignerPrivacyNotice(
+ { ...baseSettings, organizationName: " " },
+ env,
+ );
+
+ assert.equal(
+ notice.organizationSubject,
+ "The organization that runs this site",
+ );
+ assert.equal(
+ notice.organizationObject,
+ "the organization that runs this site",
+ );
+ assert.match(
+ notice.description,
+ /^The organization that runs this site uses this site/,
+ );
+ assert.match(
+ notice.rights,
+ /^You can ask the organization that runs this site for a copy/,
+ );
+ assert.doesNotMatch(notice.processors, /runs this site hosts this site/);
+ assert.doesNotMatch(notice.processors, /for The organization/);
+ }
+
+ const localUnnamed = buildSignerPrivacyNotice(
+ { ...baseSettings, organizationName: null },
+ {},
+ );
+ assert.doesNotMatch(localUnnamed.processors, /Vercel|Neon/);
+ assert.match(
+ localUnnamed.processors,
+ /The organization that runs this site hosts it and stores documents on its own storage alongside its database/,
+ );
+ assert.match(localUnnamed.processors, /process your information for it\./);
+
+ const blobUnnamed = buildSignerPrivacyNotice(
+ { ...baseSettings, organizationName: null },
+ { BLOB_READ_WRITE_TOKEN: "vercel_blob_rw_secret" },
+ );
+ assert.doesNotMatch(blobUnnamed.processors, /hosting provider \(Vercel\)/);
+ assert.match(
+ blobUnnamed.processors,
+ /The organization that runs this site hosts it alongside its database/,
+ );
+ assert.match(blobUnnamed.processors, /file storage \(Vercel Blob\)/);
+ assert.match(blobUnnamed.processors, /process your information for it\./);
+});
+
+test("resolveSignerPrivacyPage redirects in hosted mode and when a custom privacy URL is set", () => {
+ assert.deepEqual(
+ resolveSignerPrivacyPage(baseSettings, { HOSTED_MODE: "1" }),
+ { destination: "/privacy", kind: "redirect" },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyPage(
+ { ...baseSettings, privacyUrl: "https://example.org/privacy" },
+ { HOSTED_MODE: "true" },
+ ),
+ { destination: "/privacy", kind: "redirect" },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyPage({ ...baseSettings, hosted: true }, {}),
+ { destination: "/privacy", kind: "redirect" },
+ );
+ assert.deepEqual(
+ resolveSignerPrivacyPage(
+ { ...baseSettings, privacyUrl: " https://example.org/privacy " },
+ {},
+ ),
+ { destination: "https://example.org/privacy", kind: "redirect" },
+ );
+
+ const resolved = resolveSignerPrivacyPage(
+ { ...baseSettings, privacyUrl: " " },
+ {},
+ );
+ assert.equal(resolved.kind, "notice");
+ assert.doesNotMatch(resolved.notice.processors, /Vercel/);
+});
+
+test("buildSignerPrivacyNotice formats retention and support contact from settings", () => {
+ const timed = buildSignerPrivacyNotice(
+ {
+ ...baseSettings,
+ retentionDays: 90,
+ supportAddress: "Acme Support <[email protected]>",
+ },
+ {},
+ );
+
+ assert.equal(
+ timed.retention,
+ "Finished documents and their audit trails are deleted 90 days after they are finished.",
+ );
+ assert.deepEqual(timed.contact, {
+ address: "[email protected]",
+ href: "mailto:[email protected]",
+ });
+
+ const indefinite = buildSignerPrivacyNotice(
+ { ...baseSettings, retentionDays: null, supportAddress: null },
+ {},
+ );
+
+ assert.match(
+ indefinite.retention,
+ /kept until the organization deletes them/,
+ );
+ assert.equal(indefinite.contact, null);
+});
diff --git a/src/lib/signer-privacy.ts b/src/lib/signer-privacy.ts
new file mode 100644
index 0000000..bcd8d44
--- /dev/null
+++ b/src/lib/signer-privacy.ts
@@ -0,0 +1,162 @@
+import { buildPublicSupportLink, type PublicSupportLink } from "./legal.ts";
+import {
+ hasBlobCredentials,
+ resolveStorageDriver,
+ type StorageDriver,
+} from "./services/storage/driver.ts";
+import type { ResolvedSettings } from "./settings.ts";
+import { isHostedMode, readEnv, type EnvSource } from "./utils/env.ts";
+
+// Built-in GDPR Article 13 notice for signers on a non-hosted install when
+// the organization has not linked its own privacy policy. The processor copy
+// follows the instance's actual hosting and file storage instead of assuming
+// every install runs on Vercel and Vercel Blob.
+
+const DEFAULT_ORGANIZATION_SUBJECT = "The organization that runs this site";
+const DEFAULT_ORGANIZATION_OBJECT = "the organization that runs this site";
+
+const EEA_TRANSFER_CLAUSE =
+ "where information leaves the European Economic Area, it is protected by the EU-US Data Privacy Framework or by standard contractual clauses.";
+
+export type SignerPrivacyHosting = "self-hosted" | "vercel";
+
+export type SignerPrivacyDeployment = {
+ hosting: SignerPrivacyHosting;
+ storage: StorageDriver;
+};
+
+export type SignerPrivacySettings = Pick<
+ ResolvedSettings,
+ | "hosted"
+ | "organizationName"
+ | "privacyUrl"
+ | "retentionDays"
+ | "supportAddress"
+>;
+
+export type SignerPrivacyNotice = {
+ contact: PublicSupportLink | null;
+ deployment: SignerPrivacyDeployment;
+ description: string;
+ organizationObject: string;
+ organizationSubject: string;
+ processors: string;
+ retention: string;
+ rights: string;
+};
+
+export type SignerPrivacyPageResolution =
+ | { destination: string; kind: "redirect" }
+ | { kind: "notice"; notice: SignerPrivacyNotice };
+
+function resolveStorageForNotice(
+ env: EnvSource,
+ onVercel: boolean,
+): StorageDriver {
+ try {
+ return resolveStorageDriver(env);
+ } catch {
+ // An unrecognized STORAGE_DRIVER should not stop the privacy notice from
+ // rendering; fall back to the same detection rule as driver.ts.
+ return hasBlobCredentials(env) || onVercel ? "blob" : "local";
+ }
+}
+
+/** How this deployment hosts the app and stores uploaded documents. */
+export function resolveSignerPrivacyDeployment(
+ env: EnvSource = process.env,
+): SignerPrivacyDeployment {
+ const onVercel = readEnv(env, "VERCEL") === "1";
+
+ return {
+ hosting: onVercel ? "vercel" : "self-hosted",
+ storage: resolveStorageForNotice(env, onVercel),
+ };
+}
+
+/**
+ * The "Who else handles it" paragraph for the built-in signer privacy notice,
+ * naming Vercel and Vercel Blob only when this deployment actually uses them.
+ */
+export function buildSignerPrivacyProcessorsText(
+ organizationName: string | null | undefined,
+ deployment: SignerPrivacyDeployment,
+): string {
+ const namedOrganization = organizationName?.trim() || null;
+ const organizationObject = namedOrganization ?? DEFAULT_ORGANIZATION_OBJECT;
+ const intro =
+ "The other parties to the document see your name, email and signature.";
+
+ if (deployment.hosting === "vercel") {
+ const storagePhrase =
+ deployment.storage === "blob"
+ ? "file storage (Vercel Blob)"
+ : "the site's configured file storage";
+
+ return `${intro} The services that run this site process it for ${organizationObject}: the hosting provider (Vercel), the database provider (such as Neon), ${storagePhrase} and the email provider (Resend). Some are based in the United States; ${EEA_TRANSFER_CLAUSE}`;
+ }
+
+ const hostClause = namedOrganization
+ ? `${namedOrganization} hosts this site`
+ : `${DEFAULT_ORGANIZATION_SUBJECT} hosts it`;
+ const processorTarget = namedOrganization ?? "it";
+
+ if (deployment.storage === "blob") {
+ return `${intro} ${hostClause} alongside its database. Any hosting or database provider it uses, file storage (Vercel Blob) and the email provider (Resend) process your information for ${processorTarget}. Some are based in the United States; ${EEA_TRANSFER_CLAUSE}`;
+ }
+
+ return `${intro} ${hostClause} and stores documents on its own storage alongside its database. Any hosting or database provider it uses, and the email provider (Resend) when emails are sent, process your information for ${processorTarget}. Where any of those services are based in the United States and ${EEA_TRANSFER_CLAUSE.slice("where ".length)}`;
+}
+
+/** Builds the text and links for the built-in signer privacy notice. */
+export function buildSignerPrivacyNotice(
+ settings: Pick<
+ SignerPrivacySettings,
+ "organizationName" | "retentionDays" | "supportAddress"
+ >,
+ env: EnvSource = process.env,
+): SignerPrivacyNotice {
+ const namedOrganization = settings.organizationName?.trim() || null;
+ const organizationSubject = namedOrganization ?? DEFAULT_ORGANIZATION_SUBJECT;
+ const organizationObject = namedOrganization ?? DEFAULT_ORGANIZATION_OBJECT;
+ const deployment = resolveSignerPrivacyDeployment(env);
+ const retention = settings.retentionDays
+ ? `Finished documents and their audit trails are deleted ${String(settings.retentionDays)} days after they are finished.`
+ : "Finished documents and their audit trails are kept until the organization deletes them, because they are evidence of an agreement and many must be kept for years by law.";
+
+ return {
+ contact: buildPublicSupportLink(settings.supportAddress),
+ deployment,
+ description: `${organizationSubject} uses this site to send documents for electronic signature. This notice says what is collected about you when you sign, why, and what you can do about it.`,
+ organizationObject,
+ organizationSubject,
+ processors: buildSignerPrivacyProcessorsText(namedOrganization, deployment),
+ retention,
+ rights: `You can ask ${organizationObject} for a copy of your information, to correct it, to restrict or object to its use, or to erase it. A signed record may be kept despite a request to erase it while it is needed as evidence or by law (GDPR Article 17(3)). You can also complain to the data protection authority where you live or work.`,
+ };
+}
+
+/**
+ * Resolves `/signer-privacy`: hosted installs use `/privacy`, organizations
+ * with a published policy redirect there, and everyone else gets the built-in
+ * notice tailored to this deployment.
+ */
+export function resolveSignerPrivacyPage(
+ settings: SignerPrivacySettings,
+ env: EnvSource = process.env,
+): SignerPrivacyPageResolution {
+ if (isHostedMode(env) || settings.hosted) {
+ return { destination: "/privacy", kind: "redirect" };
+ }
+
+ const customPrivacyUrl = settings.privacyUrl?.trim();
+
+ if (customPrivacyUrl) {
+ return { destination: customPrivacyUrl, kind: "redirect" };
+ }
+
+ return {
+ kind: "notice",
+ notice: buildSignerPrivacyNotice(settings, env),
+ };
+}