@civitai/app-sdk 0.98.0 → 0.98.1

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.
package/README.md CHANGED
@@ -541,10 +541,15 @@ this plugin is the only way the manifest reaches `@civitai/sdk`.
541
541
 
542
542
  ### Web storage in a block (`@civitai/app-sdk/safe-storage`)
543
543
 
544
- Block iframes are sandboxed **without `allow-same-origin`**, so the document has
545
- an *opaque origin*. There is no origin to key web storage against, and the
546
- platform doesn't hand back an empty store — merely **reading** the property
547
- throws:
544
+ A published block is framed at its own origin, `https://<blockId>.civit.ai`
545
+ (on its run page, at its version path `/v/<sha>/`), where web storage, IndexedDB and the rest
546
+ work normally, scoped to the app
547
+ ([Frame origin and browser storage](https://developer.civitai.com/apps/guide/concepts#frame-origin)).
548
+ Some frames are still sandboxed **without `allow-same-origin`**: an unverified block that
549
+ declares an `apps:storage:shared:*` scope, and the frame a moderator reviews a
550
+ block in. There the document has an *opaque origin* (`self.origin === 'null'`),
551
+ there is no origin to key web storage against, and the platform doesn't hand
552
+ back an empty store — merely **reading** the property throws:
548
553
 
549
554
  ```
550
555
  SecurityError: Failed to read the 'localStorage' property from 'Window':
@@ -583,7 +588,8 @@ round-trip probe shows they're unusable. Rules:
583
588
  revoked `Proxy` or a throwing getter sitting on `localStorage` is classified,
584
589
  not propagated.
585
590
  - The fallback is **session-scoped** — nothing survives a reload. That's the
586
- honest semantic at an opaque origin. Treat storage as a cache; use the
591
+ honest semantic at an opaque origin. Even at a real origin, treat storage as a
592
+ cache (browsers may evict it); use the
587
593
  document store (`app.storage.collection(name)` in `@civitai/sdk`) for anything
588
594
  durable.
589
595
 
@@ -612,9 +618,10 @@ if you want the standalone `Storage` work-alike.
612
618
  ### Nested documents
613
619
 
614
620
  🔴 **A nested `<iframe src="…">` pointing at your own bundled content cannot
615
- load, and no manifest change fixes it** — your block's origin is opaque and the
616
- static host stamps `frame-ancestors` + `X-Frame-Options` on every path it
617
- serves. The full derivation, the dated external browser matrix (an
621
+ load, and no manifest change fixes it** — the static host stamps
622
+ `frame-ancestors` (Civitai's own sites only) + `X-Frame-Options` on every path
623
+ it serves, so a frame whose ancestors include your block's origin, opaque or
624
+ real, is refused. The full derivation, the dated external browser matrix (an
618
625
  observation of the platform — nothing in this repo verifies it) and the known
619
626
  limits
620
627
  are in one place: the header of
@@ -625,7 +632,7 @@ Phaser) is a `<canvas>` plus a JS loader that normally mounts straight into the
625
632
  document you hand it, which avoids the whole problem class.
626
633
 
627
634
  When a separate document is genuinely required, fetch it and inline it as the
628
- iframe's `srcdoc` — that frame inherits your opaque origin and carries no
635
+ iframe's `srcdoc` — that frame (opaque when sandboxed, as below) carries no
629
636
  response headers of its own:
630
637
 
631
638
  ```ts
@@ -8,7 +8,8 @@
8
8
  * all. Build-time manifest validation lives at `@civitai/app-sdk/manifest`
9
9
  * (node-only); see the note on `BlockManifestError` below.
10
10
  */
11
- // FIRST import, on purpose. Blocks are framed at an opaque origin (sandbox
11
+ // FIRST import, on purpose. Some block frames (moderator review; an unverified block that
12
+ // declares an `apps:storage:shared:*` scope) are at an opaque origin (sandbox
12
13
  // without `allow-same-origin`), where touching `localStorage`/`sessionStorage`
13
14
  // THROWS — including from third-party dependencies nobody can guard from the
14
15
  // outside. Importing this repairs those globals before anything else in the
@@ -8,12 +8,12 @@
8
8
  * bundled content by URL. Neither is a bug, and neither has a manifest-side
9
9
  * workaround:
10
10
  *
11
- * 1. A block's own frame is sandboxed with the manifest's `iframe.sandbox`
12
- * tokens intersected by a trust-tier allowlist. An unverified block keeps
13
- * `allow-scripts allow-forms` and nothing else — `allow-same-origin` is
14
- * refused at `civitai app validate` time ("forbidden outside the internal
15
- * trust tier") and re-stripped host-side even if it reached the manifest.
16
- * So the block document's origin is OPAQUE: `window.origin === "null"`.
11
+ * 1. A block cannot declare `allow-same-origin` (refused at `civitai app
12
+ * validate` time, "forbidden outside the internal trust tier", and
13
+ * re-stripped host-side); the HOST decides it. A published block is now
14
+ * framed at its own origin, `https://<blockId>.civit.ai`; a moderator-
15
+ * review frame, and an unverified block that declares an
16
+ * `apps:storage:shared:*` scope, stay OPAQUE: `window.origin === "null"`.
17
17
  *
18
18
  * 2. Every path served from `https://<blockId>.civit.ai/` — `.html`, `.js`,
19
19
  * `.wasm`, archive files, all of it — carries
@@ -27,7 +27,10 @@
27
27
  * then URL-parses it, and the string `"null"` fails that parse, returning
28
28
  * Blocked before any source matching happens. So widening the allowlist cannot
29
29
  * fix this, and `X-Frame-Options: SAMEORIGIN` blocks it a second time on its
30
- * own.
30
+ * own. At a REAL origin the result is the same by derivation, NOT by the
31
+ * measurement below (which covers the opaque case only): the platform's
32
+ * `frame-ancestors` lists Civitai's own sites and not the block's origin, so the
33
+ * block as an ancestor fails it.
31
34
  *
32
35
  * 🔴 EXTERNAL PLATFORM MEASUREMENT — NOTHING IN THIS REPO VERIFIES THE MATRIX
33
36
  * BELOW. It was taken on 2026-10-03 against a local two-origin Chromium replica
@@ -56,11 +59,13 @@
56
59
  * WHAT THIS MODULE DOES
57
60
  * =====================
58
61
  * The one thing that works: fetch the nested document's HTML (the static host
59
- * sends `Access-Control-Allow-Origin: *`, so a null-origin `fetch` succeeds
60
- * where a frame load does not), rewrite its base URL to the absolute location
61
- * it was fetched from, and hand the string to an iframe's `srcdoc`. A `srcdoc`
62
- * frame inherits the parent's opaque origin and carries NO response headers of
63
- * its own, so neither policy applies to it.
62
+ * sends `Access-Control-Allow-Origin: *`, so even a null-origin `fetch`
63
+ * succeeds where a frame load does not; from a published block's real origin
64
+ * the fetch of its own document is same-origin), rewrite its base URL to the
65
+ * absolute location it was fetched from, and hand the string to an iframe's
66
+ * `srcdoc`. A `srcdoc` frame carries NO response headers of its own, so neither
67
+ * policy applies to it. Its origin is the parent's only if it is not sandboxed:
68
+ * with the `sandbox="allow-scripts"` this module's callers set, it is opaque.
64
69
  *
65
70
  * 🔴 PREFER A SINGLE-DOCUMENT DESIGN. An engine build (Defold, Unity, Phaser,
66
71
  * …) is a `<canvas>` plus a JS loader and normally mounts straight into the
@@ -152,7 +157,7 @@ export interface InjectBaseHrefResult {
152
157
  *
153
158
  * This is the whole mechanism, and the reason it is a separate function with
154
159
  * tests of its own: a `srcdoc` document's own base URL is `about:srcdoc`, which
155
- * inherits the embedder's — an opaque origin — so every `src="loader.js"` and
160
+ * inherits the embedder's (and is opaque in a sandboxed frame) — so every `src="loader.js"` and
156
161
  * `url(font.woff2)` in the fetched markup resolves to nothing. A wrong or
157
162
  * missing `<base>` breaks every relative load in the document **with no error
158
163
  * naming the base**, which is why it is pinned by its own test.
@@ -8,12 +8,12 @@
8
8
  * bundled content by URL. Neither is a bug, and neither has a manifest-side
9
9
  * workaround:
10
10
  *
11
- * 1. A block's own frame is sandboxed with the manifest's `iframe.sandbox`
12
- * tokens intersected by a trust-tier allowlist. An unverified block keeps
13
- * `allow-scripts allow-forms` and nothing else — `allow-same-origin` is
14
- * refused at `civitai app validate` time ("forbidden outside the internal
15
- * trust tier") and re-stripped host-side even if it reached the manifest.
16
- * So the block document's origin is OPAQUE: `window.origin === "null"`.
11
+ * 1. A block cannot declare `allow-same-origin` (refused at `civitai app
12
+ * validate` time, "forbidden outside the internal trust tier", and
13
+ * re-stripped host-side); the HOST decides it. A published block is now
14
+ * framed at its own origin, `https://<blockId>.civit.ai`; a moderator-
15
+ * review frame, and an unverified block that declares an
16
+ * `apps:storage:shared:*` scope, stay OPAQUE: `window.origin === "null"`.
17
17
  *
18
18
  * 2. Every path served from `https://<blockId>.civit.ai/` — `.html`, `.js`,
19
19
  * `.wasm`, archive files, all of it — carries
@@ -27,7 +27,10 @@
27
27
  * then URL-parses it, and the string `"null"` fails that parse, returning
28
28
  * Blocked before any source matching happens. So widening the allowlist cannot
29
29
  * fix this, and `X-Frame-Options: SAMEORIGIN` blocks it a second time on its
30
- * own.
30
+ * own. At a REAL origin the result is the same by derivation, NOT by the
31
+ * measurement below (which covers the opaque case only): the platform's
32
+ * `frame-ancestors` lists Civitai's own sites and not the block's origin, so the
33
+ * block as an ancestor fails it.
31
34
  *
32
35
  * 🔴 EXTERNAL PLATFORM MEASUREMENT — NOTHING IN THIS REPO VERIFIES THE MATRIX
33
36
  * BELOW. It was taken on 2026-10-03 against a local two-origin Chromium replica
@@ -56,11 +59,13 @@
56
59
  * WHAT THIS MODULE DOES
57
60
  * =====================
58
61
  * The one thing that works: fetch the nested document's HTML (the static host
59
- * sends `Access-Control-Allow-Origin: *`, so a null-origin `fetch` succeeds
60
- * where a frame load does not), rewrite its base URL to the absolute location
61
- * it was fetched from, and hand the string to an iframe's `srcdoc`. A `srcdoc`
62
- * frame inherits the parent's opaque origin and carries NO response headers of
63
- * its own, so neither policy applies to it.
62
+ * sends `Access-Control-Allow-Origin: *`, so even a null-origin `fetch`
63
+ * succeeds where a frame load does not; from a published block's real origin
64
+ * the fetch of its own document is same-origin), rewrite its base URL to the
65
+ * absolute location it was fetched from, and hand the string to an iframe's
66
+ * `srcdoc`. A `srcdoc` frame carries NO response headers of its own, so neither
67
+ * policy applies to it. Its origin is the parent's only if it is not sandboxed:
68
+ * with the `sandbox="allow-scripts"` this module's callers set, it is opaque.
64
69
  *
65
70
  * 🔴 PREFER A SINGLE-DOCUMENT DESIGN. An engine build (Defold, Unity, Phaser,
66
71
  * …) is a `<canvas>` plus a JS loader and normally mounts straight into the
@@ -125,7 +130,7 @@ export class NestedDocumentError extends Error {
125
130
  *
126
131
  * This is the whole mechanism, and the reason it is a separate function with
127
132
  * tests of its own: a `srcdoc` document's own base URL is `about:srcdoc`, which
128
- * inherits the embedder's — an opaque origin — so every `src="loader.js"` and
133
+ * inherits the embedder's (and is opaque in a sandboxed frame) — so every `src="loader.js"` and
129
134
  * `url(font.woff2)` in the fetched markup resolves to nothing. A wrong or
130
135
  * missing `<base>` breaks every relative load in the document **with no error
131
136
  * naming the base**, which is why it is pinned by its own test.
@@ -248,8 +253,9 @@ export async function fetchNestedDocument(options) {
248
253
  // meaning what it means.
249
254
  if (options.signal?.aborted)
250
255
  throw cause;
251
- throw new NestedDocumentError(`fetchNestedDocument: request to ${url} failed. A block runs at an opaque origin, so the ` +
252
- 'host must answer with Access-Control-Allow-Origin.', { code: 'network-error', url, cause });
256
+ throw new NestedDocumentError(`fetchNestedDocument: request to ${url} failed. A URL cross-origin to the block's frame ` +
257
+ '(every URL, in an opaque-origin frame) needs the host to answer with ' +
258
+ 'Access-Control-Allow-Origin.', { code: 'network-error', url, cause });
253
259
  }
254
260
  if (!response.ok) {
255
261
  throw new NestedDocumentError(`fetchNestedDocument: ${url} returned HTTP ${response.status}.`, { code: 'http-error', url, status: response.status });
@@ -7,11 +7,12 @@
7
7
  * `tests/guards/safe-storage-copy-parity.test.mjs`, so a fix here goes red
8
8
  * until it is applied there too.
9
9
  *
10
- * Civitai Apps run in an iframe sandboxed as `allow-scripts allow-forms`,
11
- * deliberately WITHOUT `allow-same-origin`. The document therefore has an
12
- * **opaque origin**, and there is no origin to key web storage against, so the
13
- * platform does not merely return an empty store — merely *reading* the
14
- * property throws:
10
+ * A published Civitai App runs at its own origin, where web storage works.
11
+ * Some frames (moderator review; an unverified block that declares an
12
+ * `apps:storage:shared:*` scope) are still sandboxed WITHOUT
13
+ * `allow-same-origin`. Such a document has an **opaque origin**, and there is
14
+ * no origin to key web storage against, so the platform does not merely return
15
+ * an empty store — merely *reading* the property throws:
15
16
  *
16
17
  * SecurityError: Failed to read the 'localStorage' property from 'Window':
17
18
  * The document is sandboxed and lacks the 'allow-same-origin' flag.
@@ -7,11 +7,12 @@
7
7
  * `tests/guards/safe-storage-copy-parity.test.mjs`, so a fix here goes red
8
8
  * until it is applied there too.
9
9
  *
10
- * Civitai Apps run in an iframe sandboxed as `allow-scripts allow-forms`,
11
- * deliberately WITHOUT `allow-same-origin`. The document therefore has an
12
- * **opaque origin**, and there is no origin to key web storage against, so the
13
- * platform does not merely return an empty store — merely *reading* the
14
- * property throws:
10
+ * A published Civitai App runs at its own origin, where web storage works.
11
+ * Some frames (moderator review; an unverified block that declares an
12
+ * `apps:storage:shared:*` scope) are still sandboxed WITHOUT
13
+ * `allow-same-origin`. Such a document has an **opaque origin**, and there is
14
+ * no origin to key web storage against, so the platform does not merely return
15
+ * an empty store — merely *reading* the property throws:
15
16
  *
16
17
  * SecurityError: Failed to read the 'localStorage' property from 'Window':
17
18
  * The document is sandboxed and lacks the 'allow-same-origin' flag.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@civitai/app-sdk",
3
- "version": "0.98.0",
3
+ "version": "0.98.1",
4
4
  "description": "OAuth + PKCE, encrypted-cookie sessions, scopes, and orchestrator helpers for building third-party Civitai apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",