@tokenoftrust/storefront-runner 6.12.9 → 6.12.11

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.
@@ -83,7 +83,7 @@ export async function serveControlPlane(input: ControlPlaneInput): Promise<Respo
83
83
  nowSeconds: Math.floor(Date.now() / 1000),
84
84
  });
85
85
  if (preview.context.status === "refused") {
86
- return previewContextRefusalResponse(preview.context.httpStatus);
86
+ return previewContextRefusalResponse(preview.context);
87
87
  }
88
88
  // A pinned route rewrite arrives here without the outer preview route's
89
89
  // session. Verify its tenant-bound grant before the host login gate runs.
@@ -3,7 +3,7 @@
3
3
  * `tot_preview` cookies), shared by every middleware layer that consults it: the
4
4
  * front door's static passthrough and mirror stage, the control-plane gate, and the
5
5
  * render chain. A presented context is verified by `requireValidPreviewToken` and
6
- * never degrades to "absent"; the control plane and the render chain refuse it with
6
+ * never degrades to "absent" (except a cookie-only expired token, below); the control plane and the render chain refuse it with
7
7
  * `previewContextRefusalResponse` before any publication, page-cache, rewrite-target
8
8
  * or source resolution.
9
9
  *
@@ -61,6 +61,13 @@ export async function resolveRequestPreviewContext(
61
61
  secret: input.secret,
62
62
  nowSeconds: input.nowSeconds,
63
63
  });
64
+ // A `tot_preview` cookie alone that has merely expired grants nothing and proves no
65
+ // tampering: it reads as absent, so the viewer falls back to session or public
66
+ // access instead of a dead-end 403. Any presented `__preview` query value, and every
67
+ // other refusal (bad signature, wrong tenant, ambiguity), still refuses.
68
+ if (context.status === "refused" && context.reason === "expired" && queryValues.length === 0) {
69
+ return { context: { status: "absent" }, presented, cookieValue: null };
70
+ }
64
71
  if (
65
72
  context.status === "refused" &&
66
73
  (isPreviewDispatcherPath(input.url.pathname) || isAuthPath(input.renderPath))
@@ -220,7 +220,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
220
220
  nowSeconds,
221
221
  });
222
222
  if (preview.context.status === "refused") {
223
- return previewContextRefusalResponse(preview.context.httpStatus);
223
+ return previewContextRefusalResponse(preview.context);
224
224
  }
225
225
  const verifiedPreview = preview.context.status === "valid" ? preview.context : null;
226
226
  const queryToken = verifiedPreview?.source === "query" ? verifiedPreview.token : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "6.12.9",
3
+ "version": "6.12.11",
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",
@@ -328,14 +328,22 @@ export async function requireValidPreviewToken(input: PreviewContextInput): Prom
328
328
  }
329
329
 
330
330
  /**
331
- * The one refusal for a presented preview context: fixed, no-store JSON carrying
332
- * {@link PREVIEW_CONTEXT_REFUSED} and nothing derived from the request.
331
+ * The one refusal for a presented preview context: no-store JSON carrying
332
+ * {@link PREVIEW_CONTEXT_REFUSED} and the closed-set `reason` that refused it. Nothing
333
+ * else is derived from the request.
333
334
  */
334
- export function previewContextRefusalResponse(status: 401 | 403 | 503): Response {
335
+ export function previewContextRefusalResponse(
336
+ refusal: { httpStatus: 401 | 403 | 503; reason: PreviewContextRefusalReason },
337
+ ): Response {
335
338
  return new Response(
336
- JSON.stringify({ ok: false, error: PREVIEW_CONTEXT_REFUSED, code: PREVIEW_CONTEXT_REFUSED }),
339
+ JSON.stringify({
340
+ ok: false,
341
+ error: PREVIEW_CONTEXT_REFUSED,
342
+ code: PREVIEW_CONTEXT_REFUSED,
343
+ reason: refusal.reason,
344
+ }),
337
345
  {
338
- status,
346
+ status: refusal.httpStatus,
339
347
  headers: {
340
348
  "content-type": "application/json; charset=utf-8",
341
349
  "cache-control": "no-store",