@tokenoftrust/storefront-runner 6.14.1 → 6.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,8 @@ export interface PreviewAnnotationBootstrapConfig {
35
35
  capturePolicyVersion: string;
36
36
  nonce?: string;
37
37
  receiptExpiresAt: string;
38
+ /** May a session record capture this document? Mirrors the receipt's claim. */
39
+ recordable: boolean;
38
40
  }
39
41
 
40
42
  export interface ReviewerCookieJar {
@@ -46,6 +48,8 @@ export interface AnnotationBootstrapInput {
46
48
  secret: string | null;
47
49
  nowSeconds: number;
48
50
  document: RenderedDocument;
51
+ /** The server's recording verdict for this route (`protectedSurfaces.ts`). */
52
+ recordable: boolean;
49
53
  /** Expiry of the preview capability this render rode in on, when it has one. */
50
54
  capabilityExpiresAt?: number | null;
51
55
  cookies: ReviewerCookieJar;
@@ -94,6 +98,7 @@ export async function buildAnnotationBootstrap(
94
98
  const receipt = await signRenderReceipt(input.secret, {
95
99
  ...input.document,
96
100
  reviewer: await reviewerPseudonym(input.secret, input.document.tenant, key),
101
+ recordable: input.recordable,
97
102
  originalIssuedAt: input.nowSeconds,
98
103
  issuedAt: input.nowSeconds,
99
104
  expiresAt,
@@ -105,6 +110,7 @@ export async function buildAnnotationBootstrap(
105
110
  capturePolicyVersion: PREVIEW_CAPTURE_POLICY_VERSION,
106
111
  nonce: input.nonce,
107
112
  receiptExpiresAt: new Date(expiresAt * 1000).toISOString(),
113
+ recordable: input.recordable,
108
114
  };
109
115
  }
110
116
 
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Surfaces a preview record never captures, and the route roots whose deeper segments never
3
+ * survive into a stored page reference. One list, imported by `safePageRef` (server) and by the
4
+ * session recorder (browser), so the two can never disagree.
5
+ *
6
+ * The server decides: a route is recordable only when its first segment is not a platform root
7
+ * below and it falls under no tenant-declared or member-area prefix. The receipt and bootstrap carry
8
+ * that verdict as `recordable`; the browser probe (`protectedProbe.ts`) can only narrow it.
9
+ *
10
+ * Pure and dependency-free: it ships in the Worker and in the browser client.
11
+ */
12
+
13
+ /**
14
+ * Route roots that can name a customer, an order, a credential or a payment, or that are platform
15
+ * surfaces: checkout, cart, payment, authentication, account and member areas, admin, `/cockpit`,
16
+ * `/api`, and age and identity verification.
17
+ */
18
+ export const PROTECTED_ROUTE_ROOTS: ReadonlySet<string> = new Set([
19
+ "account", "accounts", "admin", "api", "auth", "cart", "checkout", "cockpit", "customer",
20
+ "customers", "invite", "invites", "login", "logout", "member", "members", "my", "order",
21
+ "orders", "password", "pay", "payment", "profile", "register", "reset", "signup",
22
+ "subscription", "subscriptions", "unsubscribe", "verify",
23
+ ]);
24
+
25
+ /**
26
+ * Origins whose iframes collect payment details. A page embedding one is never recorded. A payment
27
+ * provider is added here, never by tenant config.
28
+ */
29
+ export const PAYMENT_FRAME_ORIGINS: ReadonlySet<string> = new Set([
30
+ "https://js.stripe.com",
31
+ "https://checkout.stripe.com",
32
+ "https://hooks.stripe.com",
33
+ "https://www.paypal.com",
34
+ "https://www.sandbox.paypal.com",
35
+ "https://assets.braintreegateway.com",
36
+ "https://web.squarecdn.com",
37
+ "https://sandbox.web.squarecdn.com",
38
+ "https://accept.authorize.net",
39
+ "https://test.authorize.net",
40
+ "https://checkoutshopper-live.adyen.com",
41
+ "https://checkoutshopper-test.adyen.com",
42
+ "https://pay.google.com",
43
+ "https://js.klarna.com",
44
+ "https://foxycart.tokenoftrust.com",
45
+ ]);
46
+
47
+ /** The declared tenant configuration this module reads: additive prefixes only. */
48
+ export interface ProtectedSurfaceConfig {
49
+ /** Tenant-declared prefixes that are never recorded (`recording.protectedPrefixes`). */
50
+ recording?: { protectedPrefixes?: readonly string[] } | null;
51
+ /** ADR 0013 gated member-area prefixes (`serving.memberPrefixes`). */
52
+ serving?: { memberPrefixes?: readonly string[] } | null;
53
+ }
54
+
55
+ const PREFIX_PATTERN = /^\/[A-Za-z0-9._~-]+(?:\/[A-Za-z0-9._~-]+)*$/;
56
+ const MAX_PREFIXES = 64;
57
+
58
+ /** One prefix in canonical form (leading slash, no trailing slash, lowercase), or null. */
59
+ export function normalizeProtectedPrefix(value: unknown): string | null {
60
+ if (typeof value !== "string" || value.length > 256) return null;
61
+ const trimmed = value.trim().replace(/\/+$/, "");
62
+ if (!PREFIX_PATTERN.test(trimmed)) return null;
63
+ if (trimmed.split("/").some((segment) => segment === "." || segment === "..")) return null;
64
+ return trimmed.toLowerCase();
65
+ }
66
+
67
+ /**
68
+ * The tenant's protected prefixes: its declared `recording.protectedPrefixes` merged with its ADR
69
+ * 0013 member-area prefixes. Additive only: a tenant can protect more, never unprotect a platform
70
+ * root. A malformed entry is dropped (it could only ever have narrowed, never widened, recording).
71
+ */
72
+ export function tenantProtectedPrefixes(config: ProtectedSurfaceConfig | null | undefined): string[] {
73
+ const declared = [
74
+ ...(config?.recording?.protectedPrefixes ?? []),
75
+ ...(config?.serving?.memberPrefixes ?? []),
76
+ ];
77
+ const out = new Set<string>();
78
+ for (const entry of declared) {
79
+ const prefix = normalizeProtectedPrefix(entry);
80
+ if (prefix) out.add(prefix);
81
+ if (out.size >= MAX_PREFIXES) break;
82
+ }
83
+ return [...out].sort();
84
+ }
85
+
86
+ function decodedSegments(path: string): string[] | null {
87
+ const segments: string[] = [];
88
+ for (const raw of path.split("/")) {
89
+ if (raw.length === 0) continue;
90
+ try {
91
+ segments.push(decodeURIComponent(raw).toLowerCase());
92
+ } catch (error) {
93
+ if (error instanceof URIError) return null;
94
+ throw error;
95
+ }
96
+ }
97
+ return segments;
98
+ }
99
+
100
+ /** Is this route root a platform-protected surface? */
101
+ export function isProtectedRoot(segment: string): boolean {
102
+ return PROTECTED_ROUTE_ROOTS.has(segment.toLowerCase());
103
+ }
104
+
105
+ /**
106
+ * May a record capture this tenant-relative route? False for a platform root, a route under any
107
+ * declared prefix, or a path that cannot be decoded (fails closed).
108
+ */
109
+ export function isRecordableRoute(renderPath: string, protectedPrefixes: readonly string[]): boolean {
110
+ const path = renderPath.split(/[?#]/, 1)[0] ?? "";
111
+ const segments = decodedSegments(path);
112
+ if (!segments) return false;
113
+ const first = segments[0];
114
+ if (first !== undefined && isProtectedRoot(first)) return false;
115
+ const canonical = `/${segments.join("/")}`;
116
+ for (const entry of protectedPrefixes) {
117
+ const prefix = normalizeProtectedPrefix(entry);
118
+ if (!prefix) continue;
119
+ if (canonical === prefix || canonical.startsWith(`${prefix}/`)) return false;
120
+ }
121
+ return true;
122
+ }
@@ -11,12 +11,14 @@
11
11
  * - the tenant-scoped reviewer pseudonym (`rv1_…`), derived server-side from that
12
12
  * key, so one browser has unrelated pseudonyms on different stores;
13
13
  * - the rendered-context receipt: tenant, preview kind, rendered revision, platform
14
- * build, safe page reference, the reviewer pseudonym, and an expiry. It is
15
- * minted at render from server state only and verified again on submission.
14
+ * build, safe page reference, the reviewer pseudonym, whether a session record may
15
+ * capture the page, and an expiry. It is minted at render from server state only
16
+ * and verified again on submission.
16
17
  *
17
18
  * The receipt is evidence, never authority: every submission and renewal re-checks
18
19
  * current preview access. Renderer-safe: WebCrypto only, no control-plane imports.
19
20
  */
21
+ import { isProtectedRoot } from "./protectedSurfaces";
20
22
 
21
23
  export const PREVIEW_REVIEWER_COOKIE = "tot_pf_reviewer";
22
24
  export const RENDER_RECEIPT_PREFIX = "pfr1";
@@ -57,6 +59,11 @@ export interface RenderedDocument {
57
59
 
58
60
  export interface RenderReceiptClaims extends RenderedDocument {
59
61
  reviewer: string;
62
+ /**
63
+ * May a session record capture this document? Decided at render from the route and the
64
+ * tenant's declared protected prefixes; an absent claim reads as false.
65
+ */
66
+ recordable: boolean;
60
67
  /** Issue time of the render that first produced this document identity. */
61
68
  originalIssuedAt: number;
62
69
  issuedAt: number;
@@ -153,6 +160,7 @@ export async function signRenderReceipt(secret: string, claims: RenderReceiptCla
153
160
  p: claims.platformSha,
154
161
  g: claims.pageRef,
155
162
  rv: claims.reviewer,
163
+ rc: claims.recordable,
156
164
  oiat: claims.originalIssuedAt,
157
165
  iat: claims.issuedAt,
158
166
  exp: claims.expiresAt,
@@ -197,6 +205,7 @@ export async function verifyRenderReceipt(
197
205
  platformSha: String(raw.p ?? ""),
198
206
  pageRef: String(raw.g ?? ""),
199
207
  reviewer: raw.rv,
208
+ recordable: raw.rc === true,
200
209
  originalIssuedAt: raw.oiat,
201
210
  issuedAt: raw.iat,
202
211
  expiresAt: raw.exp,
@@ -215,22 +224,13 @@ export function receiptExpiry(nowSeconds: number, capabilityExpiresAt?: number |
215
224
 
216
225
  // ---- safe page reference ---------------------------------------------------
217
226
 
218
- /**
219
- * Routes whose path segments can name a customer, an order or a credential. Only
220
- * their first segment survives; every segment under them becomes a placeholder.
221
- */
222
- const PRIVATE_ROOTS = new Set([
223
- "account", "accounts", "admin", "api", "auth", "cart", "checkout", "cockpit", "customer",
224
- "customers", "invite", "invites", "login", "logout", "member", "members", "my", "order",
225
- "orders", "password", "profile", "register", "reset", "signup", "subscription",
226
- "subscriptions", "unsubscribe", "verify",
227
- ]);
228
227
  const SAFE_SEGMENT = /^[a-z](?:[a-z-]{0,62}[a-z])?$/;
229
228
  const MAX_PAGE_SEGMENTS = 12;
230
229
 
231
230
  /**
232
231
  * A page reference safe to store: the tenant-relative route with every segment that
233
- * could carry a dynamic or private value replaced by `[segment]`. Query and fragment
232
+ * could carry a dynamic or private value replaced by `[segment]`. Under a protected route root
233
+ * (`protectedSurfaces.ts`) only the root survives. Query and fragment
234
234
  * never survive. A segment is kept only when it is a short lowercase word or
235
235
  * hyphenated words with no digits, no encoding and no dots — so ids, slugs with
236
236
  * numbers, emails, tokens and encoded values are never presumed public.
@@ -248,7 +248,7 @@ export function safePageRef(renderPath: string): string {
248
248
  }
249
249
  const keep = !privateRoot && SAFE_SEGMENT.test(segment);
250
250
  out.push(keep ? segment : "[segment]");
251
- if (i === 0 && keep && PRIVATE_ROOTS.has(segment)) privateRoot = true;
251
+ if (i === 0 && keep && isProtectedRoot(segment)) privateRoot = true;
252
252
  }
253
253
  const ref = `/${out.join("/")}`;
254
254
  return isSafePageRef(ref) ? ref : "page:unresolved";
@@ -11,9 +11,14 @@
11
11
  * live/public render, or a document whose revision or platform build cannot be named. A host
12
12
  * name or `NODE_ENV` alone never qualifies a render. The bootstrap is evidence for a later
13
13
  * submission, never authority: the bridge re-checks current preview access on every call.
14
+ *
15
+ * Every decorated document also carries the server's recording verdict: a route under a platform
16
+ * protected root or a tenant-declared or member-area prefix (`protectedSurfaces.ts`) is minted
17
+ * `recordable:false`, and the client then mounts no recorder for it.
14
18
  */
15
19
  import { HTML_CACHE_POLICY_CAPTURE_PROBE, verifyPreviewToken } from "@tot/public-runtime";
16
20
  import { injectPreviewAnnotations, type ReviewerCookieJar } from "./inject";
21
+ import { isRecordableRoute } from "./protectedSurfaces";
17
22
  import {
18
23
  PLATFORM_SHA_PATTERN,
19
24
  PREVIEW_REVIEWER_COOKIE,
@@ -67,6 +72,8 @@ export interface PreviewAnnotationDecoration {
67
72
  candidatePin: { versionId: string; integrationStage: "candidate" | "staged" } | null;
68
73
  tenantId: string;
69
74
  renderPath: string;
75
+ /** The tenant's declared protected prefixes (`tenantProtectedPrefixes(tenant)`). */
76
+ protectedPrefixes: readonly string[];
70
77
  secret: string | null;
71
78
  nowSeconds: number;
72
79
  cookies: ReviewerCookieJar;
@@ -123,6 +130,7 @@ export async function decoratePreviewAnnotations(
123
130
  platformSha,
124
131
  pageRef: safePageRef(input.renderPath),
125
132
  },
133
+ recordable: isRecordableRoute(input.renderPath, input.protectedPrefixes),
126
134
  capabilityExpiresAt,
127
135
  cookies: input.cookies,
128
136
  pageBase: input.pageBase,
@@ -34,6 +34,7 @@ import {
34
34
  decoratePreviewAnnotations,
35
35
  isPublicationCapture,
36
36
  } from "@/lib/publication/shared/previewAnnotations/renderDecorator";
37
+ import { tenantProtectedPrefixes } from "@/lib/publication/shared/previewAnnotations/protectedSurfaces";
37
38
  import {
38
39
  resolveCustomizationEnv,
39
40
  buildCsp,
@@ -865,6 +866,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
865
866
  candidatePin: candidatePin ?? null,
866
867
  tenantId: tenant.tenant_id,
867
868
  renderPath,
869
+ protectedPrefixes: tenantProtectedPrefixes(tenant),
868
870
  secret: previewSecret,
869
871
  nowSeconds,
870
872
  cookies: context.cookies,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "6.14.1",
3
+ "version": "6.14.2",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",
@@ -715,6 +715,20 @@ export interface TenantConfig {
715
715
  * while a fresh one is fetched. All in seconds. Absent ⇒ {@link DEFAULT_HTML_CACHE_POLICY}.
716
716
  */
717
717
  htmlCachePolicy?: HtmlCachePolicy;
718
+ /**
719
+ * Gated member-area route prefixes (ADR 0013: member areas are path-scoped), e.g.
720
+ * `["/club"]`. Each is routed to the Worker origin with caching off, and a preview
721
+ * session record never captures a page under one.
722
+ */
723
+ memberPrefixes?: string[];
724
+ };
725
+ /**
726
+ * Preview session recording (feedback record contract §6). `protectedPrefixes` names
727
+ * tenant routes a record never captures, in addition to the platform's protected roots
728
+ * and `serving.memberPrefixes`. Additive only: it cannot unprotect a platform root.
729
+ */
730
+ recording?: {
731
+ protectedPrefixes?: string[];
718
732
  };
719
733
  /**
720
734
  * Catalog serving (ADR 0033). The store's own `content/catalog/` files are the