@botiverse/porthole 0.15.2 → 0.16.0
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 +89 -0
- package/dist/bridge/bridge.d.ts +1 -8
- package/dist/bridge/bridge.js +0 -7
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +1 -1
- package/dist/compile/policy.d.ts +0 -7
- package/dist/compile/policy.js +1 -10
- package/dist/config/capabilities.d.ts +8 -14
- package/dist/config/capabilities.js +4 -5
- package/dist/config/schema.d.ts +2 -13
- package/dist/config/validate.js +0 -24
- package/dist/conformance/behavior.js +26 -37
- package/dist/conformance/clipboard.js +47 -1
- package/dist/conformance/harness-source.js +1 -1
- package/dist/displays/displays.js +1 -3
- package/dist/guide/limits.js +1 -1
- package/dist/guide/runtime.js +1 -1
- package/dist/host/create-host.d.ts +1 -1
- package/dist/host/create-host.js +6 -51
- package/dist/host/door.d.ts +1 -1
- package/dist/host/locate.d.ts +1 -1
- package/dist/host/locate.js +2 -2
- package/dist/host/outcome.d.ts +5 -12
- package/dist/host/outcome.js +8 -16
- package/dist/host/types.d.ts +6 -22
- package/dist/index.d.ts +2 -4
- package/dist/index.js +2 -4
- package/dist/isolation/served.d.ts +9 -14
- package/dist/isolation/served.js +17 -31
- package/dist/isolation/types.d.ts +2 -19
- package/dist/isolation/types.js +0 -17
- package/dist/platform/focus-field.d.ts +11 -0
- package/dist/platform/focus-field.js +18 -0
- package/dist/platform/types.d.ts +6 -22
- package/dist/platform/web.js +8 -98
- package/dist/presets/presets.d.ts +0 -2
- package/dist/presets/presets.js +0 -1
- package/dist/react/frame.d.ts +0 -8
- package/dist/react/frame.js +0 -4
- package/dist/runtime/contract.d.ts +2 -2
- package/dist/runtime/contract.js +2 -2
- package/dist/runtime/types.generated.js +6 -6
- package/dist/server/files.js +7 -23
- package/dist/server/host.d.ts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +4 -6
- package/dist/server/naming.js +1 -1
- package/dist/server/pages.d.ts +9 -2
- package/dist/server/pages.js +28 -8
- package/dist/server/server.js +28 -166
- package/dist/server/types.d.ts +7 -7
- package/dist/shell/plan.js +2 -2
- package/dist/shell/runtime.js +1 -9
- package/docs/ADOPTING.md +42 -135
- package/docs/ARCHITECTURE.md +0 -33
- package/docs/DECISIONS.md +296 -9
- package/docs/DESIGN.md +27 -50
- package/docs/THREAT_MODEL.md +140 -242
- package/package.json +1 -1
- package/src/bridge/bridge.ts +1 -17
- package/src/check/page.ts +1 -1
- package/src/compile/policy.ts +1 -11
- package/src/config/capabilities.ts +8 -14
- package/src/config/schema.ts +2 -13
- package/src/config/validate.ts +0 -28
- package/src/conformance/behavior.ts +50 -52
- package/src/conformance/clipboard.ts +56 -1
- package/src/displays/displays.ts +1 -3
- package/src/guide/limits.ts +1 -1
- package/src/guide/runtime.ts +1 -1
- package/src/host/create-host.ts +6 -52
- package/src/host/door.ts +1 -1
- package/src/host/locate.ts +2 -2
- package/src/host/outcome.ts +8 -21
- package/src/host/types.ts +6 -20
- package/src/index.ts +2 -4
- package/src/isolation/served.ts +18 -37
- package/src/isolation/types.ts +2 -24
- package/src/platform/focus-field.ts +18 -0
- package/src/platform/types.ts +6 -21
- package/src/platform/web.ts +8 -116
- package/src/presets/presets.ts +0 -3
- package/src/react/frame.tsx +0 -10
- package/src/runtime/contract.ts +4 -4
- package/src/runtime/types.generated.ts +6 -6
- package/src/server/files.ts +4 -19
- package/src/server/host.ts +1 -1
- package/src/server/index.ts +4 -16
- package/src/server/naming.ts +1 -1
- package/src/server/pages.ts +38 -12
- package/src/server/server.ts +29 -189
- package/src/server/types.ts +7 -7
- package/src/shell/plan.ts +2 -2
- package/src/shell/runtime.ts +1 -9
- package/types/runtime/v1/artifact.d.ts +2 -3
- package/types/runtime/v1/assets.d.ts +1 -1
- package/types/runtime/v1/chat.d.ts +2 -2
- package/types/runtime/v1/comments.d.ts +1 -1
- package/types/runtime/v1/downloads.d.ts +2 -2
- package/types/runtime/v1/links.d.ts +2 -2
- package/dist/platform/focus-guard.d.ts +0 -252
- package/dist/platform/focus-guard.js +0 -764
- package/dist/server/nested.d.ts +0 -66
- package/dist/server/nested.js +0 -120
- package/dist/shell/frame.d.ts +0 -28
- package/dist/shell/frame.js +0 -338
- package/src/platform/focus-guard.ts +0 -999
- package/src/server/nested.ts +0 -156
- package/src/shell/frame.ts +0 -371
package/dist/server/server.js
CHANGED
|
@@ -7,8 +7,8 @@ import { randomBytes } from "./crypto.js";
|
|
|
7
7
|
import { isHostLabel, reservedLabels } from "./naming.js";
|
|
8
8
|
import { doorResponse, doorStatusResponse, enterPage, pageScript, SESSION_PATH, statusPage, tabOnlyPage, } from "./pages.js";
|
|
9
9
|
import { libraryFile } from "./libraries.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { ownLoad, serveAsset, serveFile, ticketPage } from "./files.js";
|
|
11
|
+
import { PORTHOLE_LABEL_PREFIX } from "../isolation/served.js";
|
|
12
12
|
import { DEFAULT_ENTRY } from "../files/paths.js";
|
|
13
13
|
import { isPagePath } from "../files/types.js";
|
|
14
14
|
import { isPortholeCookie, setsPortholeCookie } from "./proxy.js";
|
|
@@ -47,10 +47,8 @@ const BASE = /^\/(?:(?!\.{1,2}\/)[A-Za-z0-9._:~-]{1,200}\/){0,16}$/u;
|
|
|
47
47
|
const ENTER_PATH = "/__porthole/enter";
|
|
48
48
|
/** Where a redirect entry's code is redeemed, before its clean address (P068). */
|
|
49
49
|
const ENTRY_PATH = "/__porthole/entry";
|
|
50
|
-
/** How long a nested page's ticket from its clean address to its shell's label lasts (P114). */
|
|
51
|
-
const HOP_SECONDS = 60;
|
|
52
50
|
/**
|
|
53
|
-
* A path below a file set's base, as a
|
|
51
|
+
* A path below a file set's base, as a ticket carries it (a page of a set, P125): a relative path of URL path
|
|
54
52
|
* characters, no empty segment but a last one, no dot segment (encoded or not), no query.
|
|
55
53
|
*/
|
|
56
54
|
const isPageRest = (rest) => typeof rest === "string" &&
|
|
@@ -264,29 +262,12 @@ export function createServer(options) {
|
|
|
264
262
|
}
|
|
265
263
|
return label;
|
|
266
264
|
};
|
|
267
|
-
/**
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
* Every other display of the scope runs agent-made content on the scope's origin with
|
|
271
|
-
* `allow-same-origin`: on that origin, the shell's realm (its word to the host, the page's
|
|
272
|
-
* sealed address) would be theirs.
|
|
273
|
-
*/
|
|
274
|
-
const labelFor = (instance) => {
|
|
275
|
-
const label = nameOf(instance.scope);
|
|
276
|
-
if (instance.document.kind !== "artifact" || compiledFor(instance)?.config.nested !== true) {
|
|
277
|
-
return label;
|
|
278
|
-
}
|
|
279
|
-
const own = nestedLabelOf(label);
|
|
280
|
-
if (isReserved(own)) {
|
|
281
|
-
throw new TypeError(`content.reserved holds ${own}, a nested page's shell's label: reserve no ${PORTHOLE_LABEL_PREFIX} label`);
|
|
282
|
-
}
|
|
283
|
-
return own;
|
|
284
|
-
};
|
|
285
|
-
/** Whether a request's label may be one this server named (a nested page's shell's, P114). */
|
|
265
|
+
/** The label an instance is served on: its scope's. */
|
|
266
|
+
const labelFor = (instance) => nameOf(instance.scope);
|
|
267
|
+
/** Whether a request's label may be one this server named: never one of Porthole's own. */
|
|
286
268
|
const ours = (label) => !isReserved(label) &&
|
|
287
|
-
(
|
|
288
|
-
|
|
289
|
-
(content.name === undefined ? LABEL.test(label) : isHostLabel(label))));
|
|
269
|
+
!label.startsWith(PORTHOLE_LABEL_PREFIX) &&
|
|
270
|
+
(content.name === undefined ? LABEL.test(label) : isHostLabel(label));
|
|
290
271
|
const secure = content.scheme === "https";
|
|
291
272
|
const defaultPort = secure ? 443 : 80;
|
|
292
273
|
const portPart = content.port === undefined || content.port === defaultPort ? "" : `:${content.port}`;
|
|
@@ -294,7 +275,6 @@ export function createServer(options) {
|
|
|
294
275
|
const contentSource = `${content.scheme}://*.${domain}${portPart}`;
|
|
295
276
|
const sampleHost = `${keys.label("")}.${domain}`;
|
|
296
277
|
const sampleOrigin = originOfLabel(keys.label(""));
|
|
297
|
-
const sampleNestedOrigin = originOfLabel(nestedLabelOf(keys.label("")));
|
|
298
278
|
const authorize = options.authorize;
|
|
299
279
|
const authorizeTtl = authorize?.ttlSeconds ?? 0;
|
|
300
280
|
if (!Number.isInteger(authorizeTtl) || authorizeTtl < 0 || authorizeTtl > 300) {
|
|
@@ -448,9 +428,7 @@ export function createServer(options) {
|
|
|
448
428
|
if (config.isolation !== "domain" || !MODES[kind].includes(config.mode)) {
|
|
449
429
|
throw new TypeError(`The config ${JSON.stringify(name)} (${config.mode}, ${config.isolation}) can't serve a ${kind}: it needs ${MODES[kind].join(" or ")} mode with domain isolation`);
|
|
450
430
|
}
|
|
451
|
-
|
|
452
|
-
const samples = config.nested === true ? [sampleOrigin, sampleNestedOrigin] : [sampleOrigin];
|
|
453
|
-
if (!samples.every((sample) => config.contentOrigins.some((source) => originMatchesSource(sample, source)))) {
|
|
431
|
+
if (!config.contentOrigins.some((source) => originMatchesSource(sampleOrigin, source))) {
|
|
454
432
|
throw new TypeError(`The config ${JSON.stringify(name)}'s contentOrigins don't include this server's (${contentSource})`);
|
|
455
433
|
}
|
|
456
434
|
return each;
|
|
@@ -523,7 +501,6 @@ export function createServer(options) {
|
|
|
523
501
|
}
|
|
524
502
|
return {
|
|
525
503
|
html: config.shellDocument({ origins, document: stored.html, cspMeta: false }),
|
|
526
|
-
document: stored.html,
|
|
527
504
|
compiled: config,
|
|
528
505
|
assets: true,
|
|
529
506
|
};
|
|
@@ -752,8 +729,8 @@ export function createServer(options) {
|
|
|
752
729
|
return best;
|
|
753
730
|
}
|
|
754
731
|
/**
|
|
755
|
-
* A taken ticket, if it is good for `label`'s origin: its instance's own
|
|
756
|
-
*
|
|
732
|
+
* A taken ticket, if it is good for `label`'s origin: its instance's own, or for an entry code
|
|
733
|
+
* (`entry`) its scope's, where a clean address is.
|
|
757
734
|
*/
|
|
758
735
|
async function take(ticket, label, entry = false) {
|
|
759
736
|
if (ticket === null || ticket.length === 0 || ticket.length > 128) {
|
|
@@ -893,17 +870,14 @@ export function createServer(options) {
|
|
|
893
870
|
if (await sealedEmbed(label, token)) {
|
|
894
871
|
return page(401, "This has ended", "Content here opens for a while. Open it again from the page that showed it.", method, "session", undefined, true);
|
|
895
872
|
}
|
|
896
|
-
|
|
897
|
-
// config without nesting never frames this address but at the host.
|
|
898
|
-
return statusPage(401, "This has ended", "Content here opens for a while. Open it again from the app that showed it.", nestedAncestors(origin, frameAncestors), method, "session", [...options.hostOrigins, origin]);
|
|
873
|
+
return statusPage(401, "This has ended", "Content here opens for a while. Open it again from the app that showed it.", frameAncestors, method, "session", options.hostOrigins);
|
|
899
874
|
}
|
|
900
875
|
// An asset of this artifact's library, at the frame's own sealed address (P091): every engine
|
|
901
876
|
// sends a frame's path, where some send no Referer that names it.
|
|
902
877
|
const blob = SEALED_ASSET.exec(rest)?.[1];
|
|
903
878
|
if (blob !== undefined) {
|
|
904
|
-
// A nested page loads no assets (its config refuses them): none on its shell's label (P114).
|
|
905
879
|
const none = () => page(404, "Not found", "This address names no content.", method, undefined, undefined, access.embed === true);
|
|
906
|
-
if (options.assets === undefined
|
|
880
|
+
if (options.assets === undefined) {
|
|
907
881
|
return none();
|
|
908
882
|
}
|
|
909
883
|
return (await assetFor(request, label, access, blob)) ?? none();
|
|
@@ -972,7 +946,7 @@ export function createServer(options) {
|
|
|
972
946
|
if (access === null) {
|
|
973
947
|
return page(401, "This link has been used", "Content here opens once per link. Open it again from the app that showed it.", method, "session");
|
|
974
948
|
}
|
|
975
|
-
//
|
|
949
|
+
// The page below its base the ticket was issued for (a page of a set, P125).
|
|
976
950
|
const asked = cookie === null ? undefined : record?.page;
|
|
977
951
|
const rest = isPageRest(asked) ? asked : undefined;
|
|
978
952
|
return serveAccess(request, access, cookie, undefined, rest);
|
|
@@ -989,8 +963,7 @@ export function createServer(options) {
|
|
|
989
963
|
/**
|
|
990
964
|
* A served display's door (P125): its own ticket's, taken once, for this instance on this
|
|
991
965
|
* origin; then the door's answer for that ticket's grant (`answerDoor`, the one `doorAnswer`
|
|
992
|
-
* gives, P126). No other ticket opens it
|
|
993
|
-
* (`serveShellLabel`).
|
|
966
|
+
* gives, P126). No other ticket opens it.
|
|
994
967
|
*/
|
|
995
968
|
async function serveDoor(request, url, label, key) {
|
|
996
969
|
const method = request.method.toUpperCase();
|
|
@@ -1005,8 +978,7 @@ export function createServer(options) {
|
|
|
1005
978
|
record.embed === true ||
|
|
1006
979
|
record.entry !== undefined ||
|
|
1007
980
|
record.instance.document.kind === "external" ||
|
|
1008
|
-
keys.instanceKey(record.instance) !== key
|
|
1009
|
-
compiledFor(record.instance)?.config.nested === true) {
|
|
981
|
+
keys.instanceKey(record.instance) !== key) {
|
|
1010
982
|
return doorSays(401, "session", method);
|
|
1011
983
|
}
|
|
1012
984
|
}
|
|
@@ -1061,7 +1033,7 @@ export function createServer(options) {
|
|
|
1061
1033
|
* (`at`) a path under a file set's base (P081).
|
|
1062
1034
|
*/
|
|
1063
1035
|
async function serveAccess(request, access, cookie, at,
|
|
1064
|
-
/**
|
|
1036
|
+
/** The page below its files' base its ticket was issued for (a page of a set, P125). */
|
|
1065
1037
|
pageAt) {
|
|
1066
1038
|
const method = request.method.toUpperCase();
|
|
1067
1039
|
const refusal = await denied(request, access);
|
|
@@ -1087,55 +1059,8 @@ export function createServer(options) {
|
|
|
1087
1059
|
("files" in served ? ticketPage(served.files, pageAt) === null : pageAt !== undefined)) {
|
|
1088
1060
|
return missing();
|
|
1089
1061
|
}
|
|
1090
|
-
//
|
|
1091
|
-
|
|
1092
|
-
// that address, below the sealed prefix, answers the page and its files, without a cookie.
|
|
1093
|
-
const nested = served.compiled.config.nested === true;
|
|
1094
|
-
const sealedAt = at !== undefined && at.base.startsWith(FILES_PREFIX);
|
|
1095
|
-
if (nested && !sealedAt) {
|
|
1096
|
-
if (!isNavigation(request)) {
|
|
1097
|
-
return page(404, "Not found", "This page's files are at its own address.", method);
|
|
1098
|
-
}
|
|
1099
|
-
// Its shell is served on its own label alone (P114): a clean address, entered on the scope's
|
|
1100
|
-
// label (P068), goes there with a one-time ticket of its own, for what is left of its session.
|
|
1101
|
-
const own = originOfLabel(labelFor(access.instance));
|
|
1102
|
-
if (access.origin !== own) {
|
|
1103
|
-
return hop(access, own, "files" in served && at !== undefined ? at.rest : "");
|
|
1104
|
-
}
|
|
1105
|
-
const sealed = await sealFiles(access);
|
|
1106
|
-
let rest = "";
|
|
1107
|
-
if ("files" in served) {
|
|
1108
|
-
const entry = served.files.entry ?? DEFAULT_ENTRY;
|
|
1109
|
-
rest =
|
|
1110
|
-
pageAt !== undefined
|
|
1111
|
-
? pageAt
|
|
1112
|
-
: at !== undefined && at.rest !== ""
|
|
1113
|
-
? at.rest
|
|
1114
|
-
: entry.includes("/")
|
|
1115
|
-
? entry
|
|
1116
|
-
.split("/")
|
|
1117
|
-
.map((segment) => encodeURIComponent(segment))
|
|
1118
|
-
.join("/")
|
|
1119
|
-
: "";
|
|
1120
|
-
}
|
|
1121
|
-
const shell = nestedShellResponse(served.compiled, {
|
|
1122
|
-
origin: access.origin,
|
|
1123
|
-
origins: options.hostOrigins,
|
|
1124
|
-
framedBy,
|
|
1125
|
-
page: `${access.origin}${sealed.base}${rest}`,
|
|
1126
|
-
renew: { url: `${access.origin}${sealed.base}__porthole/renew`, expires: sealed.expires },
|
|
1127
|
-
method,
|
|
1128
|
-
});
|
|
1129
|
-
if (cookie !== null) {
|
|
1130
|
-
shell.headers.set("set-cookie", cookie);
|
|
1131
|
-
}
|
|
1132
|
-
return shell;
|
|
1133
|
-
}
|
|
1134
|
-
// Below the sealed prefix, a nested page and its files are framed by its shell too. An embed
|
|
1135
|
-
// session is never nested (`issue`): its answers are framed by any page (P143).
|
|
1136
|
-
const ancestors = nested
|
|
1137
|
-
? nestedAncestors(access.origin, frameAncestors)
|
|
1138
|
-
: ancestorsFor(access);
|
|
1062
|
+
// An embed session's answers are framed by any page (P143).
|
|
1063
|
+
const ancestors = ancestorsFor(access);
|
|
1139
1064
|
// Whom its pages hear and tell: the host origins, or no one for an embed session (P143).
|
|
1140
1065
|
const hostOrigins = embed ? [] : options.hostOrigins;
|
|
1141
1066
|
if ("files" in served) {
|
|
@@ -1189,48 +1114,11 @@ export function createServer(options) {
|
|
|
1189
1114
|
const directives = served.assets
|
|
1190
1115
|
? assetCspDirectives(config, cspDirectives, access.origin)
|
|
1191
1116
|
: cspDirectives;
|
|
1192
|
-
const headers = documentHeaders(
|
|
1117
|
+
const headers = documentHeaders(servedDocumentCsp(config, directives), servedPermissionsPolicy(config), ancestors);
|
|
1193
1118
|
if (cookie !== null) {
|
|
1194
1119
|
headers.set("set-cookie", cookie);
|
|
1195
1120
|
}
|
|
1196
|
-
|
|
1197
|
-
const html = nested
|
|
1198
|
-
? served.compiled.shellDocument({
|
|
1199
|
-
origins: [access.origin],
|
|
1200
|
-
document: served.document ?? "",
|
|
1201
|
-
cspMeta: false,
|
|
1202
|
-
})
|
|
1203
|
-
: served.html;
|
|
1204
|
-
return new Response(method === "HEAD" ? null : html, { status: 200, headers });
|
|
1205
|
-
}
|
|
1206
|
-
/**
|
|
1207
|
-
* A nested page entered at its clean address (P114), whose shell is never served there: on to the
|
|
1208
|
-
* shell's own label, with a one-time ticket for the same access (its viewer, its subject, what is
|
|
1209
|
-
* left of its session) and the path below its base it was entered at. Only this server's own
|
|
1210
|
-
* answer carries the ticket, as `issue`'s frame address does; the host's check already let the
|
|
1211
|
-
* request in.
|
|
1212
|
-
*/
|
|
1213
|
-
async function hop(access, own, rest) {
|
|
1214
|
-
const now = Date.now();
|
|
1215
|
-
const ticket = newTicket();
|
|
1216
|
-
await tickets.put(ticketId(ticket), {
|
|
1217
|
-
instance: access.instance,
|
|
1218
|
-
viewer: access.viewer,
|
|
1219
|
-
expiresAt: now + HOP_SECONDS * 1_000,
|
|
1220
|
-
sessionSeconds: Math.min(MAX_SESSION_SECONDS, Math.max(1, Math.floor((access.expiresAt - now) / 1_000))),
|
|
1221
|
-
...(access.anonymous === true ? { anonymous: true } : {}),
|
|
1222
|
-
...(access.subject === undefined ? {} : { subject: access.subject }),
|
|
1223
|
-
...(isPageRest(rest) ? { page: rest } : {}),
|
|
1224
|
-
});
|
|
1225
|
-
return new Response(null, {
|
|
1226
|
-
status: 303,
|
|
1227
|
-
headers: {
|
|
1228
|
-
location: `${own}${PREFIX}d/${keys.instanceKey(access.instance)}?ticket=${ticket}`,
|
|
1229
|
-
"cache-control": "no-store",
|
|
1230
|
-
"referrer-policy": "no-referrer",
|
|
1231
|
-
"x-robots-tag": "noindex, nofollow",
|
|
1232
|
-
},
|
|
1233
|
-
});
|
|
1121
|
+
return new Response(method === "HEAD" ? null : served.html, { status: 200, headers });
|
|
1234
1122
|
}
|
|
1235
1123
|
/**
|
|
1236
1124
|
* An asset at `/_blob/<id>` (P089, after the review): a request carrying an access to an
|
|
@@ -1619,34 +1507,12 @@ export function createServer(options) {
|
|
|
1619
1507
|
return page(502, "The app didn't answer", "Its server couldn't be reached.", method);
|
|
1620
1508
|
}
|
|
1621
1509
|
}
|
|
1622
|
-
/**
|
|
1623
|
-
* A nested page's shell's own label (P114): Porthole's shell at a frame's address, its page and
|
|
1624
|
-
* that page's files below the sealed prefix, and Porthole's status pages (and their script).
|
|
1625
|
-
* Nothing else: no clean address, entry, asset, library or app, so no agent-made content ever
|
|
1626
|
-
* runs on this origin with it (every file below the prefix carries a sandbox without it).
|
|
1627
|
-
*/
|
|
1628
|
-
async function serveShellLabel(request, url, label) {
|
|
1629
|
-
const method = request.method.toUpperCase();
|
|
1630
|
-
const script = pageScript(url.pathname);
|
|
1631
|
-
if (script !== null) {
|
|
1632
|
-
return script;
|
|
1633
|
-
}
|
|
1634
|
-
const document = DOCUMENT_PATH.exec(url.pathname);
|
|
1635
|
-
if (document?.[1] !== undefined) {
|
|
1636
|
-
return serveDocument(request, url, label, document[1]);
|
|
1637
|
-
}
|
|
1638
|
-
const sealed = FILES_PATH.exec(url.pathname);
|
|
1639
|
-
if (sealed?.[1] !== undefined) {
|
|
1640
|
-
return serveSealed(request, url, label, sealed[1], sealed[2]);
|
|
1641
|
-
}
|
|
1642
|
-
return page(404, "Nothing here", "This address names no content.", method);
|
|
1643
|
-
}
|
|
1644
1510
|
/** A grant, checked for an instance (`issue`'s rules, and `doorAnswer`'s, P126). */
|
|
1645
1511
|
function checkGrant(clean, grant) {
|
|
1646
1512
|
const anonymous = grant.anonymous === true;
|
|
1647
1513
|
// An embedded document (P143): a public page with no host, which any page may frame. Only
|
|
1648
1514
|
// where the host opted in, and only as narrow as that: anonymous, no level, no user, an
|
|
1649
|
-
// artifact's page
|
|
1515
|
+
// artifact's page.
|
|
1650
1516
|
// Read as given: a host's grant is checked here, not trusted to its type.
|
|
1651
1517
|
const asked = grant.embed;
|
|
1652
1518
|
const embed = asked !== undefined;
|
|
@@ -1660,8 +1526,8 @@ export function createServer(options) {
|
|
|
1660
1526
|
if (!anonymous || grant.level !== undefined || grant.user !== undefined) {
|
|
1661
1527
|
throw new TypeError("An embed grant is anonymous, with no viewer, level or user: it has no host to give them to (P143)");
|
|
1662
1528
|
}
|
|
1663
|
-
if (clean.document.kind !== "artifact"
|
|
1664
|
-
throw new TypeError("An embed grant opens an artifact's page
|
|
1529
|
+
if (clean.document.kind !== "artifact") {
|
|
1530
|
+
throw new TypeError("An embed grant opens an artifact's page: never a url-mode app, a served shell or the sandbox proxy (P143)");
|
|
1665
1531
|
}
|
|
1666
1532
|
}
|
|
1667
1533
|
if (anonymous) {
|
|
@@ -1737,11 +1603,11 @@ export function createServer(options) {
|
|
|
1737
1603
|
}
|
|
1738
1604
|
/**
|
|
1739
1605
|
* Whether an instance's frame has a door (P125): a document framed on its scope's origin, where
|
|
1740
|
-
* the scope's other displays run content (a served shell, a page
|
|
1741
|
-
*
|
|
1606
|
+
* the scope's other displays run content (a served shell, a page, the sandbox proxy). A
|
|
1607
|
+
* url-mode app has none.
|
|
1742
1608
|
*/
|
|
1743
1609
|
function hasDoor(instance) {
|
|
1744
|
-
return instance.document.kind !== "external"
|
|
1610
|
+
return instance.document.kind !== "external";
|
|
1745
1611
|
}
|
|
1746
1612
|
const underDomain = (host) => host === domain || host.endsWith(`.${domain}`);
|
|
1747
1613
|
/**
|
|
@@ -1795,7 +1661,6 @@ export function createServer(options) {
|
|
|
1795
1661
|
throw new TypeError("A frame's page is a relative path below an artifact's files (no . or ..)");
|
|
1796
1662
|
}
|
|
1797
1663
|
const { clean, key, ticket, door } = await mint(instance, grant, undefined, below);
|
|
1798
|
-
// A nested page's frame is its shell, on the shell's own label (P114).
|
|
1799
1664
|
const origin = originOfLabel(labelFor(clean));
|
|
1800
1665
|
const path = clean.document.kind === "external"
|
|
1801
1666
|
? `${ENTER_PATH}?ticket=${ticket}`
|
|
@@ -1817,7 +1682,7 @@ export function createServer(options) {
|
|
|
1817
1682
|
const clean = cleanInstance(instance);
|
|
1818
1683
|
check(clean);
|
|
1819
1684
|
if (!hasDoor(clean)) {
|
|
1820
|
-
throw new TypeError("This instance has no door (P125): a
|
|
1685
|
+
throw new TypeError("This instance has no door (P125): a url-mode app has none");
|
|
1821
1686
|
}
|
|
1822
1687
|
const below = at.page;
|
|
1823
1688
|
if (below !== undefined && (!isPageRest(below) || clean.document.kind !== "artifact")) {
|
|
@@ -1943,9 +1808,6 @@ export function createServer(options) {
|
|
|
1943
1808
|
if (!ours(label)) {
|
|
1944
1809
|
return page(404, "Nothing here", "This address names no content.", method);
|
|
1945
1810
|
}
|
|
1946
|
-
if (isNestedLabel(label)) {
|
|
1947
|
-
return await serveShellLabel(request, url, label);
|
|
1948
|
-
}
|
|
1949
1811
|
if (url.pathname === ENTER_PATH) {
|
|
1950
1812
|
return await enter(request, url, label);
|
|
1951
1813
|
}
|
package/dist/server/types.d.ts
CHANGED
|
@@ -78,8 +78,8 @@ export type Grant = ({
|
|
|
78
78
|
/**
|
|
79
79
|
* An embedded document (P143): a public page that any site may frame, with no host. Only where
|
|
80
80
|
* the server opted in (`ServerOptions.embeds`), only with `anonymous: true` and no `level` or
|
|
81
|
-
* `user`, and only for an artifact's page
|
|
82
|
-
*
|
|
81
|
+
* `user`, and only for an artifact's page (never a url-mode app, a served shell or the sandbox
|
|
82
|
+
* proxy); anything else throws at `issue`. Carried signed in the
|
|
83
83
|
* session (and in a frame's sealed files' address), so it is never added to a session or taken
|
|
84
84
|
* from one. Every answer of such a session says `frame-ancestors *` (no other session's changes),
|
|
85
85
|
* its shell's plan names no host (it asks no host, hears none and tells no parent anything; the
|
|
@@ -110,14 +110,14 @@ export interface TicketRecord {
|
|
|
110
110
|
readonly pinned?: boolean;
|
|
111
111
|
};
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
113
|
+
* The page below its files' base the ticket was issued for (a page of a set, P125): the entry
|
|
114
|
+
* page when absent.
|
|
115
115
|
*/
|
|
116
116
|
readonly page?: string;
|
|
117
117
|
/**
|
|
118
118
|
* A door's ticket (P125): `issue` mints one beside the content's, for the same grant and as
|
|
119
|
-
* long, for a display whose frame is on its scope's origin (a served shell, a page
|
|
120
|
-
*
|
|
119
|
+
* long, for a display whose frame is on its scope's origin (a served shell, a page, the sandbox
|
|
120
|
+
* proxy). Taken only at the door (`/__porthole/door/<key>`), never at the
|
|
121
121
|
* content's address; the door takes no other.
|
|
122
122
|
*/
|
|
123
123
|
readonly door?: true;
|
|
@@ -378,7 +378,7 @@ export interface PortholeServer {
|
|
|
378
378
|
* is what `authorize.check` is handed (and gives the method: HEAD has no body, a method other
|
|
379
379
|
* than GET or HEAD is 405); default, a GET of the door on the instance's origin. Throws, as
|
|
380
380
|
* `issue` does, for an instance or grant `issue` would refuse, and for an instance with no door
|
|
381
|
-
* (a
|
|
381
|
+
* (a url-mode app).
|
|
382
382
|
*/
|
|
383
383
|
doorAnswer(instance: InstanceRef, grant: Grant, request?: Request,
|
|
384
384
|
/** The page below a file set's base the frame opens at, as `issue`'s `at` (P125). */
|
package/dist/shell/plan.js
CHANGED
|
@@ -38,8 +38,8 @@ export function shellPlan(config) {
|
|
|
38
38
|
themeVariables: Object.keys(config.theme.variables),
|
|
39
39
|
themeEvent: config.theme.event,
|
|
40
40
|
themeDocuments: config.theme.documents ?? "declared",
|
|
41
|
-
// An opaque origin has no storage
|
|
42
|
-
storage: config.isolation === "opaque"
|
|
41
|
+
// An opaque origin has no storage.
|
|
42
|
+
storage: config.isolation === "opaque" ? "memory" : "native",
|
|
43
43
|
maxErrorReports: config.limits.maxErrorReports,
|
|
44
44
|
maxPromptChars: config.limits.maxPromptChars,
|
|
45
45
|
maxCopyChars: MAX_COPY_CHARS,
|
package/dist/shell/runtime.js
CHANGED
|
@@ -271,8 +271,6 @@ export const SHELL_RUNTIME = String.raw `(() => {
|
|
|
271
271
|
// takes the next load for that page, not for content that left). Anything else stays stopped:
|
|
272
272
|
// another path of the origin, a file that isn't a page, another origin.
|
|
273
273
|
let navigating = (_url) => {};
|
|
274
|
-
// A nested page's files' address renewed by its shell (P111), which the shell's message gives.
|
|
275
|
-
let adoptFiles = (_base) => false;
|
|
276
274
|
let filesBase = plan.files && typeof plan.files.base === "string" ? plan.files.base : null;
|
|
277
275
|
// Every address the page's files had (P083: a sealed one is renewed): what reports say as "./".
|
|
278
276
|
const filesBases = filesBase === null ? [] : [filesBase];
|
|
@@ -1652,7 +1650,7 @@ export const SHELL_RUNTIME = String.raw `(() => {
|
|
|
1652
1650
|
// modules keep the address they loaded from; the server serves their own loads till the session
|
|
1653
1651
|
// ends.
|
|
1654
1652
|
const replace = History.prototype.replaceState;
|
|
1655
|
-
// The files' origin, read from the address itself
|
|
1653
|
+
// The files' origin, read from the address itself.
|
|
1656
1654
|
const filesOrigin = filesBase === null ? null : new NativeURL(filesBase).origin;
|
|
1657
1655
|
// A renewed sealed address (P083): one segment under the same origin's sealed prefix, checked
|
|
1658
1656
|
// through the platform's own functions (content may have replaced a prototype's, and the base
|
|
@@ -1672,7 +1670,6 @@ export const SHELL_RUNTIME = String.raw `(() => {
|
|
|
1672
1670
|
filesBases.push(base);
|
|
1673
1671
|
return true;
|
|
1674
1672
|
};
|
|
1675
|
-
adoptFiles = adopt;
|
|
1676
1673
|
if (filesBase !== null && typeof plan.files.expires === "number") {
|
|
1677
1674
|
const nativeFetch = window.fetch.bind(window);
|
|
1678
1675
|
const renewIn = (expires) => Math.max(30000, expires - Date.now() - 300000);
|
|
@@ -2242,11 +2239,6 @@ export const SHELL_RUNTIME = String.raw `(() => {
|
|
|
2242
2239
|
case "ui/notifications/tool-input":
|
|
2243
2240
|
void render(params.arguments);
|
|
2244
2241
|
break;
|
|
2245
|
-
case "porthole/files-renewed":
|
|
2246
|
-
// From the page's parent only (the listener's check): a nested page's shell renewed its
|
|
2247
|
-
// files' sealed address, which this page can't (its loads aren't its origin's own, P111).
|
|
2248
|
-
adoptFiles(params.base);
|
|
2249
|
-
break;
|
|
2250
2242
|
case "ui/notifications/host-context-changed":
|
|
2251
2243
|
applyTheme(params);
|
|
2252
2244
|
break;
|