The email gate
An optional page in front of a share link. A reader gives an address, gets a signed pass, and the artifact loads. Off by default — a deployment that does not configure it behaves exactly as before. The decision and its trade-offs are in ADR 0004; this page is how to run it.
What the reader sees
GET /s/<token> → the gate: title, one email field, one consent line, one button
POST /s/<token> → stores the lead, sets the pass, 303 → /s/<token>
GET /s/<token> + pass → the artifact, as before
The gate page is written by artifactkit, not by the artifact's author: inline CSS, system fonts, no
script, no external asset. If scripting is off, the form still submits — it is a plain POST. The
page is no-store, noindex, and refuses to be framed.
/v/<id> (staff views) and /api/* are never gated, gate on or off.
Enable it
import { createArtifactHandler } from '@artifactkitdev/core/http';
import { posthogTelemetry } from '@artifactkitdev/core/adapters/telemetry';
const handler = createArtifactHandler({
deps,
artifactsHost: env.ARTIFACTS_HOST,
frameAncestors: [],
gate: {
enabled: true,
leads: adapter.leads, // the LeadStore port: memory, fs, or your own
analytics: posthogTelemetry({ apiKey: env.POSTHOG_KEY }), // optional but this is the lead list
consent: 'We’ll email you about this artifact. No list-sharing.',
},
});
gate.analytics is any object with capture({ name, distinctId, properties }) — the telemetry
adapters already have that shape, so nothing needs wrapping.
| option | default | meaning |
|---|---|---|
enabled | false | gates every share link on this deployment; staff views are never gated |
leads | required when enabled | a LeadStore |
analytics | none | where artifact.lead.captured goes; without it leads exist only in leads |
consent | the built-in sentence | the line above the button |
passTtlSeconds | 30 days | how long one reader's pass lasts |
limiter | in-process, 5 / 10 min per reader and 50 / hour per artifact | a RateLimiter |
Where the leads are
Each accepted address is one row: { artifactId, email, version, capturedAt }. A repeat submission
of the same address for the same artifact is ignored (record returns false) — a second visit is
not a second lead — and no second event is emitted, so the count and the event stream agree.
The event is the durable list:
artifact.lead.captured distinct_id = the address properties = { artifact_id, version }
That event is published to gate.analytics only. It is not written to the artifact event log, is
not returned by GET /api/artifacts/{id}/events, and is not delivered to webhook subscribers —
because an address in that log is an address in an API response. If you want leads in a CRM, write a
LeadStore adapter for the CRM; do not subscribe a webhook to the address.
The local store keeps rows for 400 days. Nothing deletes them on a timer — serverless has no
timer you can trust — so run prune from whatever cron you already have:
const cutoff = new Date(Date.now() - 400 * 24 * 60 * 60 * 1000).toISOString();
const removed = await leads.prune(cutoff);
console.log(`pruned ${removed} leads older than ${cutoff}`);
To honour a deletion request, prune with that address's date or delete the row through your own adapter; the gate does not ship a mailing list and has no unsubscribe flow. Unsubscribing happens in whatever tool sends the mail, and that tool is the operator's.
The pass
__Host-akg=g1.<artifactId>.<exp>.<signature>; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=2592000
- Signed with the deployment's existing
TokenSigner(the same secret as staff view tokens). Rotating that secret invalidates every live pass, which is the intended behaviour. - Scoped to the artifact id in the payload: a pass for one artifact opens nothing else.
- Stateless. There is no session table, no cleanup job, and a lost cookie is just a reader filling in the form again.
- Revoking the share link is the kill switch: the artifact
404s whatever pass the reader holds.
While the gate is on, share responses are Cache-Control: private, no-store with Vary: Cookie,
instead of the usual private, max-age=60. A gated artifact must not be replayed from a cache after
the pass expires.
Rate limiting
The default is in-process and deliberately blunt: 5 attempts per 10 minutes per (artifact, reader
address) and 50 per hour per artifact, 429 with Retry-After. Addresses are used as bucket keys in
memory only — never stored, never logged, never sent anywhere — and the map is swept when it grows.
On more than one instance each instance counts separately, so the effective limit is
instances × 5. That is fine for a bored script and not a defence against a botnet. To do better,
pass a RateLimiter backed by KV or Redis:
gate: { enabled: true, leads, limiter: { check: (key, nowMs) => myBucket(key, nowMs) } }
Operating notes
- https only.
__Host-plusSecuremeans a real deployment must be https.http://localhostis treated as trustworthy by Chrome and Safari, so the demo works; other hosts will not accept the cookie. - Gate on means gate for everything shared. There is no per-artifact switch; a deployment that needs both runs two deployments.
- Analytics down does not block readers. The capture error is swallowed after the lead is stored.
- Store down does block readers, with the existing
503path — a pass is only minted after the lead is written, so no one gets the artifact in exchange for an address that was lost. - Expired or tampered passes are silent. The gate page is served with no warning; there is no "your session expired" message for a script to distinguish from a first visit.
What it does not do
- No mailing list, no sending, no unsubscribe links, no double opt-in.
- No per-artifact enablement, no A/B test of the gate, no modal over the artifact.
- No IP, user-agent or referrer storage. If you need attribution, put it in the share URL and read it in the page you build around it — not in the gate.