@botiverse/porthole 0.14.16 → 0.14.17
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/CHANGELOG.md +19 -0
- package/dist/isolation/served.d.ts +8 -0
- package/dist/isolation/served.js +16 -0
- package/dist/server/host.d.ts +14 -1
- package/dist/server/host.js +8 -3
- package/dist/server/nested.d.ts +5 -4
- package/dist/server/nested.js +8 -6
- package/dist/server/pages.d.ts +16 -2
- package/dist/server/pages.js +51 -16
- package/dist/server/server.js +26 -2
- package/dist/server/types.d.ts +8 -0
- package/dist/shell/frame.d.ts +6 -0
- package/dist/shell/frame.js +16 -3
- package/docs/ADOPTING.md +12 -3
- package/docs/DECISIONS.md +112 -0
- package/docs/THREAT_MODEL.md +18 -4
- package/package.json +1 -1
- package/src/isolation/served.ts +21 -0
- package/src/server/host.ts +22 -4
- package/src/server/nested.ts +13 -5
- package/src/server/pages.ts +72 -18
- package/src/server/server.ts +32 -1
- package/src/server/types.ts +8 -0
- package/src/shell/frame.ts +22 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,25 @@
|
|
|
4
4
|
section); the reasons for every change are in [docs/DECISIONS.md](docs/DECISIONS.md), by the
|
|
5
5
|
P-numbers below.
|
|
6
6
|
|
|
7
|
+
## 0.14.17
|
|
8
|
+
|
|
9
|
+
- **An app framed by another (P141): `framedBy`.** `createContentHost({ framedBy })` and
|
|
10
|
+
`createServer({ framedBy })` name the origins of an outer page that frames your app (Raft's Deck).
|
|
11
|
+
`frame-ancestors` is checked against every ancestor, so until now each of your frames was blank
|
|
12
|
+
inside it. Each may now be an ancestor of every frame Porthole serves (content, nested pages,
|
|
13
|
+
doors, status, entry and tab-only pages, the authorize route's pages), after the host origins,
|
|
14
|
+
and is never a host: no frame hears or tells it, it is in no page's `data-porthole-hosts` or
|
|
15
|
+
shell's plan, and redirect entry and the handoff stay `appOrigins`' alone. Exact https origins
|
|
16
|
+
(`http://` on loopback); a wildcard, a path, a desktop scheme, an app origin or the content
|
|
17
|
+
domain's site throws. `statusPage`, `doorResponse`, `doorStatusResponse` and
|
|
18
|
+
`nestedShellResponse` take `framedBy` for a content Worker of your own. Without it every response
|
|
19
|
+
is as before.
|
|
20
|
+
- **Security (P141):** a loosening, bounded: the outer origins only in `frame-ancestors`, and
|
|
21
|
+
checked. Where they are set, a page or a nested page's shell says its `*` fallback (a desktop
|
|
22
|
+
scheme among the host origins) only to a parent the engine names as a host origin, so an outer
|
|
23
|
+
page that frames content directly is told nothing by Porthole and heard by nothing; it can hear
|
|
24
|
+
what the content itself says to its parent.
|
|
25
|
+
|
|
7
26
|
## 0.14.16
|
|
8
27
|
|
|
9
28
|
- **On a tab the shell asks no host (P139).** A page opened on a tab of its own no longer asks
|
|
@@ -25,6 +25,14 @@ export declare function isExactOrigin(origin: unknown): origin is string;
|
|
|
25
25
|
export declare function isHostOrigin(origin: unknown): origin is string;
|
|
26
26
|
/** Why `origin` can't be a host origin, in words a host's developer can act on; null if it can. */
|
|
27
27
|
export declare function hostOriginProblem(origin: unknown): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Why `origin` can't be one of a host's `framedBy` (P141): an outer page that may be an
|
|
30
|
+
* ancestor of every frame the host shows, above the host's own page, and never a host origin. An
|
|
31
|
+
* exact web origin, `https://host[:port]` (lowercase, no path, no wildcard), or `http://` on
|
|
32
|
+
* loopback alone (`localhost`, `*.localhost`, `127.0.0.1`, `[::1]`) for development: never a
|
|
33
|
+
* desktop scheme, `"null"`, a CSP keyword or a list. Null if it can be.
|
|
34
|
+
*/
|
|
35
|
+
export declare function framedByProblem(origin: unknown): string | null;
|
|
28
36
|
/**
|
|
29
37
|
* Whether two hosts may be the same site. Without the public-suffix list this errs one way only:
|
|
30
38
|
* it says "same site" whenever the hosts are equal or share their last two labels, so a pair it
|
package/dist/isolation/served.js
CHANGED
|
@@ -58,6 +58,22 @@ export function hostOriginProblem(origin) {
|
|
|
58
58
|
}
|
|
59
59
|
return `${JSON.stringify(origin)} is not an exact origin (scheme://host[:port], lowercase, no path)`;
|
|
60
60
|
}
|
|
61
|
+
const LOOPBACK_HOST = (host) => host === "localhost" || host.endsWith(".localhost") || host === "127.0.0.1" || host === "[::1]";
|
|
62
|
+
/**
|
|
63
|
+
* Why `origin` can't be one of a host's `framedBy` (P141): an outer page that may be an
|
|
64
|
+
* ancestor of every frame the host shows, above the host's own page, and never a host origin. An
|
|
65
|
+
* exact web origin, `https://host[:port]` (lowercase, no path, no wildcard), or `http://` on
|
|
66
|
+
* loopback alone (`localhost`, `*.localhost`, `127.0.0.1`, `[::1]`) for development: never a
|
|
67
|
+
* desktop scheme, `"null"`, a CSP keyword or a list. Null if it can be.
|
|
68
|
+
*/
|
|
69
|
+
export function framedByProblem(origin) {
|
|
70
|
+
const parsed = typeof origin === "string" && isHostOrigin(origin) ? parseOrigin(origin) : null;
|
|
71
|
+
if (parsed === null ||
|
|
72
|
+
!(parsed.scheme === "https" || (parsed.scheme === "http" && LOOPBACK_HOST(parsed.host)))) {
|
|
73
|
+
return `${JSON.stringify(origin)} is not an exact https origin (https://host[:port], lowercase, no path; http only on loopback)`;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
61
77
|
/**
|
|
62
78
|
* Whether two hosts may be the same site. Without the public-suffix list this errs one way only:
|
|
63
79
|
* it says "same site" whenever the hosts are equal or share their last two labels, so a pair it
|
package/dist/server/host.d.ts
CHANGED
|
@@ -72,8 +72,21 @@ type Awaitable<T> = T | Promise<T>;
|
|
|
72
72
|
export interface ContentHostOptions<V> {
|
|
73
73
|
/** `content.example.com`, `content.localhost:8790`; empty: content off. Or parsed settings. */
|
|
74
74
|
readonly domain: string | null | undefined | ContentDomainInfo;
|
|
75
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* The app's own origins: they frame content (`frame-ancestors`), are the only origins its frames
|
|
77
|
+
* hear and tell, and are checked for clashes.
|
|
78
|
+
*/
|
|
76
79
|
readonly appOrigins: readonly string[];
|
|
80
|
+
/**
|
|
81
|
+
* Origins of an outer page that frame the app itself (P141): each may be an ancestor of every frame
|
|
82
|
+
* the app shows, above an app origin's page, so it is in every `frame-ancestors` Porthole sends
|
|
83
|
+
* (content, nested pages, doors, status and entry pages, the authorize route's pages) after
|
|
84
|
+
* `appOrigins`, and nowhere else. Never an origin a frame hears or tells, never an app origin for
|
|
85
|
+
* redirect entry or the handoff; the app's own page must still be the frame's parent. Exact https
|
|
86
|
+
* origins (`http://` on loopback), none an app origin, none the content domain's site. The app's
|
|
87
|
+
* own `frame-ancestors` (its page's, which Porthole doesn't send) is the app's to set.
|
|
88
|
+
*/
|
|
89
|
+
readonly framedBy?: readonly string[];
|
|
77
90
|
/** At least 32 random bytes (or a string of at least 32 bytes). */
|
|
78
91
|
readonly secret: Uint8Array | string;
|
|
79
92
|
readonly tickets?: TicketStore;
|
package/dist/server/host.js
CHANGED
|
@@ -3,7 +3,7 @@ import { base64url, fromBase64url, fromUtf8, hmacSha256, timingSafeEqual, utf8 }
|
|
|
3
3
|
import { ContentDomainError, contentDomain, serverDomain, } from "./domain.js";
|
|
4
4
|
import { reservedLabels } from "./naming.js";
|
|
5
5
|
import { peerAddress } from "./peer.js";
|
|
6
|
-
import { appStatusPage, tabOnlyPage } from "./pages.js";
|
|
6
|
+
import { ancestorsOf, appStatusPage, tabOnlyPage } from "./pages.js";
|
|
7
7
|
import { createServer } from "./server.js";
|
|
8
8
|
/**
|
|
9
9
|
* The host kit (P066): everything around `/server` that every host wrote, so an app writes only
|
|
@@ -252,6 +252,8 @@ export function createContentHost(options) {
|
|
|
252
252
|
let server = null;
|
|
253
253
|
let view = { state: "off" };
|
|
254
254
|
let configs = {};
|
|
255
|
+
// Who may frame the authorize route's pages: the app origins, and the outer pages' once checked.
|
|
256
|
+
let appAncestors = options.appOrigins.join(" ");
|
|
255
257
|
try {
|
|
256
258
|
domain =
|
|
257
259
|
options.domain !== null && typeof options.domain === "object"
|
|
@@ -285,6 +287,7 @@ export function createContentHost(options) {
|
|
|
285
287
|
}),
|
|
286
288
|
secret,
|
|
287
289
|
hostOrigins: options.appOrigins,
|
|
290
|
+
...(options.framedBy === undefined ? {} : { framedBy: options.framedBy }),
|
|
288
291
|
configs,
|
|
289
292
|
...(options.source === undefined ? {} : { artifacts: { get: options.source } }),
|
|
290
293
|
...(options.assets === undefined
|
|
@@ -320,6 +323,8 @@ export function createContentHost(options) {
|
|
|
320
323
|
},
|
|
321
324
|
}),
|
|
322
325
|
});
|
|
326
|
+
// createServer checked them (P141): only then in a header of the app's.
|
|
327
|
+
appAncestors = ancestorsOf(options.appOrigins, options.framedBy);
|
|
323
328
|
view = gate === undefined ? { state: "healthy" } : { state: "checking" };
|
|
324
329
|
}
|
|
325
330
|
}
|
|
@@ -839,7 +844,7 @@ export function createContentHost(options) {
|
|
|
839
844
|
return server === null || !served() ? null : server.urlOf(scope, path);
|
|
840
845
|
},
|
|
841
846
|
authorize(viewerOf) {
|
|
842
|
-
const appPage = (status, title, detail, reason, method, link) => appStatusPage(status, title, detail,
|
|
847
|
+
const appPage = (status, title, detail, reason, method, link) => appStatusPage(status, title, detail, appAncestors, reason, options.appOrigins, link, method);
|
|
843
848
|
return async (request) => {
|
|
844
849
|
const method = request.method.toUpperCase();
|
|
845
850
|
if (method !== "GET" && method !== "HEAD") {
|
|
@@ -857,7 +862,7 @@ export function createContentHost(options) {
|
|
|
857
862
|
// sign-in or refusal there, and says nothing to the page that frames it.
|
|
858
863
|
const dest = request.headers.get("sec-fetch-dest");
|
|
859
864
|
if (dest === "iframe" || dest === "frame") {
|
|
860
|
-
return tabOnlyPage(
|
|
865
|
+
return tabOnlyPage(appAncestors, method);
|
|
861
866
|
}
|
|
862
867
|
const clean = `${domain.originOf(state.label)}${state.path}`;
|
|
863
868
|
if (state.expired) {
|
package/dist/server/nested.d.ts
CHANGED
|
@@ -28,10 +28,10 @@ export declare const NESTED_FILES_PREFIX = "/__porthole/f/";
|
|
|
28
28
|
/**
|
|
29
29
|
* The shell's CSP (a header): its own script alone runs (by its hash), it frames and fetches
|
|
30
30
|
* nothing but its origin's sealed files (the page, the renewal), and only the host origins frame
|
|
31
|
-
* it. Nothing of the page's runs here: the page is a
|
|
32
|
-
* this (a framed URL's document never does).
|
|
31
|
+
* it (with, above them, a host's `framedBy`, P141). Nothing of the page's runs here: the page is a
|
|
32
|
+
* document of its own, which inherits none of this (a framed URL's document never does).
|
|
33
33
|
*/
|
|
34
|
-
export declare function nestedShellCsp(script: string, origin: string, hostOrigins: readonly string[]): string;
|
|
34
|
+
export declare function nestedShellCsp(script: string, origin: string, hostOrigins: readonly string[], framedBy?: readonly string[]): string;
|
|
35
35
|
/**
|
|
36
36
|
* The answer at the address the host frames, for a nested page (P111): Porthole's shell, never
|
|
37
37
|
* stored (it carries the page's sealed address), its page at `options.page`.
|
|
@@ -42,7 +42,8 @@ export declare function nestedShellResponse(compiled: CompiledConfig, options: F
|
|
|
42
42
|
}): Response;
|
|
43
43
|
/**
|
|
44
44
|
* Who may frame a nested page and its files' answers: its shell (the shell's own origin, P114) and,
|
|
45
|
-
* above it, the host origins (`frame-ancestors` names every ancestor)
|
|
45
|
+
* above it, the host origins and a host's `framedBy` (`frame-ancestors` names every ancestor; P141):
|
|
46
|
+
* `frameAncestors` is the server's whole list.
|
|
46
47
|
*/
|
|
47
48
|
export declare const nestedAncestors: (origin: string, frameAncestors: string) => string;
|
|
48
49
|
/**
|
package/dist/server/nested.js
CHANGED
|
@@ -2,6 +2,7 @@ import { INERT_FILE_CSP, PAGE_SANDBOX_TOKENS, servedPermissionsPolicy, serialize
|
|
|
2
2
|
import { frameShellDocument, frameShellScript } from "../shell/frame.js";
|
|
3
3
|
import { onNestedLabel, PORTHOLE_LABEL_PREFIX } from "../isolation/served.js";
|
|
4
4
|
import { sha256, utf8 } from "./crypto.js";
|
|
5
|
+
import { ancestorsOf } from "./pages.js";
|
|
5
6
|
import { base32 } from "./keys.js";
|
|
6
7
|
export { isNestedLabel, PORTHOLE_LABEL_PREFIX } from "../isolation/served.js";
|
|
7
8
|
/**
|
|
@@ -33,10 +34,10 @@ const base64 = (bytes) => btoa(String.fromCharCode(...bytes));
|
|
|
33
34
|
/**
|
|
34
35
|
* The shell's CSP (a header): its own script alone runs (by its hash), it frames and fetches
|
|
35
36
|
* nothing but its origin's sealed files (the page, the renewal), and only the host origins frame
|
|
36
|
-
* it. Nothing of the page's runs here: the page is a
|
|
37
|
-
* this (a framed URL's document never does).
|
|
37
|
+
* it (with, above them, a host's `framedBy`, P141). Nothing of the page's runs here: the page is a
|
|
38
|
+
* document of its own, which inherits none of this (a framed URL's document never does).
|
|
38
39
|
*/
|
|
39
|
-
export function nestedShellCsp(script, origin, hostOrigins) {
|
|
40
|
+
export function nestedShellCsp(script, origin, hostOrigins, framedBy = []) {
|
|
40
41
|
const files = `${origin}${NESTED_FILES_PREFIX}`;
|
|
41
42
|
const directives = [
|
|
42
43
|
["default-src", "'none'"],
|
|
@@ -45,7 +46,7 @@ export function nestedShellCsp(script, origin, hostOrigins) {
|
|
|
45
46
|
["connect-src", files],
|
|
46
47
|
["base-uri", "'none'"],
|
|
47
48
|
["form-action", "'none'"],
|
|
48
|
-
["frame-ancestors", ...hostOrigins],
|
|
49
|
+
["frame-ancestors", ...ancestorsOf(hostOrigins, framedBy).split(" ")],
|
|
49
50
|
];
|
|
50
51
|
return serializeCsp(directives);
|
|
51
52
|
}
|
|
@@ -65,7 +66,7 @@ export function nestedShellResponse(compiled, options) {
|
|
|
65
66
|
const script = frameShellScript(options);
|
|
66
67
|
const headers = new Headers({
|
|
67
68
|
"content-type": "text/html; charset=utf-8",
|
|
68
|
-
"content-security-policy": nestedShellCsp(script, options.origin, options.origins),
|
|
69
|
+
"content-security-policy": nestedShellCsp(script, options.origin, options.origins, options.framedBy),
|
|
69
70
|
"cache-control": "no-store",
|
|
70
71
|
"referrer-policy": "no-referrer",
|
|
71
72
|
"x-content-type-options": "nosniff",
|
|
@@ -83,7 +84,8 @@ export function nestedShellResponse(compiled, options) {
|
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* Who may frame a nested page and its files' answers: its shell (the shell's own origin, P114) and,
|
|
86
|
-
* above it, the host origins (`frame-ancestors` names every ancestor)
|
|
87
|
+
* above it, the host origins and a host's `framedBy` (`frame-ancestors` names every ancestor; P141):
|
|
88
|
+
* `frameAncestors` is the server's whole list.
|
|
87
89
|
*/
|
|
88
90
|
export const nestedAncestors = (origin, frameAncestors) => `${origin} ${frameAncestors}`;
|
|
89
91
|
/**
|
package/dist/server/pages.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { FrameBlock } from "../host/types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Who may frame a page: the host origins, then a host's `framedBy` (P141), each checked (they go
|
|
4
|
+
* into a header).
|
|
5
|
+
*/
|
|
6
|
+
export declare function ancestorsOf(hostOrigins: readonly string[], framedBy?: readonly string[]): string;
|
|
2
7
|
/** Where the pages' scripts are served, on every content origin. */
|
|
3
8
|
export declare const STATUS_SCRIPT_PATH = "/__porthole/status.js";
|
|
4
9
|
export declare const ENTER_SCRIPT_PATH = "/__porthole/enter.js";
|
|
@@ -29,7 +34,12 @@ export declare function statusPageOf(options: {
|
|
|
29
34
|
readonly detail: string;
|
|
30
35
|
readonly reason?: FrameBlock;
|
|
31
36
|
readonly hostOrigins: readonly string[];
|
|
32
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Origins of an outer page that may be an ancestor above a host origin's page (P141): added to its
|
|
39
|
+
* `frame-ancestors` after the host origins, never told anything. Default none.
|
|
40
|
+
*/
|
|
41
|
+
readonly framedBy?: readonly string[];
|
|
42
|
+
/** Who may frame it (`frame-ancestors`): default, the host origins, then `framedBy`. */
|
|
33
43
|
readonly frameAncestors?: string;
|
|
34
44
|
readonly link?: {
|
|
35
45
|
readonly href: string;
|
|
@@ -37,9 +47,13 @@ export declare function statusPageOf(options: {
|
|
|
37
47
|
};
|
|
38
48
|
readonly method?: string;
|
|
39
49
|
}): Response;
|
|
40
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* What a door is given: the host origins it tells, and who may frame it (default, those and then
|
|
52
|
+
* `framedBy`, P141: an outer page's origins above a host origin's page, never told anything).
|
|
53
|
+
*/
|
|
41
54
|
export interface DoorOptions {
|
|
42
55
|
readonly hostOrigins: readonly string[];
|
|
56
|
+
readonly framedBy?: readonly string[];
|
|
43
57
|
readonly frameAncestors?: string;
|
|
44
58
|
readonly method?: string;
|
|
45
59
|
}
|
package/dist/server/pages.js
CHANGED
|
@@ -1,13 +1,42 @@
|
|
|
1
1
|
import { DOOR_SANDBOX_TOKENS } from "../compile/policy.js";
|
|
2
|
+
import { framedByProblem } from "../isolation/served.js";
|
|
2
3
|
import { FRAME_STATUS_METHOD } from "../isolation/types.js";
|
|
3
4
|
import { base64url, sha256, utf8 } from "./crypto.js";
|
|
4
5
|
/**
|
|
5
6
|
* The server's own pages on a content origin: why it shows nothing of the content, and the page a
|
|
6
|
-
* framed app is entered through. Plain, framable only by the host origins,
|
|
7
|
-
* the page that frames it how loading went
|
|
8
|
-
* the host origins only, so a host can show
|
|
9
|
-
* the host-agnostic mechanism's; a host that
|
|
7
|
+
* framed app is entered through. Plain, framable only by the host origins (and, above them, a
|
|
8
|
+
* host's `framedBy`, P141), never cached. Each tells the page that frames it how loading went
|
|
9
|
+
* (`porthole/notifications/frame-status`, P040), posted to the host origins only, so a host can show
|
|
10
|
+
* its own fallback ("Open in a new tab"). Their words are the host-agnostic mechanism's; a host that
|
|
11
|
+
* wants its own wording serves its own page in front.
|
|
10
12
|
*/
|
|
13
|
+
/**
|
|
14
|
+
* Whether a page's `frame-ancestors` holds its parent to its host origins: it names no one else.
|
|
15
|
+
* Where it does (a host's `framedBy`, P141), its parent may be an outer page, and the page says
|
|
16
|
+
* `*` only to a parent the engine names as a host origin (`strictParent`, below).
|
|
17
|
+
*/
|
|
18
|
+
const heldToHosts = (frameAncestors, hostOrigins) => frameAncestors
|
|
19
|
+
.split(" ")
|
|
20
|
+
.filter((each) => each !== "")
|
|
21
|
+
.every((each) => hostOrigins.includes(each));
|
|
22
|
+
/** The attribute that says so, on a page's `<main>`: none where its parent is held to its hosts. */
|
|
23
|
+
const strictParent = (frameAncestors, hostOrigins) => heldToHosts(frameAncestors, hostOrigins) ? "" : ' data-porthole-strict-parent=""';
|
|
24
|
+
/**
|
|
25
|
+
* Who may frame a page: the host origins, then a host's `framedBy` (P141), each checked (they go
|
|
26
|
+
* into a header).
|
|
27
|
+
*/
|
|
28
|
+
export function ancestorsOf(hostOrigins, framedBy = []) {
|
|
29
|
+
for (const origin of framedBy) {
|
|
30
|
+
const problem = framedByProblem(origin);
|
|
31
|
+
if (problem !== null) {
|
|
32
|
+
throw new TypeError(`framedBy: ${problem}`);
|
|
33
|
+
}
|
|
34
|
+
if (hostOrigins.includes(origin)) {
|
|
35
|
+
throw new TypeError(`framedBy: ${origin} is a host origin already`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [...hostOrigins, ...framedBy.filter((each, at) => framedBy.indexOf(each) === at)].join(" ");
|
|
39
|
+
}
|
|
11
40
|
const escape = (text) => text.replace(/[&<>"']/gu, (char) => `&#${char.charCodeAt(0)};`);
|
|
12
41
|
const STYLE = ":root{color-scheme:light dark;font-family:system-ui,sans-serif}body{margin:0;min-height:100vh;display:grid;place-items:center;background:Canvas;color:CanvasText}main{max-width:420px;padding:24px}h1{font-size:17px;margin:0 0 8px}p{margin:0;opacity:.75;line-height:1.5}";
|
|
13
42
|
/** Where the pages' scripts are served, on every content origin. */
|
|
@@ -19,16 +48,20 @@ export const SESSION_PATH = "/__porthole/session";
|
|
|
19
48
|
* Tells the page that frames this one how loading went, at each web host origin. A desktop app's
|
|
20
49
|
* own scheme (`ferry://app`) is no target origin a browser takes (postMessage throws), so where
|
|
21
50
|
* the host origins hold one, and the parent isn't known to be a web host origin, the word goes to
|
|
22
|
-
* the parent as `*`: these pages' `frame-ancestors`
|
|
23
|
-
*
|
|
51
|
+
* the parent as `*`: these pages' `frame-ancestors` hold their parent to the host origins, and what
|
|
52
|
+
* they say is no secret (P070). Where it names an outer page too (`framedBy`, P141), the parent may be
|
|
53
|
+
* the outer page: then `*` goes only to a parent the engine names (`location.ancestorOrigins`,
|
|
54
|
+
* not masked as "null") as one of the host origins, so an outer page is never told. One origin
|
|
55
|
+
* failing never stops the page.
|
|
24
56
|
*/
|
|
25
|
-
const say = () => `const
|
|
57
|
+
const say = () => `const strict = main.dataset.portholeStrictParent !== undefined;
|
|
58
|
+
const say = (params) => {
|
|
26
59
|
if (window.parent === window) return;
|
|
27
60
|
const message = { jsonrpc: "2.0", method: ${JSON.stringify(FRAME_STATUS_METHOD)}, params };
|
|
28
61
|
const web = hosts.filter((origin) => origin.startsWith("https://") || origin.startsWith("http://"));
|
|
29
62
|
for (const origin of web) { try { window.parent.postMessage(message, origin); } catch (_) {} }
|
|
30
63
|
const parent = location.ancestorOrigins && location.ancestorOrigins.length > 0 ? location.ancestorOrigins[0] : null;
|
|
31
|
-
if (web.length < hosts.length && (parent === null || !web.includes(parent))) { try { window.parent.postMessage(message, "*"); } catch (_) {} }
|
|
64
|
+
if (web.length < hosts.length && (parent === null || !web.includes(parent)) && (!strict || (parent !== null && hosts.includes(parent)))) { try { window.parent.postMessage(message, "*"); } catch (_) {} }
|
|
32
65
|
};`;
|
|
33
66
|
/** Tells the host the page is blocked, and why (from the page's data attributes). */
|
|
34
67
|
const STATUS_SCRIPT = `(() => {
|
|
@@ -97,7 +130,7 @@ const pageHeaders = (frameAncestors, connect) => ({
|
|
|
97
130
|
"x-robots-tag": "noindex, nofollow",
|
|
98
131
|
});
|
|
99
132
|
export function statusPage(status, title, detail, frameAncestors, method = "GET", reason = "error", hostOrigins = [], code) {
|
|
100
|
-
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}"${code === undefined ? "" : ` data-porthole-code="${escape(code)}"`} data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"><h1>${escape(title)}</h1><p>${escape(detail)}</p></main><script src="${STATUS_SCRIPT_PATH}"></script></body></html>`;
|
|
133
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}"${code === undefined ? "" : ` data-porthole-code="${escape(code)}"`} data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"${strictParent(frameAncestors, hostOrigins)}><h1>${escape(title)}</h1><p>${escape(detail)}</p></main><script src="${STATUS_SCRIPT_PATH}"></script></body></html>`;
|
|
101
134
|
return new Response(method === "HEAD" ? null : body, {
|
|
102
135
|
status,
|
|
103
136
|
headers: pageHeaders(frameAncestors, false),
|
|
@@ -105,7 +138,7 @@ export function statusPage(status, title, detail, frameAncestors, method = "GET"
|
|
|
105
138
|
}
|
|
106
139
|
/** The page a framed app is entered through (its answer also sets the session cookie). */
|
|
107
140
|
export function enterPage(target, frameAncestors, hostOrigins, cookie) {
|
|
108
|
-
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Opening the app</title><style>${STYLE}</style></head><body><main data-porthole-enter="" data-porthole-target="${escape(target)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"><h1>Opening the app…</h1><p></p></main><script src="${ENTER_SCRIPT_PATH}"></script></body></html>`;
|
|
141
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Opening the app</title><style>${STYLE}</style></head><body><main data-porthole-enter="" data-porthole-target="${escape(target)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"${strictParent(frameAncestors, hostOrigins)}><h1>Opening the app…</h1><p></p></main><script src="${ENTER_SCRIPT_PATH}"></script></body></html>`;
|
|
109
142
|
const headers = new Headers(pageHeaders(frameAncestors, true));
|
|
110
143
|
headers.set("set-cookie", cookie);
|
|
111
144
|
return new Response(body, { status: 200, headers });
|
|
@@ -129,7 +162,7 @@ export function appStatusPage(status, title, detail, frameAncestors, reason, hos
|
|
|
129
162
|
const more = link === undefined
|
|
130
163
|
? ""
|
|
131
164
|
: `<p><a href="${escape(link.href)}" target="_top" rel="noopener">${escape(link.text)}</a></p>`;
|
|
132
|
-
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}a{color:inherit}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"><h1>${escape(title)}</h1><p>${escape(detail)}</p>${more}</main><script>${STATUS_SCRIPT}</script></body></html>`;
|
|
165
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}a{color:inherit}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"${strictParent(frameAncestors, hostOrigins)}><h1>${escape(title)}</h1><p>${escape(detail)}</p>${more}</main><script>${STATUS_SCRIPT}</script></body></html>`;
|
|
133
166
|
return new Response(method === "HEAD" ? null : body, {
|
|
134
167
|
status,
|
|
135
168
|
headers: {
|
|
@@ -148,7 +181,7 @@ export function appStatusPage(status, title, detail, frameAncestors, reason, hos
|
|
|
148
181
|
* its one script inline under its hash, so it works on any origin.
|
|
149
182
|
*/
|
|
150
183
|
export function statusPageOf(options) {
|
|
151
|
-
return appStatusPage(options.status, options.title, options.detail, options.frameAncestors ?? options.hostOrigins.
|
|
184
|
+
return appStatusPage(options.status, options.title, options.detail, options.frameAncestors ?? ancestorsOf(options.hostOrigins, options.framedBy), options.reason ?? "error", options.hostOrigins, options.link, options.method);
|
|
152
185
|
}
|
|
153
186
|
/** A door's word that its display may be framed (P125), from the page's data attributes. */
|
|
154
187
|
const DOOR_SCRIPT = `(() => {
|
|
@@ -182,10 +215,11 @@ const doorHeaders = (script, frameAncestors) => new Headers({
|
|
|
182
215
|
*/
|
|
183
216
|
export function doorResponse(options) {
|
|
184
217
|
const hosts = escape(JSON.stringify(options.hostOrigins));
|
|
185
|
-
const
|
|
218
|
+
const ancestors = options.frameAncestors ?? ancestorsOf(options.hostOrigins, options.framedBy);
|
|
219
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Opening</title></head><body><main data-porthole-door="" data-porthole-hosts="${hosts}"${strictParent(ancestors, options.hostOrigins)}></main><script>${DOOR_SCRIPT}</script></body></html>`;
|
|
186
220
|
return new Response(options.method?.toUpperCase() === "HEAD" ? null : body, {
|
|
187
221
|
status: 200,
|
|
188
|
-
headers: doorHeaders(hashOfDoor(),
|
|
222
|
+
headers: doorHeaders(hashOfDoor(), ancestors),
|
|
189
223
|
});
|
|
190
224
|
}
|
|
191
225
|
/**
|
|
@@ -197,10 +231,11 @@ export function doorResponse(options) {
|
|
|
197
231
|
export function doorStatusResponse(options) {
|
|
198
232
|
const { status, reason, code } = options;
|
|
199
233
|
const hosts = escape(JSON.stringify(options.hostOrigins));
|
|
200
|
-
const
|
|
234
|
+
const ancestors = options.frameAncestors ?? ancestorsOf(options.hostOrigins, options.framedBy);
|
|
235
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Not shown</title></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}"${code === undefined ? "" : ` data-porthole-code="${escape(code)}"`} data-porthole-hosts="${hosts}"${strictParent(ancestors, options.hostOrigins)}></main><script>${STATUS_SCRIPT}</script></body></html>`;
|
|
201
236
|
return new Response(options.method?.toUpperCase() === "HEAD" ? null : body, {
|
|
202
237
|
status,
|
|
203
|
-
headers: doorHeaders(hashOfStatus(),
|
|
238
|
+
headers: doorHeaders(hashOfStatus(), ancestors),
|
|
204
239
|
});
|
|
205
240
|
}
|
|
206
241
|
/**
|
package/dist/server/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compile } from "../compile/compile.js";
|
|
2
|
-
import { hostOriginProblem, maybeSameSite, originMatchesSource, parseOrigin, } from "../isolation/served.js";
|
|
2
|
+
import { framedByProblem, hostOriginProblem, maybeSameSite, originMatchesSource, parseOrigin, } from "../isolation/served.js";
|
|
3
3
|
import { DOOR_PATH, } from "../isolation/types.js";
|
|
4
4
|
import { sandboxProxyDocument } from "../mcp/proxy.js";
|
|
5
5
|
import { base32, createKeys, newTicket, ticketId } from "./keys.js";
|
|
@@ -318,7 +318,30 @@ export function createServer(options) {
|
|
|
318
318
|
throw new TypeError(`hostOrigins: ${origin} may be the same site as the content domain ${domain}: serve content from a registrable domain the host uses for nothing else`);
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
|
|
321
|
+
// An outer page's origins (P141): ancestors above a host origin's page, in `frame-ancestors` alone.
|
|
322
|
+
const framedBy = [];
|
|
323
|
+
for (const origin of options.framedBy ?? []) {
|
|
324
|
+
const problem = framedByProblem(origin);
|
|
325
|
+
if (problem !== null) {
|
|
326
|
+
throw new TypeError(`framedBy: ${problem}`);
|
|
327
|
+
}
|
|
328
|
+
if (options.hostOrigins.includes(origin)) {
|
|
329
|
+
throw new TypeError(`framedBy: ${origin} is a host origin already: framedBy names an ancestor that never talks to a frame`);
|
|
330
|
+
}
|
|
331
|
+
const parsed = parseOrigin(origin);
|
|
332
|
+
if (parsed === null ||
|
|
333
|
+
parsed.host === domain ||
|
|
334
|
+
parsed.host.endsWith(`.${domain}`) ||
|
|
335
|
+
maybeSameSite(parsed.host, sampleHost)) {
|
|
336
|
+
throw new TypeError(`framedBy: ${origin} may be the same site as the content domain ${domain}: serve content from a registrable domain the host uses for nothing else`);
|
|
337
|
+
}
|
|
338
|
+
if (!framedBy.includes(origin)) {
|
|
339
|
+
framedBy.push(origin);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Who may be an ancestor of a frame served here: the host origins, then the outer pages' (P141).
|
|
343
|
+
// Every frame's `frame-ancestors` is this; whom a frame hears and tells is `hostOrigins` alone.
|
|
344
|
+
const frameAncestors = [...options.hostOrigins, ...framedBy].join(" ");
|
|
322
345
|
let authorizeUrl = null;
|
|
323
346
|
if (options.entry !== undefined) {
|
|
324
347
|
try {
|
|
@@ -1019,6 +1042,7 @@ export function createServer(options) {
|
|
|
1019
1042
|
const shell = nestedShellResponse(served.compiled, {
|
|
1020
1043
|
origin: access.origin,
|
|
1021
1044
|
origins: options.hostOrigins,
|
|
1045
|
+
framedBy,
|
|
1022
1046
|
page: `${access.origin}${sealed.base}${rest}`,
|
|
1023
1047
|
renew: { url: `${access.origin}${sealed.base}__porthole/renew`, expires: sealed.expires },
|
|
1024
1048
|
method,
|
package/dist/server/types.d.ts
CHANGED
|
@@ -258,6 +258,14 @@ export interface ServerOptions {
|
|
|
258
258
|
readonly secret: Uint8Array;
|
|
259
259
|
/** The host origins that may embed content (`frame-ancestors`) and talk to a served shell. */
|
|
260
260
|
readonly hostOrigins: readonly string[];
|
|
261
|
+
/**
|
|
262
|
+
* Further origins that may be an ancestor of every frame served here, above a host origin's
|
|
263
|
+
* page (P141): an outer page that frames the host's app. Added to each `frame-ancestors` after
|
|
264
|
+
* the host origins, and nowhere else: never an origin a shell, a door or a page takes a message
|
|
265
|
+
* from or says anything to, never a host origin for `entry` or the handoff. Exact https origins
|
|
266
|
+
* (`http://` on loopback), none a host origin, none the content domain's site. Default none.
|
|
267
|
+
*/
|
|
268
|
+
readonly framedBy?: readonly string[];
|
|
261
269
|
/**
|
|
262
270
|
* The configs a served shell or page is served under, by the name a `ServedDocument` gives
|
|
263
271
|
* (an artifact defaults to `artifact`, the MCP Apps sandbox proxy to `mcpApp`).
|
package/dist/shell/frame.d.ts
CHANGED
|
@@ -37,6 +37,12 @@ export { SHELL_METHOD_PREFIX, SHELL_STATE_METHOD } from "../isolation/types.ts";
|
|
|
37
37
|
export interface FrameShellOptions {
|
|
38
38
|
/** The host origins: the shell takes messages from its parent only from these. */
|
|
39
39
|
readonly origins: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* Origins of an outer page that may be an ancestor above a host origin's page (P141): in the
|
|
42
|
+
* shell's `frame-ancestors` after `origins` (`nestedShellResponse`), never heard or told. Where
|
|
43
|
+
* there are any, the shell says `*` only to a parent the engine names as a host origin.
|
|
44
|
+
*/
|
|
45
|
+
readonly framedBy?: readonly string[];
|
|
40
46
|
/** The page's address: absolute, on the shell's own origin, under `/__porthole/f/`. */
|
|
41
47
|
readonly page: string;
|
|
42
48
|
/** The page frame's accessible name. */
|
package/dist/shell/frame.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PAGE_SANDBOX_TOKENS } from "../compile/policy.js";
|
|
2
|
-
import { hostOriginProblem, onNestedLabel } from "../isolation/served.js";
|
|
2
|
+
import { framedByProblem, hostOriginProblem, onNestedLabel } from "../isolation/served.js";
|
|
3
3
|
/**
|
|
4
4
|
* Porthole's shell for a nested page (P111): the whole document at the address the host frames,
|
|
5
5
|
* with no content in it. It frames the page (the same origin's sealed files' address) in a child
|
|
@@ -80,7 +80,9 @@ export const FRAME_SHELL_RUNTIME = String.raw `(() => {
|
|
|
80
80
|
const web = plan.origins.filter((origin) => origin.indexOf("https://") === 0 || origin.indexOf("http://") === 0);
|
|
81
81
|
// To the host: each web host origin (only the parent's is delivered); a desktop app's own scheme
|
|
82
82
|
// is no target a browser takes, so where one is listed and the parent isn't a known web origin,
|
|
83
|
-
// "*" (frame-ancestors holds the parent to the host origins; nothing said here is secret).
|
|
83
|
+
// "*" (frame-ancestors holds the parent to the host origins; nothing said here is secret). Where
|
|
84
|
+
// it names an outer page above them too (the host's framedBy, P141: plan.strictParent), the parent
|
|
85
|
+
// may be the outer page: "*" then goes only to a parent the engine names as a host origin.
|
|
84
86
|
const toHost = (message) => {
|
|
85
87
|
if (!framed) {
|
|
86
88
|
return;
|
|
@@ -91,7 +93,11 @@ export const FRAME_SHELL_RUNTIME = String.raw `(() => {
|
|
|
91
93
|
} catch (_) {}
|
|
92
94
|
}
|
|
93
95
|
const parent = location.ancestorOrigins && location.ancestorOrigins.length > 0 ? location.ancestorOrigins[0] : null;
|
|
94
|
-
if (
|
|
96
|
+
if (
|
|
97
|
+
web.length < plan.origins.length &&
|
|
98
|
+
(parent === null || web.indexOf(parent) === -1) &&
|
|
99
|
+
(plan.strictParent !== true || (parent !== null && plan.origins.indexOf(parent) !== -1))
|
|
100
|
+
) {
|
|
95
101
|
try {
|
|
96
102
|
window.parent.postMessage(message, "*");
|
|
97
103
|
} catch (_) {}
|
|
@@ -271,6 +277,12 @@ export function frameShellScript(options) {
|
|
|
271
277
|
throw new TypeError(`frameShellScript: ${problem}`);
|
|
272
278
|
}
|
|
273
279
|
}
|
|
280
|
+
for (const origin of options.framedBy ?? []) {
|
|
281
|
+
const problem = framedByProblem(origin);
|
|
282
|
+
if (problem !== null || options.origins.includes(origin)) {
|
|
283
|
+
throw new TypeError(`frameShellScript: framedBy: ${problem ?? `${origin} is a host origin`}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
274
286
|
let page;
|
|
275
287
|
try {
|
|
276
288
|
page = new URL(options.page);
|
|
@@ -287,6 +299,7 @@ export function frameShellScript(options) {
|
|
|
287
299
|
}
|
|
288
300
|
return FRAME_SHELL_RUNTIME.replace("__PLAN__", () => scriptJson({
|
|
289
301
|
origins: options.origins,
|
|
302
|
+
...((options.framedBy ?? []).length === 0 ? {} : { strictParent: true }),
|
|
290
303
|
page: page.href,
|
|
291
304
|
sandbox: PAGE_SANDBOX_TOKENS.join(" "),
|
|
292
305
|
...(options.title === undefined ? {} : { title: options.title }),
|
package/docs/ADOPTING.md
CHANGED
|
@@ -745,6 +745,15 @@ nodeServer({ content, app: async (request) => (await routes(request)) ?? app(req
|
|
|
745
745
|
- **`Response.redirect` needs an absolute URL** outside a browser (Node throws on `/login`).
|
|
746
746
|
- **`reserved`** is only for labels your app itself serves on the content domain (previews of a
|
|
747
747
|
dev server, `p-*`). Labels nothing serves need nothing: they are a 404 there.
|
|
748
|
+
- **`framedBy`** (P141): where another app frames yours (a dashboard that embeds your app in an
|
|
749
|
+
iframe), its origins: `framedBy: ["https://dashboard.example.com"]`. `frame-ancestors` names every
|
|
750
|
+
ancestor, so without it each of your frames is blank inside that app. Each may then be an
|
|
751
|
+
ancestor of every frame Porthole serves, after `appOrigins`, and is never a host: no frame hears
|
|
752
|
+
or tells it, it isn't in `data-porthole-hosts`, and redirect entry and the handoff stay
|
|
753
|
+
`appOrigins`' alone. Exact https origins (`http://` on loopback), none an app origin. Your own
|
|
754
|
+
page between them is still the frame's parent, and its `frame-ancestors` is yours to set. A
|
|
755
|
+
content Worker of your own passes the same list to `statusPage`, `doorResponse`,
|
|
756
|
+
`doorStatusResponse` and `nestedShellResponse` (`framedBy`).
|
|
748
757
|
- **No content domain** (self-hosted without one): still make the host, with `domain: null` (or
|
|
749
758
|
`""`). That is the supported setup: no secret is needed, `GET /porthole/meta` answers
|
|
750
759
|
`{ served: false }`, and pages show every kind opaque (a url kind, its fallback) instead of
|
|
@@ -919,7 +928,7 @@ no frame), `nestedShellResponse` throws for another origin, and the shell runs n
|
|
|
919
928
|
|
|
920
929
|
| Request | Answer |
|
|
921
930
|
| --- | --- |
|
|
922
|
-
| `<origin>/__porthole/d/<key>`, the framed address (a ticket's, a cookie's reload; an entered clean address on the scope's label answers a `303` here with a one-time ticket), a navigation | 200, `text/html`: Porthole's shell, `nestedShellResponse(compiled, { origin, origins: hostOrigins, page: "<origin>/__porthole/f/<token>/<entry>", renew: { url: "<origin>/__porthole/f/<token>/__porthole/renew", expires } })`. Headers: `Content-Security-Policy: default-src 'none'; script-src 'sha256-<its script>'; frame-src <origin>/__porthole/f/; connect-src <origin>/__porthole/f/; base-uri 'none'; form-action 'none'; frame-ancestors <host origins>`; `Cache-Control: no-store`; `Referrer-Policy: no-referrer`; `X-Content-Type-Options: nosniff`; the served `Permissions-Policy`. No content in it. Any other request there: 404. |
|
|
931
|
+
| `<origin>/__porthole/d/<key>`, the framed address (a ticket's, a cookie's reload; an entered clean address on the scope's label answers a `303` here with a one-time ticket), a navigation | 200, `text/html`: Porthole's shell, `nestedShellResponse(compiled, { origin, origins: hostOrigins, framedBy, page: "<origin>/__porthole/f/<token>/<entry>", renew: { url: "<origin>/__porthole/f/<token>/__porthole/renew", expires } })`. Headers: `Content-Security-Policy: default-src 'none'; script-src 'sha256-<its script>'; frame-src <origin>/__porthole/f/; connect-src <origin>/__porthole/f/; base-uri 'none'; form-action 'none'; frame-ancestors <host origins> <framedBy>`; `Cache-Control: no-store`; `Referrer-Policy: no-referrer`; `X-Content-Type-Options: nosniff`; the served `Permissions-Policy`. No content in it. Any other request there: 404. |
|
|
923
932
|
| `<origin>/__porthole/f/<token>/<page>` (the shell's child, or a tab) | The page as served before (the shell's runtime and the page), its plan's `origins` the content origin alone (`[<origin>]`) and its storage `memory`. `Content-Security-Policy`: `nestedFileCsp("page", fileSetCspDirectives(compiled.cspDirectives, "<origin>/__porthole/f/"))` then `; frame-ancestors ` and `nestedAncestors("<origin>", "<host origins>")`: the page's directives, its files' prefix opened, and `sandbox allow-scripts` (never `allow-same-origin`). Access from `<token>` alone: no cookie is sent (the page's origin is opaque), and never decide by `Origin` (it is `null`) or `Sec-Fetch-Site` (`cross-site`). |
|
|
924
933
|
| `<origin>/__porthole/f/<token>/<file>` (the page's loads) | As served files are, plus `Cross-Origin-Resource-Policy: cross-origin` and `Access-Control-Allow-Origin: *` (`NESTED_FILE_HEADERS`): the opaque page's images, scripts, modules, fonts and fetches are cross-origin. Every one carries a CSP sandbox, never `allow-same-origin` (`nestedFileCsp(fileTypeOf(path).role, directives)`, then the `frame-ancestors` above): a non-page file `default-src 'none'; sandbox`, a script its directives plus `sandbox`, so none opened on a tab of its own (an SVG, an XML file) runs on the shell's origin. |
|
|
925
934
|
| `<origin>/__porthole/f/<token>/__porthole/renew` | Only the shell's own fetch (`Sec-Fetch-Site: same-origin`, not a navigation): `{ "base": "<origin>/__porthole/f/<new token>/", "expires": <epoch ms> }`, `no-store`; anything else 403. The shell renews 5 minutes before `expires` and moves the page to the new base. |
|
|
@@ -1145,8 +1154,8 @@ A **content Worker of your own** (one that answers the content origins itself, i
|
|
|
1145
1154
|
`/server`) serves the door too: `issue` mints the door ticket and returns `door: { url }`, and the
|
|
1146
1155
|
Worker routes `DOOR_PATH + <key>` (`/__porthole/door/<key>`) on every label — take the door ticket
|
|
1147
1156
|
(`TicketRecord.door === true`, bound to the label and key), run the same access, document and entry
|
|
1148
|
-
checks the content route runs for that grant, then answer `doorResponse({ hostOrigins })` (open) or
|
|
1149
|
-
`doorStatusResponse({ status, reason, code?, hostOrigins })` (401 `session` / 403 `denied` / 404
|
|
1157
|
+
checks the content route runs for that grant, then answer `doorResponse({ hostOrigins, framedBy })` (open) or
|
|
1158
|
+
`doorStatusResponse({ status, reason, code?, hostOrigins, framedBy })` (401 `session` / 403 `denied` / 404
|
|
1150
1159
|
`not-found` / 500 `error`). Refuse a door ticket at `/__porthole/d/`, and serve no door on a nested
|
|
1151
1160
|
page's shell label. `DOOR_PATH`, `doorResponse` and `doorStatusResponse` are exported from
|
|
1152
1161
|
`@botiverse/porthole/server`.
|
package/docs/DECISIONS.md
CHANGED
|
@@ -8653,3 +8653,115 @@ it fails at the second pick.
|
|
|
8653
8653
|
|
|
8654
8654
|
**Revisit when** a host needs the pick kept without following it (a host that draws its own
|
|
8655
8655
|
highlight from `selected`), or a host is seen confused by `orphaned` after an upgrade.
|
|
8656
|
+
|
|
8657
|
+
|
|
8658
|
+
## P141 · 2026-11-09 · An app framed by another: its outer page may be an ancestor of its frames, never their host (`framedBy`) · Accepted
|
|
8659
|
+
|
|
8660
|
+
From Raft (task #botiverse-raft-deployment:#245, Tenny): Deck (`https://deck.raft.build`, and
|
|
8661
|
+
`https://deck-aws-dev.raft.build` on staging) frames the Raft app (`app.raft.build`) in an iframe.
|
|
8662
|
+
|
|
8663
|
+
**Context.** `frame-ancestors` is checked against every ancestor, not only the parent: a frame the
|
|
8664
|
+
app shows inside Deck has Deck above the app, and every policy Porthole sends names the host
|
|
8665
|
+
origins alone (`appOrigins`, `hostOrigins`), so each of the app's frames went blank inside Deck.
|
|
8666
|
+
The same list is also who a frame hears and tells: the shell's and the nested shell's message
|
|
8667
|
+
origins, the pages' and doors' `data-porthole-hosts`, the host kit's checks for redirect entry and
|
|
8668
|
+
the handoff. Adding Deck to `appOrigins` would let it frame content *and* speak to it as its host:
|
|
8669
|
+
answer a shell's `ui/initialize`, call host functions on the bridge's word, hear what a frame says
|
|
8670
|
+
to its host. The app frames content; Deck frames the app. Only the first is a host.
|
|
8671
|
+
|
|
8672
|
+
**Decision.**
|
|
8673
|
+
|
|
8674
|
+
1. **`framedBy: readonly string[]`**, on `createServer` and `createContentHost` (and on the helpers
|
|
8675
|
+
a content Worker of its own answers with: `statusPage`, `doorResponse`, `doorStatusResponse`
|
|
8676
|
+
and `nestedShellResponse` take it too), names origins that may be an **ancestor** of every
|
|
8677
|
+
frame Porthole serves, above a host origin's page. Default none: every response is as before,
|
|
8678
|
+
byte for byte.
|
|
8679
|
+
2. **They are in every `frame-ancestors` and nowhere else**: after the host origins, in each
|
|
8680
|
+
policy `/server` sends (a shell, an artifact page, a file set's pages and files and their own
|
|
8681
|
+
frames, a nested page's shell, page and files, the MCP Apps proxy, a door and a door that doesn't
|
|
8682
|
+
open, the status, entry and tab-only pages, assets, a renewal, a url-mode app's answers: one
|
|
8683
|
+
list in `createServer`, `frameAncestors`) and in
|
|
8684
|
+
the host kit's authorize route's pages. Never a message origin of a shell, a nested shell, a
|
|
8685
|
+
door or a page; never in `data-porthole-hosts` or a shell's plan; never a host origin for
|
|
8686
|
+
`entry.authorizeUrl`, the handoff's `Origin` check (still `appOrigins` alone) or the content
|
|
8687
|
+
domain's clash rules, which they are checked against apart.
|
|
8688
|
+
3. **They are checked as host origins are, more narrowly**: exact origins, `https://host[:port]`
|
|
8689
|
+
(`http://` on loopback alone, for development), lowercase, no path, no wildcard, no keyword, never
|
|
8690
|
+
`"null"` or a desktop scheme (an outer page is a web page); none a host origin (one origin is a
|
|
8691
|
+
host or an outer page, never both); none on, or maybe the same site as, the content domain.
|
|
8692
|
+
A bad one throws (`framedBy: …`), as a bad host origin does, before anything goes into a header;
|
|
8693
|
+
the host kit's fallback makes it a lasting `misconfigured`, as it does a bad app origin.
|
|
8694
|
+
4. **The direct parent must still be a host origin, and Porthole holds it so where it can.**
|
|
8695
|
+
`frame-ancestors` can't say "an ancestor but not the parent": with `framedBy`, an outer page
|
|
8696
|
+
that frames content directly is let in by the browser. Such a frame gets no host:
|
|
8697
|
+
- *Heard:* the shell, the nested shell and a door take a message only from a host origin
|
|
8698
|
+
(`event.origin` in its plan's `origins`): the outer page's `ui/initialize` answer is dropped,
|
|
8699
|
+
the handshake ends with no host (`data-porthole-host="none"`, P139), `porthole.use` is null,
|
|
8700
|
+
and the bridge never runs: no host function is called on its word.
|
|
8701
|
+
- *Told:* Porthole's own words go to each web host origin by name, so only a host origin as the
|
|
8702
|
+
parent receives them. The one exception was the `*` fallback where a desktop scheme is a host
|
|
8703
|
+
origin (P070, its item 6), whose premise ("these pages are framable only by the host origins,
|
|
8704
|
+
so their parent is one") `framedBy` breaks. Now, where a page's `frame-ancestors` names anyone
|
|
8705
|
+
beyond its host origins (`data-porthole-strict-parent` on the status, entry and door pages;
|
|
8706
|
+
`strictParent` in a nested shell's plan), `*` goes only to a parent the engine names
|
|
8707
|
+
(`location.ancestorOrigins[0]`, not masked as `"null"`) as one of the host origins: an outer
|
|
8708
|
+
page as the parent, or a parent the engine doesn't name, is never told. Without `framedBy`
|
|
8709
|
+
the rule is P070's, unchanged.
|
|
8710
|
+
|
|
8711
|
+
**What it re-opens (PRINCIPLE 1).** An outer page may now be an ancestor of content, which no
|
|
8712
|
+
origin but the host's could be.
|
|
8713
|
+
- *Clickjacking and framing the app's content from another app*: bounded to the origins the host
|
|
8714
|
+
names, each exact; the host's own page between them stays the host's (its `frame-ancestors` is
|
|
8715
|
+
the app's to set: Raft's in Terraform, not Porthole's).
|
|
8716
|
+
- *An outer page framing content directly*: it needs an address to frame. Tickets come from the
|
|
8717
|
+
host's issue endpoint and are used once; a clean address in a frame is the tab-only page (P125);
|
|
8718
|
+
a sealed address is in the frame's own document. If it has one, the frame loads, but as above it
|
|
8719
|
+
is no host. It hears what content says to its parent with `*` itself: the content shell's own
|
|
8720
|
+
notices (its runtime posts to `*`, P053: the content shares that realm and could post anything
|
|
8721
|
+
itself), annotation and find reports. That is the content's word, which any parent of a frame
|
|
8722
|
+
could always hear, and which the outer page must treat as untrusted; on a nested page the shell
|
|
8723
|
+
passes the page's words to host origins alone, by name, so an outer parent hears none of them.
|
|
8724
|
+
- *Partitioned cookies*: a frame below the outer page is keyed to the top-level site, the outer
|
|
8725
|
+
page's (CHIPS), as any embedding is. Where the outer page is another site than the app, a
|
|
8726
|
+
session made inside it is that partition's alone; where it is the same site (Deck at
|
|
8727
|
+
`deck.raft.build`, the app at `app.raft.build`: both `raft.build`), it is the partition the app's
|
|
8728
|
+
own tab uses too, as for any page of that site. No sharing is added across sites.
|
|
8729
|
+
|
|
8730
|
+
**Rejected.**
|
|
8731
|
+
- *Adding the outer page to `appOrigins`*: it would be a host: heard, told, an origin for entry
|
|
8732
|
+
and the handoff. Exactly what Tenny ruled out.
|
|
8733
|
+
- *A wildcard, or any https origin*: an outer page is one product's, named.
|
|
8734
|
+
- *Refusing an outer page as the parent outright*: no header can, and a shell that refused to draw
|
|
8735
|
+
where `ancestorOrigins[0]` is an outer page would decide nothing on Firefox's masked `"null"`
|
|
8736
|
+
(measured: Firefox masks a `no-referrer` frame's ancestors, Chromium names them), while it is no
|
|
8737
|
+
host already.
|
|
8738
|
+
- *The outer origins in the pages' bodies, for the `*` check*: one boolean (`strict`) says enough
|
|
8739
|
+
(the parent must be named, and a host origin), and keeps them out of everything but the header.
|
|
8740
|
+
|
|
8741
|
+
**Tested.** `test/framed-by.test.ts`: `framedBy` taken (https, loopback http) and refused (a
|
|
8742
|
+
wildcard, a path, uppercase, `*`, `'self'`, a list, a CSP injection, `"null"`, a desktop scheme,
|
|
8743
|
+
plain http, a host origin, the content domain and its site), in `createServer`, the helpers and
|
|
8744
|
+
the host kit; **the bound**: every answer of 23 (a shell and its used ticket, a 404, a door and a
|
|
8745
|
+
used door, an artifact page, the MCP Apps proxy, two file sets' tickets, pages, scripts, files and
|
|
8746
|
+
refused renewals, one of them with its own frames, a nested page's shell, page, script and ended
|
|
8747
|
+
access, a url-mode app's entry page and answer), under host origins with a desktop scheme and one
|
|
8748
|
+
`framedBy`, names it in `frame-ancestors` after the host origins, every
|
|
8749
|
+
framed document has `frame-ancestors`, and none says the outer origin in another header or its body
|
|
8750
|
+
(not in `data-porthole-hosts`, not in a plan's `origins`); without `framedBy` none is strict and
|
|
8751
|
+
none names it; the helpers' defaults are as before; the host kit's content and authorize route's pages name it,
|
|
8752
|
+
and the handoff refuses its `Origin` (403) where the app's own is taken. Assets and the tab-only
|
|
8753
|
+
page take the same one list (`frameAncestors`), untested apart. **The negative controls**: the status script, strict, says `*` only
|
|
8754
|
+
to a parent named as a host origin (desktop: yes; the outer page, `"null"`, unnamed: no), and not
|
|
8755
|
+
strict says it as before; the nested shell's script, given `framedBy`, says no `*` to an outer
|
|
8756
|
+
parent and passes none of its words to the page, while a host's word passes. Taking the strict
|
|
8757
|
+
condition out fails both. `leak/served/framed-by.spec.ts` (Chromium and Firefox here; WebKit not
|
|
8758
|
+
run on this machine): below the outer page, the app's frame shows and is answered by the app; below
|
|
8759
|
+
a foreign page it is refused; the outer page framing content itself sees the frame load and its
|
|
8760
|
+
`ui/initialize` answer refused, the handshake ending `"none"`; a door framed by the app tells it
|
|
8761
|
+
`open`, framed by the outer page says nothing to it (with the strict condition taken out it says
|
|
8762
|
+
`*`, and the probe fails). No weakening in `leak/weakenings.ts`: the probes above are the
|
|
8763
|
+
control, run as mutations.
|
|
8764
|
+
|
|
8765
|
+
**Revisit when** an outer page needs to speak to a frame (then it is a host, and needs
|
|
8766
|
+
`appOrigins`), browsers give a policy for the parent alone, or a host wants an outer page to frame
|
|
8767
|
+
content without its own page between them.
|
package/docs/THREAT_MODEL.md
CHANGED
|
@@ -5,7 +5,7 @@ What Porthole protects, from whom, and where that protection ends. For each way
|
|
|
5
5
|
guaranteed. [ADOPTING.md](ADOPTING.md) says how to set each one up, and
|
|
6
6
|
[DESIGN.md](DESIGN.md) lists every defense with the test that proves it.
|
|
7
7
|
|
|
8
|
-
**Status.** This describes Porthole 0.14.
|
|
8
|
+
**Status.** This describes Porthole 0.14.17 (2026-11-09). A review on 2026-10-19 found gaps, and every decision it led to
|
|
9
9
|
has merged ([§8](#8-fixes-in-flight) lists them). P096 changed the negative-control runner and CI,
|
|
10
10
|
and the shipped conformance probes' messages and timing, not what they check. P104 (0.9.0's
|
|
11
11
|
annotation markers) had a review of its own, and P105, in 0.10.0, is what it led to. 0.11.0 was
|
|
@@ -43,7 +43,11 @@ word 100 ms old or more; no wall moves. 0.14.15: P138 lets the host follow the c
|
|
|
43
43
|
(`selectionTracked`, the same boxes as `tracked`, on its budget, only while asked) and keeps what was
|
|
44
44
|
picked lit; no wall moves. 0.14.16: P139 has a shell on a tab of its own ask no host; P140 narrows P138: a pick stays lit, and a
|
|
45
45
|
selection is kept in the frame, only for a host that follows the selection (`keepSelection`), and a
|
|
46
|
-
host that follows none drops `selectionTracked` unread (§7).
|
|
46
|
+
host that follows none drops `selectionTracked` unread (§7). 0.14.17: P141 lets a host name the
|
|
47
|
+
origins of an outer page that frames its app (`framedBy`): each may be an ancestor of every frame,
|
|
48
|
+
above the host's own page, so it is in every `frame-ancestors`, and nowhere else; it is never a
|
|
49
|
+
host a frame hears or tells, and a page's `*` fallback is held to a parent named as a host origin
|
|
50
|
+
(§6 "What every host must do", S3).
|
|
47
51
|
|
|
48
52
|
## 1. Two layers
|
|
49
53
|
|
|
@@ -266,7 +270,16 @@ Whatever the use:
|
|
|
266
270
|
`display.focus()` inside a key's own handler moves nothing: call it from a task (measured on a
|
|
267
271
|
nested page). Nothing leaks either way: the keyboard stays out of the page.
|
|
268
272
|
- List every app origin in `appOrigins` (`hostOrigins` in `/server`): only those may frame content,
|
|
269
|
-
and only those are checked against the content
|
|
273
|
+
only those are a frame's host (heard and told), and only those are checked against the content
|
|
274
|
+
domain for a shared site.
|
|
275
|
+
- Where another app frames yours (P141), name its origins in `framedBy`, never in `appOrigins`: it
|
|
276
|
+
may then be an ancestor of your frames, above your own page, and is never their host. Your page
|
|
277
|
+
must still be the frame's parent: an outer page that frames content directly (with an address it
|
|
278
|
+
got from somewhere) is let in by the browser, but the frame takes nothing from it (no handshake,
|
|
279
|
+
no host function), Porthole's own pages and a nested page's shell tell it nothing, and what it
|
|
280
|
+
can hear is the content's own word to its parent (`*`), which it must treat as untrusted. Your
|
|
281
|
+
app page's own `frame-ancestors` is yours to set; Porthole never sends it. Name exact origins of
|
|
282
|
+
that one product, and drop them when it stops framing you.
|
|
270
283
|
- Under the app runtime, run `defineRuntimeConformance` with `api` in CI (§7).
|
|
271
284
|
|
|
272
285
|
### S1. Inline widgets in a conversation
|
|
@@ -419,7 +432,8 @@ encrypted into the path, since WebKit keeps no cookie in a frame (P083).
|
|
|
419
432
|
another label's session is never read as this one's, under https or on loopback (P101).
|
|
420
433
|
- Pages, files and status pages carry their CSP in headers and `X-Robots-Tag: noindex`, and
|
|
421
434
|
`frame-ancestors` names the app's origins only (with `nestedFrames: "own"`, P128, a file set's
|
|
422
|
-
files below its base name the page's own origin too, so its pages frame them)
|
|
435
|
+
files below its base name the page's own origin too, so its pages frame them), then the host's
|
|
436
|
+
`framedBy`, if any (P141): ancestors above the app's page, never its host.
|
|
423
437
|
- Files: from the version's manifest only, typed by Porthole's table, `nosniff`; files other than
|
|
424
438
|
pages are `Cross-Origin-Resource-Policy: same-origin`; a file set never registers a service
|
|
425
439
|
worker; a page's CSP opens its own version's path, not its whole origin.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botiverse/porthole",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.17",
|
|
4
4
|
"description": "A host-side sandbox for agent-made HTML: isolation, egress hardening, a themed shell, gated host functions, and the agent manual, from one config.",
|
|
5
5
|
"homepage": "https://github.com/botiverse/porthole#readme",
|
|
6
6
|
"bugs": {
|
package/src/isolation/served.ts
CHANGED
|
@@ -78,6 +78,27 @@ export function hostOriginProblem(origin: unknown): string | null {
|
|
|
78
78
|
return `${JSON.stringify(origin)} is not an exact origin (scheme://host[:port], lowercase, no path)`;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
const LOOPBACK_HOST = (host: string): boolean =>
|
|
82
|
+
host === "localhost" || host.endsWith(".localhost") || host === "127.0.0.1" || host === "[::1]";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Why `origin` can't be one of a host's `framedBy` (P141): an outer page that may be an
|
|
86
|
+
* ancestor of every frame the host shows, above the host's own page, and never a host origin. An
|
|
87
|
+
* exact web origin, `https://host[:port]` (lowercase, no path, no wildcard), or `http://` on
|
|
88
|
+
* loopback alone (`localhost`, `*.localhost`, `127.0.0.1`, `[::1]`) for development: never a
|
|
89
|
+
* desktop scheme, `"null"`, a CSP keyword or a list. Null if it can be.
|
|
90
|
+
*/
|
|
91
|
+
export function framedByProblem(origin: unknown): string | null {
|
|
92
|
+
const parsed = typeof origin === "string" && isHostOrigin(origin) ? parseOrigin(origin) : null;
|
|
93
|
+
if (
|
|
94
|
+
parsed === null ||
|
|
95
|
+
!(parsed.scheme === "https" || (parsed.scheme === "http" && LOOPBACK_HOST(parsed.host)))
|
|
96
|
+
) {
|
|
97
|
+
return `${JSON.stringify(origin)} is not an exact https origin (https://host[:port], lowercase, no path; http only on loopback)`;
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
81
102
|
/**
|
|
82
103
|
* Whether two hosts may be the same site. Without the public-suffix list this errs one way only:
|
|
83
104
|
* it says "same site" whenever the hosts are equal or share their last two labels, so a pair it
|
package/src/server/host.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "./domain.ts";
|
|
13
13
|
import { reservedLabels, type Naming } from "./naming.ts";
|
|
14
14
|
import { peerAddress } from "./peer.ts";
|
|
15
|
-
import { appStatusPage, tabOnlyPage } from "./pages.ts";
|
|
15
|
+
import { ancestorsOf, appStatusPage, tabOnlyPage } from "./pages.ts";
|
|
16
16
|
import { createServer } from "./server.ts";
|
|
17
17
|
import type {
|
|
18
18
|
Access,
|
|
@@ -105,8 +105,21 @@ type Awaitable<T> = T | Promise<T>;
|
|
|
105
105
|
export interface ContentHostOptions<V> {
|
|
106
106
|
/** `content.example.com`, `content.localhost:8790`; empty: content off. Or parsed settings. */
|
|
107
107
|
readonly domain: string | null | undefined | ContentDomainInfo;
|
|
108
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* The app's own origins: they frame content (`frame-ancestors`), are the only origins its frames
|
|
110
|
+
* hear and tell, and are checked for clashes.
|
|
111
|
+
*/
|
|
109
112
|
readonly appOrigins: readonly string[];
|
|
113
|
+
/**
|
|
114
|
+
* Origins of an outer page that frame the app itself (P141): each may be an ancestor of every frame
|
|
115
|
+
* the app shows, above an app origin's page, so it is in every `frame-ancestors` Porthole sends
|
|
116
|
+
* (content, nested pages, doors, status and entry pages, the authorize route's pages) after
|
|
117
|
+
* `appOrigins`, and nowhere else. Never an origin a frame hears or tells, never an app origin for
|
|
118
|
+
* redirect entry or the handoff; the app's own page must still be the frame's parent. Exact https
|
|
119
|
+
* origins (`http://` on loopback), none an app origin, none the content domain's site. The app's
|
|
120
|
+
* own `frame-ancestors` (its page's, which Porthole doesn't send) is the app's to set.
|
|
121
|
+
*/
|
|
122
|
+
readonly framedBy?: readonly string[];
|
|
110
123
|
/** At least 32 random bytes (or a string of at least 32 bytes). */
|
|
111
124
|
readonly secret: Uint8Array | string;
|
|
112
125
|
readonly tickets?: TicketStore;
|
|
@@ -636,6 +649,8 @@ export function createContentHost<V>(options: ContentHostOptions<V>): ContentHos
|
|
|
636
649
|
let server: PortholeServer | null = null;
|
|
637
650
|
let view: ContentHealthView = { state: "off" };
|
|
638
651
|
let configs: Readonly<Record<string, PortholeConfig>> = {};
|
|
652
|
+
// Who may frame the authorize route's pages: the app origins, and the outer pages' once checked.
|
|
653
|
+
let appAncestors = options.appOrigins.join(" ");
|
|
639
654
|
|
|
640
655
|
try {
|
|
641
656
|
domain =
|
|
@@ -676,6 +691,7 @@ export function createContentHost<V>(options: ContentHostOptions<V>): ContentHos
|
|
|
676
691
|
}),
|
|
677
692
|
secret,
|
|
678
693
|
hostOrigins: options.appOrigins,
|
|
694
|
+
...(options.framedBy === undefined ? {} : { framedBy: options.framedBy }),
|
|
679
695
|
configs,
|
|
680
696
|
...(options.source === undefined ? {} : { artifacts: { get: options.source } }),
|
|
681
697
|
...(options.assets === undefined
|
|
@@ -714,6 +730,8 @@ export function createContentHost<V>(options: ContentHostOptions<V>): ContentHos
|
|
|
714
730
|
},
|
|
715
731
|
}),
|
|
716
732
|
});
|
|
733
|
+
// createServer checked them (P141): only then in a header of the app's.
|
|
734
|
+
appAncestors = ancestorsOf(options.appOrigins, options.framedBy);
|
|
717
735
|
view = gate === undefined ? { state: "healthy" } : { state: "checking" };
|
|
718
736
|
}
|
|
719
737
|
} catch (error) {
|
|
@@ -1308,7 +1326,7 @@ export function createContentHost<V>(options: ContentHostOptions<V>): ContentHos
|
|
|
1308
1326
|
status,
|
|
1309
1327
|
title,
|
|
1310
1328
|
detail,
|
|
1311
|
-
|
|
1329
|
+
appAncestors,
|
|
1312
1330
|
reason,
|
|
1313
1331
|
options.appOrigins,
|
|
1314
1332
|
link,
|
|
@@ -1337,7 +1355,7 @@ export function createContentHost<V>(options: ContentHostOptions<V>): ContentHos
|
|
|
1337
1355
|
// sign-in or refusal there, and says nothing to the page that frames it.
|
|
1338
1356
|
const dest = request.headers.get("sec-fetch-dest");
|
|
1339
1357
|
if (dest === "iframe" || dest === "frame") {
|
|
1340
|
-
return tabOnlyPage(
|
|
1358
|
+
return tabOnlyPage(appAncestors, method);
|
|
1341
1359
|
}
|
|
1342
1360
|
const clean = `${domain.originOf(state.label)}${state.path}`;
|
|
1343
1361
|
if (state.expired) {
|
package/src/server/nested.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { frameShellDocument, frameShellScript, type FrameShellOptions } from "../shell/frame.ts";
|
|
10
10
|
import { onNestedLabel, PORTHOLE_LABEL_PREFIX } from "../isolation/served.ts";
|
|
11
11
|
import { sha256, utf8 } from "./crypto.ts";
|
|
12
|
+
import { ancestorsOf } from "./pages.ts";
|
|
12
13
|
import { base32 } from "./keys.ts";
|
|
13
14
|
|
|
14
15
|
export { isNestedLabel, PORTHOLE_LABEL_PREFIX } from "../isolation/served.ts";
|
|
@@ -46,13 +47,14 @@ const base64 = (bytes: Uint8Array): string => btoa(String.fromCharCode(...bytes)
|
|
|
46
47
|
/**
|
|
47
48
|
* The shell's CSP (a header): its own script alone runs (by its hash), it frames and fetches
|
|
48
49
|
* nothing but its origin's sealed files (the page, the renewal), and only the host origins frame
|
|
49
|
-
* it. Nothing of the page's runs here: the page is a
|
|
50
|
-
* this (a framed URL's document never does).
|
|
50
|
+
* it (with, above them, a host's `framedBy`, P141). Nothing of the page's runs here: the page is a
|
|
51
|
+
* document of its own, which inherits none of this (a framed URL's document never does).
|
|
51
52
|
*/
|
|
52
53
|
export function nestedShellCsp(
|
|
53
54
|
script: string,
|
|
54
55
|
origin: string,
|
|
55
56
|
hostOrigins: readonly string[],
|
|
57
|
+
framedBy: readonly string[] = [],
|
|
56
58
|
): string {
|
|
57
59
|
const files = `${origin}${NESTED_FILES_PREFIX}`;
|
|
58
60
|
const directives: CspDirective[] = [
|
|
@@ -62,7 +64,7 @@ export function nestedShellCsp(
|
|
|
62
64
|
["connect-src", files],
|
|
63
65
|
["base-uri", "'none'"],
|
|
64
66
|
["form-action", "'none'"],
|
|
65
|
-
["frame-ancestors", ...hostOrigins],
|
|
67
|
+
["frame-ancestors", ...ancestorsOf(hostOrigins, framedBy).split(" ")],
|
|
66
68
|
];
|
|
67
69
|
return serializeCsp(directives);
|
|
68
70
|
}
|
|
@@ -88,7 +90,12 @@ export function nestedShellResponse(
|
|
|
88
90
|
const script = frameShellScript(options);
|
|
89
91
|
const headers = new Headers({
|
|
90
92
|
"content-type": "text/html; charset=utf-8",
|
|
91
|
-
"content-security-policy": nestedShellCsp(
|
|
93
|
+
"content-security-policy": nestedShellCsp(
|
|
94
|
+
script,
|
|
95
|
+
options.origin,
|
|
96
|
+
options.origins,
|
|
97
|
+
options.framedBy,
|
|
98
|
+
),
|
|
92
99
|
"cache-control": "no-store",
|
|
93
100
|
"referrer-policy": "no-referrer",
|
|
94
101
|
"x-content-type-options": "nosniff",
|
|
@@ -107,7 +114,8 @@ export function nestedShellResponse(
|
|
|
107
114
|
|
|
108
115
|
/**
|
|
109
116
|
* Who may frame a nested page and its files' answers: its shell (the shell's own origin, P114) and,
|
|
110
|
-
* above it, the host origins (`frame-ancestors` names every ancestor)
|
|
117
|
+
* above it, the host origins and a host's `framedBy` (`frame-ancestors` names every ancestor; P141):
|
|
118
|
+
* `frameAncestors` is the server's whole list.
|
|
111
119
|
*/
|
|
112
120
|
export const nestedAncestors = (origin: string, frameAncestors: string): string =>
|
|
113
121
|
`${origin} ${frameAncestors}`;
|
package/src/server/pages.ts
CHANGED
|
@@ -1,16 +1,55 @@
|
|
|
1
1
|
import { DOOR_SANDBOX_TOKENS } from "../compile/policy.ts";
|
|
2
|
+
import { framedByProblem } from "../isolation/served.ts";
|
|
2
3
|
import { FRAME_STATUS_METHOD } from "../isolation/types.ts";
|
|
3
4
|
import type { FrameBlock } from "../host/types.ts";
|
|
4
5
|
import { base64url, sha256, utf8 } from "./crypto.ts";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* The server's own pages on a content origin: why it shows nothing of the content, and the page a
|
|
8
|
-
* framed app is entered through. Plain, framable only by the host origins,
|
|
9
|
-
* the page that frames it how loading went
|
|
10
|
-
* the host origins only, so a host can show
|
|
11
|
-
* the host-agnostic mechanism's; a host that
|
|
9
|
+
* framed app is entered through. Plain, framable only by the host origins (and, above them, a
|
|
10
|
+
* host's `framedBy`, P141), never cached. Each tells the page that frames it how loading went
|
|
11
|
+
* (`porthole/notifications/frame-status`, P040), posted to the host origins only, so a host can show
|
|
12
|
+
* its own fallback ("Open in a new tab"). Their words are the host-agnostic mechanism's; a host that
|
|
13
|
+
* wants its own wording serves its own page in front.
|
|
12
14
|
*/
|
|
13
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Whether a page's `frame-ancestors` holds its parent to its host origins: it names no one else.
|
|
18
|
+
* Where it does (a host's `framedBy`, P141), its parent may be an outer page, and the page says
|
|
19
|
+
* `*` only to a parent the engine names as a host origin (`strictParent`, below).
|
|
20
|
+
*/
|
|
21
|
+
const heldToHosts = (frameAncestors: string, hostOrigins: readonly string[]): boolean =>
|
|
22
|
+
frameAncestors
|
|
23
|
+
.split(" ")
|
|
24
|
+
.filter((each) => each !== "")
|
|
25
|
+
.every((each) => hostOrigins.includes(each));
|
|
26
|
+
|
|
27
|
+
/** The attribute that says so, on a page's `<main>`: none where its parent is held to its hosts. */
|
|
28
|
+
const strictParent = (frameAncestors: string, hostOrigins: readonly string[]): string =>
|
|
29
|
+
heldToHosts(frameAncestors, hostOrigins) ? "" : ' data-porthole-strict-parent=""';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Who may frame a page: the host origins, then a host's `framedBy` (P141), each checked (they go
|
|
33
|
+
* into a header).
|
|
34
|
+
*/
|
|
35
|
+
export function ancestorsOf(
|
|
36
|
+
hostOrigins: readonly string[],
|
|
37
|
+
framedBy: readonly string[] = [],
|
|
38
|
+
): string {
|
|
39
|
+
for (const origin of framedBy) {
|
|
40
|
+
const problem = framedByProblem(origin);
|
|
41
|
+
if (problem !== null) {
|
|
42
|
+
throw new TypeError(`framedBy: ${problem}`);
|
|
43
|
+
}
|
|
44
|
+
if (hostOrigins.includes(origin)) {
|
|
45
|
+
throw new TypeError(`framedBy: ${origin} is a host origin already`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [...hostOrigins, ...framedBy.filter((each, at) => framedBy.indexOf(each) === at)].join(
|
|
49
|
+
" ",
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
14
53
|
const escape = (text: string): string =>
|
|
15
54
|
text.replace(/[&<>"']/gu, (char) => `&#${char.charCodeAt(0)};`);
|
|
16
55
|
|
|
@@ -27,17 +66,21 @@ export const SESSION_PATH = "/__porthole/session";
|
|
|
27
66
|
* Tells the page that frames this one how loading went, at each web host origin. A desktop app's
|
|
28
67
|
* own scheme (`ferry://app`) is no target origin a browser takes (postMessage throws), so where
|
|
29
68
|
* the host origins hold one, and the parent isn't known to be a web host origin, the word goes to
|
|
30
|
-
* the parent as `*`: these pages' `frame-ancestors`
|
|
31
|
-
*
|
|
69
|
+
* the parent as `*`: these pages' `frame-ancestors` hold their parent to the host origins, and what
|
|
70
|
+
* they say is no secret (P070). Where it names an outer page too (`framedBy`, P141), the parent may be
|
|
71
|
+
* the outer page: then `*` goes only to a parent the engine names (`location.ancestorOrigins`,
|
|
72
|
+
* not masked as "null") as one of the host origins, so an outer page is never told. One origin
|
|
73
|
+
* failing never stops the page.
|
|
32
74
|
*/
|
|
33
75
|
const say = (): string =>
|
|
34
|
-
`const
|
|
76
|
+
`const strict = main.dataset.portholeStrictParent !== undefined;
|
|
77
|
+
const say = (params) => {
|
|
35
78
|
if (window.parent === window) return;
|
|
36
79
|
const message = { jsonrpc: "2.0", method: ${JSON.stringify(FRAME_STATUS_METHOD)}, params };
|
|
37
80
|
const web = hosts.filter((origin) => origin.startsWith("https://") || origin.startsWith("http://"));
|
|
38
81
|
for (const origin of web) { try { window.parent.postMessage(message, origin); } catch (_) {} }
|
|
39
82
|
const parent = location.ancestorOrigins && location.ancestorOrigins.length > 0 ? location.ancestorOrigins[0] : null;
|
|
40
|
-
if (web.length < hosts.length && (parent === null || !web.includes(parent))) { try { window.parent.postMessage(message, "*"); } catch (_) {} }
|
|
83
|
+
if (web.length < hosts.length && (parent === null || !web.includes(parent)) && (!strict || (parent !== null && hosts.includes(parent)))) { try { window.parent.postMessage(message, "*"); } catch (_) {} }
|
|
41
84
|
};`;
|
|
42
85
|
|
|
43
86
|
/** Tells the host the page is blocked, and why (from the page's data attributes). */
|
|
@@ -123,7 +166,7 @@ export function statusPage(
|
|
|
123
166
|
hostOrigins: readonly string[] = [],
|
|
124
167
|
code?: string,
|
|
125
168
|
): Response {
|
|
126
|
-
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}"${code === undefined ? "" : ` data-porthole-code="${escape(code)}"`} data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"><h1>${escape(title)}</h1><p>${escape(detail)}</p></main><script src="${STATUS_SCRIPT_PATH}"></script></body></html>`;
|
|
169
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}"${code === undefined ? "" : ` data-porthole-code="${escape(code)}"`} data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"${strictParent(frameAncestors, hostOrigins)}><h1>${escape(title)}</h1><p>${escape(detail)}</p></main><script src="${STATUS_SCRIPT_PATH}"></script></body></html>`;
|
|
127
170
|
return new Response(method === "HEAD" ? null : body, {
|
|
128
171
|
status,
|
|
129
172
|
headers: pageHeaders(frameAncestors, false),
|
|
@@ -137,7 +180,7 @@ export function enterPage(
|
|
|
137
180
|
hostOrigins: readonly string[],
|
|
138
181
|
cookie: string,
|
|
139
182
|
): Response {
|
|
140
|
-
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Opening the app</title><style>${STYLE}</style></head><body><main data-porthole-enter="" data-porthole-target="${escape(target)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"><h1>Opening the app…</h1><p></p></main><script src="${ENTER_SCRIPT_PATH}"></script></body></html>`;
|
|
183
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Opening the app</title><style>${STYLE}</style></head><body><main data-porthole-enter="" data-porthole-target="${escape(target)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"${strictParent(frameAncestors, hostOrigins)}><h1>Opening the app…</h1><p></p></main><script src="${ENTER_SCRIPT_PATH}"></script></body></html>`;
|
|
141
184
|
const headers = new Headers(pageHeaders(frameAncestors, true));
|
|
142
185
|
headers.set("set-cookie", cookie);
|
|
143
186
|
return new Response(body, { status: 200, headers });
|
|
@@ -173,7 +216,7 @@ export function appStatusPage(
|
|
|
173
216
|
link === undefined
|
|
174
217
|
? ""
|
|
175
218
|
: `<p><a href="${escape(link.href)}" target="_top" rel="noopener">${escape(link.text)}</a></p>`;
|
|
176
|
-
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}a{color:inherit}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"><h1>${escape(title)}</h1><p>${escape(detail)}</p>${more}</main><script>${STATUS_SCRIPT}</script></body></html>`;
|
|
219
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${STYLE}a{color:inherit}</style></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}" data-porthole-hosts="${escape(JSON.stringify(hostOrigins))}"${strictParent(frameAncestors, hostOrigins)}><h1>${escape(title)}</h1><p>${escape(detail)}</p>${more}</main><script>${STATUS_SCRIPT}</script></body></html>`;
|
|
177
220
|
return new Response(method === "HEAD" ? null : body, {
|
|
178
221
|
status,
|
|
179
222
|
headers: {
|
|
@@ -198,7 +241,12 @@ export function statusPageOf(options: {
|
|
|
198
241
|
readonly detail: string;
|
|
199
242
|
readonly reason?: FrameBlock;
|
|
200
243
|
readonly hostOrigins: readonly string[];
|
|
201
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* Origins of an outer page that may be an ancestor above a host origin's page (P141): added to its
|
|
246
|
+
* `frame-ancestors` after the host origins, never told anything. Default none.
|
|
247
|
+
*/
|
|
248
|
+
readonly framedBy?: readonly string[];
|
|
249
|
+
/** Who may frame it (`frame-ancestors`): default, the host origins, then `framedBy`. */
|
|
202
250
|
readonly frameAncestors?: string;
|
|
203
251
|
readonly link?: { readonly href: string; readonly text: string };
|
|
204
252
|
readonly method?: string;
|
|
@@ -207,7 +255,7 @@ export function statusPageOf(options: {
|
|
|
207
255
|
options.status,
|
|
208
256
|
options.title,
|
|
209
257
|
options.detail,
|
|
210
|
-
options.frameAncestors ?? options.hostOrigins.
|
|
258
|
+
options.frameAncestors ?? ancestorsOf(options.hostOrigins, options.framedBy),
|
|
211
259
|
options.reason ?? "error",
|
|
212
260
|
options.hostOrigins,
|
|
213
261
|
options.link,
|
|
@@ -242,9 +290,13 @@ const doorHeaders = (script: string, frameAncestors: string): Headers =>
|
|
|
242
290
|
"x-robots-tag": "noindex, nofollow",
|
|
243
291
|
});
|
|
244
292
|
|
|
245
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* What a door is given: the host origins it tells, and who may frame it (default, those and then
|
|
295
|
+
* `framedBy`, P141: an outer page's origins above a host origin's page, never told anything).
|
|
296
|
+
*/
|
|
246
297
|
export interface DoorOptions {
|
|
247
298
|
readonly hostOrigins: readonly string[];
|
|
299
|
+
readonly framedBy?: readonly string[];
|
|
248
300
|
readonly frameAncestors?: string;
|
|
249
301
|
readonly method?: string;
|
|
250
302
|
}
|
|
@@ -257,10 +309,11 @@ export interface DoorOptions {
|
|
|
257
309
|
*/
|
|
258
310
|
export function doorResponse(options: DoorOptions): Response {
|
|
259
311
|
const hosts = escape(JSON.stringify(options.hostOrigins));
|
|
260
|
-
const
|
|
312
|
+
const ancestors = options.frameAncestors ?? ancestorsOf(options.hostOrigins, options.framedBy);
|
|
313
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Opening</title></head><body><main data-porthole-door="" data-porthole-hosts="${hosts}"${strictParent(ancestors, options.hostOrigins)}></main><script>${DOOR_SCRIPT}</script></body></html>`;
|
|
261
314
|
return new Response(options.method?.toUpperCase() === "HEAD" ? null : body, {
|
|
262
315
|
status: 200,
|
|
263
|
-
headers: doorHeaders(hashOfDoor(),
|
|
316
|
+
headers: doorHeaders(hashOfDoor(), ancestors),
|
|
264
317
|
});
|
|
265
318
|
}
|
|
266
319
|
|
|
@@ -279,10 +332,11 @@ export function doorStatusResponse(
|
|
|
279
332
|
): Response {
|
|
280
333
|
const { status, reason, code } = options;
|
|
281
334
|
const hosts = escape(JSON.stringify(options.hostOrigins));
|
|
282
|
-
const
|
|
335
|
+
const ancestors = options.frameAncestors ?? ancestorsOf(options.hostOrigins, options.framedBy);
|
|
336
|
+
const body = `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Not shown</title></head><body><main data-porthole-status="${status}" data-porthole-reason="${escape(reason)}"${code === undefined ? "" : ` data-porthole-code="${escape(code)}"`} data-porthole-hosts="${hosts}"${strictParent(ancestors, options.hostOrigins)}></main><script>${STATUS_SCRIPT}</script></body></html>`;
|
|
283
337
|
return new Response(options.method?.toUpperCase() === "HEAD" ? null : body, {
|
|
284
338
|
status,
|
|
285
|
-
headers: doorHeaders(hashOfStatus(),
|
|
339
|
+
headers: doorHeaders(hashOfStatus(), ancestors),
|
|
286
340
|
});
|
|
287
341
|
}
|
|
288
342
|
|
package/src/server/server.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { compile, type CompiledConfig } from "../compile/compile.ts";
|
|
2
2
|
import type { DisplayMode, EgressConfig } from "../config/schema.ts";
|
|
3
3
|
import {
|
|
4
|
+
framedByProblem,
|
|
4
5
|
hostOriginProblem,
|
|
5
6
|
maybeSameSite,
|
|
6
7
|
originMatchesSource,
|
|
@@ -438,7 +439,36 @@ export function createServer(options: ServerOptions): PortholeServer {
|
|
|
438
439
|
);
|
|
439
440
|
}
|
|
440
441
|
}
|
|
441
|
-
|
|
442
|
+
// An outer page's origins (P141): ancestors above a host origin's page, in `frame-ancestors` alone.
|
|
443
|
+
const framedBy: string[] = [];
|
|
444
|
+
for (const origin of options.framedBy ?? []) {
|
|
445
|
+
const problem = framedByProblem(origin);
|
|
446
|
+
if (problem !== null) {
|
|
447
|
+
throw new TypeError(`framedBy: ${problem}`);
|
|
448
|
+
}
|
|
449
|
+
if (options.hostOrigins.includes(origin)) {
|
|
450
|
+
throw new TypeError(
|
|
451
|
+
`framedBy: ${origin} is a host origin already: framedBy names an ancestor that never talks to a frame`,
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
const parsed = parseOrigin(origin);
|
|
455
|
+
if (
|
|
456
|
+
parsed === null ||
|
|
457
|
+
parsed.host === domain ||
|
|
458
|
+
parsed.host.endsWith(`.${domain}`) ||
|
|
459
|
+
maybeSameSite(parsed.host, sampleHost)
|
|
460
|
+
) {
|
|
461
|
+
throw new TypeError(
|
|
462
|
+
`framedBy: ${origin} may be the same site as the content domain ${domain}: serve content from a registrable domain the host uses for nothing else`,
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
if (!framedBy.includes(origin)) {
|
|
466
|
+
framedBy.push(origin);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// Who may be an ancestor of a frame served here: the host origins, then the outer pages' (P141).
|
|
470
|
+
// Every frame's `frame-ancestors` is this; whom a frame hears and tells is `hostOrigins` alone.
|
|
471
|
+
const frameAncestors = [...options.hostOrigins, ...framedBy].join(" ");
|
|
442
472
|
let authorizeUrl: URL | null = null;
|
|
443
473
|
if (options.entry !== undefined) {
|
|
444
474
|
try {
|
|
@@ -1290,6 +1320,7 @@ export function createServer(options: ServerOptions): PortholeServer {
|
|
|
1290
1320
|
const shell = nestedShellResponse(served.compiled, {
|
|
1291
1321
|
origin: access.origin,
|
|
1292
1322
|
origins: options.hostOrigins,
|
|
1323
|
+
framedBy,
|
|
1293
1324
|
page: `${access.origin}${sealed.base}${rest}`,
|
|
1294
1325
|
renew: { url: `${access.origin}${sealed.base}__porthole/renew`, expires: sealed.expires },
|
|
1295
1326
|
method,
|
package/src/server/types.ts
CHANGED
|
@@ -273,6 +273,14 @@ export interface ServerOptions {
|
|
|
273
273
|
readonly secret: Uint8Array;
|
|
274
274
|
/** The host origins that may embed content (`frame-ancestors`) and talk to a served shell. */
|
|
275
275
|
readonly hostOrigins: readonly string[];
|
|
276
|
+
/**
|
|
277
|
+
* Further origins that may be an ancestor of every frame served here, above a host origin's
|
|
278
|
+
* page (P141): an outer page that frames the host's app. Added to each `frame-ancestors` after
|
|
279
|
+
* the host origins, and nowhere else: never an origin a shell, a door or a page takes a message
|
|
280
|
+
* from or says anything to, never a host origin for `entry` or the handoff. Exact https origins
|
|
281
|
+
* (`http://` on loopback), none a host origin, none the content domain's site. Default none.
|
|
282
|
+
*/
|
|
283
|
+
readonly framedBy?: readonly string[];
|
|
276
284
|
/**
|
|
277
285
|
* The configs a served shell or page is served under, by the name a `ServedDocument` gives
|
|
278
286
|
* (an artifact defaults to `artifact`, the MCP Apps sandbox proxy to `mcpApp`).
|
package/src/shell/frame.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PAGE_SANDBOX_TOKENS } from "../compile/policy.ts";
|
|
2
|
-
import { hostOriginProblem, onNestedLabel } from "../isolation/served.ts";
|
|
2
|
+
import { framedByProblem, hostOriginProblem, onNestedLabel } from "../isolation/served.ts";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Porthole's shell for a nested page (P111): the whole document at the address the host frames,
|
|
@@ -81,7 +81,9 @@ export const FRAME_SHELL_RUNTIME = String.raw`(() => {
|
|
|
81
81
|
const web = plan.origins.filter((origin) => origin.indexOf("https://") === 0 || origin.indexOf("http://") === 0);
|
|
82
82
|
// To the host: each web host origin (only the parent's is delivered); a desktop app's own scheme
|
|
83
83
|
// is no target a browser takes, so where one is listed and the parent isn't a known web origin,
|
|
84
|
-
// "*" (frame-ancestors holds the parent to the host origins; nothing said here is secret).
|
|
84
|
+
// "*" (frame-ancestors holds the parent to the host origins; nothing said here is secret). Where
|
|
85
|
+
// it names an outer page above them too (the host's framedBy, P141: plan.strictParent), the parent
|
|
86
|
+
// may be the outer page: "*" then goes only to a parent the engine names as a host origin.
|
|
85
87
|
const toHost = (message) => {
|
|
86
88
|
if (!framed) {
|
|
87
89
|
return;
|
|
@@ -92,7 +94,11 @@ export const FRAME_SHELL_RUNTIME = String.raw`(() => {
|
|
|
92
94
|
} catch (_) {}
|
|
93
95
|
}
|
|
94
96
|
const parent = location.ancestorOrigins && location.ancestorOrigins.length > 0 ? location.ancestorOrigins[0] : null;
|
|
95
|
-
if (
|
|
97
|
+
if (
|
|
98
|
+
web.length < plan.origins.length &&
|
|
99
|
+
(parent === null || web.indexOf(parent) === -1) &&
|
|
100
|
+
(plan.strictParent !== true || (parent !== null && plan.origins.indexOf(parent) !== -1))
|
|
101
|
+
) {
|
|
96
102
|
try {
|
|
97
103
|
window.parent.postMessage(message, "*");
|
|
98
104
|
} catch (_) {}
|
|
@@ -264,6 +270,12 @@ export { SHELL_METHOD_PREFIX, SHELL_STATE_METHOD } from "../isolation/types.ts";
|
|
|
264
270
|
export interface FrameShellOptions {
|
|
265
271
|
/** The host origins: the shell takes messages from its parent only from these. */
|
|
266
272
|
readonly origins: readonly string[];
|
|
273
|
+
/**
|
|
274
|
+
* Origins of an outer page that may be an ancestor above a host origin's page (P141): in the
|
|
275
|
+
* shell's `frame-ancestors` after `origins` (`nestedShellResponse`), never heard or told. Where
|
|
276
|
+
* there are any, the shell says `*` only to a parent the engine names as a host origin.
|
|
277
|
+
*/
|
|
278
|
+
readonly framedBy?: readonly string[];
|
|
267
279
|
/** The page's address: absolute, on the shell's own origin, under `/__porthole/f/`. */
|
|
268
280
|
readonly page: string;
|
|
269
281
|
/** The page frame's accessible name. */
|
|
@@ -287,6 +299,12 @@ export function frameShellScript(options: FrameShellOptions): string {
|
|
|
287
299
|
throw new TypeError(`frameShellScript: ${problem}`);
|
|
288
300
|
}
|
|
289
301
|
}
|
|
302
|
+
for (const origin of options.framedBy ?? []) {
|
|
303
|
+
const problem = framedByProblem(origin);
|
|
304
|
+
if (problem !== null || options.origins.includes(origin)) {
|
|
305
|
+
throw new TypeError(`frameShellScript: framedBy: ${problem ?? `${origin} is a host origin`}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
290
308
|
let page: URL;
|
|
291
309
|
try {
|
|
292
310
|
page = new URL(options.page);
|
|
@@ -305,6 +323,7 @@ export function frameShellScript(options: FrameShellOptions): string {
|
|
|
305
323
|
return FRAME_SHELL_RUNTIME.replace("__PLAN__", () =>
|
|
306
324
|
scriptJson({
|
|
307
325
|
origins: options.origins,
|
|
326
|
+
...((options.framedBy ?? []).length === 0 ? {} : { strictParent: true }),
|
|
308
327
|
page: page.href,
|
|
309
328
|
sandbox: PAGE_SANDBOX_TOKENS.join(" "),
|
|
310
329
|
...(options.title === undefined ? {} : { title: options.title }),
|