castle-web-cli 0.4.243 → 0.4.245
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/dist/api.d.ts +1 -0
- package/dist/api.js +13 -0
- package/dist/contentOriginTiming.d.ts +13 -0
- package/dist/contentOriginTiming.js +15 -0
- package/dist/imports.js +28 -6
- package/dist/index.js +54 -5
- package/dist/init.js +1 -1
- package/dist/projectState.d.ts +33 -0
- package/dist/projectState.js +97 -0
- package/dist/serve.d.ts +18 -0
- package/dist/serve.js +103 -2
- package/dist/serveSecurity.d.ts +105 -3
- package/dist/serveSecurity.js +500 -39
- package/dist/shell/assets/{index-DulbYIJm.js → index-Bec6LpAv.js} +87 -87
- package/dist/shell/index.html +1 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/runtime.js +57 -0
- package/kits/hub-game/code/client/chrome.js +9 -2
- package/kits/hub-game/code/client/hookLayer.js +8 -0
- package/kits/hub-game/code/client/padCues.js +2 -0
- package/kits/hub-game/code/client/padReadability.js +6 -1
- package/kits/hub-game/code/client/signals.js +126 -0
- package/kits/hub-game/code/client/state.js +4 -0
- package/kits/hub-game/code/server/friendBests.js +8 -2
- package/kits/hub-game/code/server/hub.js +31 -4
- package/kits/hub-game/code/server/npcs.js +4 -0
- package/kits/hub-game/code/server/party.js +3 -0
- package/kits/hub-game/code/server/resumePose.js +30 -9
- package/kits/hub-game/code/server/signals.js +124 -0
- package/kits/hub-game/code/server/writerLease.js +161 -17
- package/kits/hub-game/code/systems/hub.js +21 -2
- package/kits/hub-game/docs/contract.md +92 -11
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-menu-client.mjs +7 -6
- package/kits/hub-game/scripts/test-menu-footer-dom.mjs +94 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +6 -3
- package/kits/hub-game/scripts/test-resume-pose.mjs +85 -0
- package/kits/hub-game/scripts/test-signals.mjs +412 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +108 -4
- package/kits/hub-game/scripts/test-writer-lease.mjs +385 -1
- package/package.json +2 -2
package/dist/serveSecurity.d.ts
CHANGED
|
@@ -5,6 +5,28 @@ export type LocalContentPorts = Record<ContentRole, number>;
|
|
|
5
5
|
export declare const SERVE_AUTH_FAILURE_HEADER = "x-castle-serve-auth";
|
|
6
6
|
export declare const SERVE_AUTH_FAILURE_VALUE = "invalid";
|
|
7
7
|
export declare const MOBILE_HOST_PROTOCOL = "2";
|
|
8
|
+
export declare const COMPAT_CONTENT_PARAM = "castleCompat";
|
|
9
|
+
export declare const PROTOCOL2_MARKER_FILE = "protocol2-shell-seen.json";
|
|
10
|
+
export declare const CONTENT_ORIGIN_FILE = "content-origin.json";
|
|
11
|
+
/** What `compatibilityContent` grants: a role, and whether the response must be sandboxed. */
|
|
12
|
+
export interface CompatibilityContent {
|
|
13
|
+
role: ContentRole;
|
|
14
|
+
/**
|
|
15
|
+
* A referrer-less static load: the response must carry
|
|
16
|
+
* `Content-Security-Policy: sandbox` and `X-Content-Type-Options: nosniff`,
|
|
17
|
+
* and must never be Vite's HTML fallback.
|
|
18
|
+
*/
|
|
19
|
+
sandboxed: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A native app WebView, which is all a released Castle app opens the editor in:
|
|
23
|
+
* iOS/iPadOS WKWebView's default user agent has AppleWebKit but no `Safari/`
|
|
24
|
+
* token (every Safari, and every Chromium browser, carries one), and Android
|
|
25
|
+
* System WebView marks itself `; wv)`. Page script cannot change the user agent
|
|
26
|
+
* its browser sends, so deck code in a desktop or mobile browser can never
|
|
27
|
+
* look like this. Exported for the tests.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isNativeWebViewUserAgent(userAgent: string | undefined): boolean;
|
|
8
30
|
export declare function mintContentGrantLabel(grant: {
|
|
9
31
|
role: ContentRole;
|
|
10
32
|
publicPort: number;
|
|
@@ -17,13 +39,52 @@ export declare class ServeSecurity {
|
|
|
17
39
|
readonly serveToken: string;
|
|
18
40
|
private readonly contentProxyToken;
|
|
19
41
|
private readonly signingKey;
|
|
20
|
-
private
|
|
42
|
+
private serveNonce;
|
|
43
|
+
private readonly retiredNonces;
|
|
44
|
+
private projectDir;
|
|
45
|
+
private projectRealpath;
|
|
46
|
+
private projectId;
|
|
21
47
|
private contentGrantExpiresAtSeconds;
|
|
22
48
|
private readonly pathKey;
|
|
49
|
+
private readonly compatContentKey;
|
|
50
|
+
private protocol2ShellSeen;
|
|
23
51
|
private readonly tickets;
|
|
24
52
|
private localContentPorts;
|
|
25
53
|
private localContentHost;
|
|
26
54
|
constructor(publicPort: number, localContentPorts?: LocalContentPorts);
|
|
55
|
+
/**
|
|
56
|
+
* Keep this serve's state in `projectDir` (`.castle/runtime/`, see
|
|
57
|
+
* projectState.ts): the protocol-2 marker and the content-origin record.
|
|
58
|
+
*
|
|
59
|
+
* Content origins stay stable across serves of this project: the record
|
|
60
|
+
* holds a random project id and the current grant expiry, and the nonce in
|
|
61
|
+
* every label is derived from the signing key, that id and the project's
|
|
62
|
+
* real path. The nonce is in the grant MAC input (whose format Ghost also
|
|
63
|
+
* verifies, so it cannot grow a field), so a record copied into another
|
|
64
|
+
* project -- or another project later served on the same port -- yields a
|
|
65
|
+
* different nonce and never verifies this project's labels. A missing or
|
|
66
|
+
* malformed record is absent (the first mint writes a fresh one); deck code
|
|
67
|
+
* that rewrites it only moves its own project's origins.
|
|
68
|
+
*
|
|
69
|
+
* Files an earlier build kept directly in `.castle/` (which cloud checkpoint
|
|
70
|
+
* capture rejects) are migrated: the marker moves, a v1 record is dropped.
|
|
71
|
+
*/
|
|
72
|
+
useProjectState(projectDir: string): void;
|
|
73
|
+
private adoptProjectId;
|
|
74
|
+
/** The state file `name`, if its directory is safe (created on demand), else null. */
|
|
75
|
+
private stateFile;
|
|
76
|
+
private migrateLegacyState;
|
|
77
|
+
/**
|
|
78
|
+
* Whether a protocol-2 app shell has opened this project, read from disk on
|
|
79
|
+
* every call: another serve of the same project may have written it since
|
|
80
|
+
* this one started. Anything at the marker path counts, and so does an
|
|
81
|
+
* unsafe state directory (fail closed).
|
|
82
|
+
*/
|
|
83
|
+
private protocol2MarkerPresent;
|
|
84
|
+
private writeProtocol2Marker;
|
|
85
|
+
private readContentOriginRecord;
|
|
86
|
+
private writeContentOriginRecord;
|
|
87
|
+
private noteProtocol2Shell;
|
|
27
88
|
setLocalContentPorts(ports: LocalContentPorts): void;
|
|
28
89
|
setLocalContentHost(host: string): void;
|
|
29
90
|
authorizeHttp(req: http.IncomingMessage): boolean;
|
|
@@ -47,9 +108,26 @@ export declare class ServeSecurity {
|
|
|
47
108
|
consumeLegacyContentTicket(req: http.IncomingMessage): ContentRole | null;
|
|
48
109
|
private pruneTickets;
|
|
49
110
|
shellBootstrap(req: http.IncomingMessage): string;
|
|
50
|
-
contentOrigins(req: http.IncomingMessage
|
|
111
|
+
contentOrigins(req: http.IncomingMessage, options?: {
|
|
112
|
+
allowCompatibility?: boolean;
|
|
113
|
+
}): {
|
|
51
114
|
editOrigin: string;
|
|
52
115
|
playOrigin: string;
|
|
116
|
+
contentParams?: Record<string, string>;
|
|
117
|
+
/** Set only for signed (cloud, isolated) origins: when their labels expire. */
|
|
118
|
+
expiresAtSeconds?: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* What `GET /__castle/content-origins` returns to an open shell refreshing
|
|
122
|
+
* its grants. Never compatibility origins: the refresh request carries none
|
|
123
|
+
* of what admission needs (no `embed=mobile`, a sandbox referrer), and a
|
|
124
|
+
* compatibility shell has no expiry to refresh. Isolated origins are exactly
|
|
125
|
+
* what the shell route would give the same shell now.
|
|
126
|
+
*/
|
|
127
|
+
refreshedContentOrigins(req: http.IncomingMessage): {
|
|
128
|
+
edit: string;
|
|
129
|
+
play: string;
|
|
130
|
+
expiresAtSeconds: number | null;
|
|
53
131
|
};
|
|
54
132
|
private contentGrantExpiry;
|
|
55
133
|
/**
|
|
@@ -68,8 +146,32 @@ export declare class ServeSecurity {
|
|
|
68
146
|
localContentProxyHeaders(role: ContentRole): Record<string, string>;
|
|
69
147
|
verifyContentRequest(req: http.IncomingMessage): ContentRole | null;
|
|
70
148
|
compatibilityContentRole(req: http.IncomingMessage): ContentRole | null;
|
|
149
|
+
/**
|
|
150
|
+
* The content role a compatibility-mode request gets on the shell origin,
|
|
151
|
+
* and whether its response must be sandboxed (see CompatibilityContent).
|
|
152
|
+
*/
|
|
153
|
+
compatibilityContent(req: http.IncomingMessage): CompatibilityContent | null;
|
|
71
154
|
shellOrigin(req: http.IncomingMessage): string;
|
|
72
155
|
private mintContentLabel;
|
|
73
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Whether this shell request gets compatibility origins (edit and play on the
|
|
158
|
+
* shell origin, the shell's own authority). Only a released mobile app may:
|
|
159
|
+
* castle-www forwards `embed=mobile` (every released app sends it) and, from
|
|
160
|
+
* protocol-2 apps, `mobileHostProtocol=2`. Those parameters are attacker
|
|
161
|
+
* controlled -- an isolated deck can navigate its frame or a new window to
|
|
162
|
+
* `?embed=mobile` -- so admission also needs what deck code cannot forge:
|
|
163
|
+
*
|
|
164
|
+
* - a native WebView user agent (a script cannot change its browser's UA,
|
|
165
|
+
* so no desktop or mobile browser is ever admitted);
|
|
166
|
+
* - castle-www as the embedder: a castle.xyz referrer and, where the browser
|
|
167
|
+
* sends Fetch Metadata, not a cross-site request (a navigation from the
|
|
168
|
+
* castlexyz.com content domain is cross-site and carries its referrer);
|
|
169
|
+
* - no protocol-2 shell ever seen on this project (see protocol2ShellSeen): inside
|
|
170
|
+
* a protocol-2 app, deck code can top-navigate to castle.xyz/admin/cloud
|
|
171
|
+
* with embed=mobile alone, and the request would otherwise look legitimate.
|
|
172
|
+
*
|
|
173
|
+
* See docs/mobile-webview-host-protocol.md for what remains.
|
|
174
|
+
*/
|
|
175
|
+
private admitCompatibilityShell;
|
|
74
176
|
private contentMac;
|
|
75
177
|
}
|