@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.11.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.
Files changed (255) hide show
  1. package/AGENTS.md +2 -2
  2. package/README.md +47 -6
  3. package/docs/architecture.md +1369 -63
  4. package/package.json +14 -9
  5. package/packages/extension/package.json +5 -3
  6. package/packages/extension/src/bridge-handlers/dispatch.ts +57 -3
  7. package/packages/extension/src/bridge-handlers/instance.ts +10 -1
  8. package/packages/extension/src/bridge-handlers/lifecycle.ts +65 -26
  9. package/packages/extension/src/bridge-ticket-client.ts +61 -7
  10. package/packages/extension/src/bridge-tls-checks.ts +79 -0
  11. package/packages/extension/src/bridge.ts +41 -28
  12. package/packages/extension/src/canvas-tool.ts +2 -0
  13. package/packages/extension/src/command-handler.ts +80 -6
  14. package/packages/extension/src/connect-target.ts +23 -0
  15. package/packages/extension/src/connection.ts +30 -7
  16. package/packages/extension/src/dashboard-http-origin.ts +88 -0
  17. package/packages/extension/src/dev-build.ts +11 -1
  18. package/packages/extension/src/git-link-builder.ts +11 -2
  19. package/packages/extension/src/inbound-limits.ts +138 -0
  20. package/packages/extension/src/local-token-header.ts +77 -6
  21. package/packages/extension/src/model-refresh.ts +69 -0
  22. package/packages/extension/src/pinned-endpoint.ts +44 -0
  23. package/packages/extension/src/project-trust-live.ts +143 -0
  24. package/packages/extension/src/project-trust.ts +159 -20
  25. package/packages/extension/src/provider-register.ts +59 -18
  26. package/packages/extension/src/remote-registration-gate.ts +21 -21
  27. package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
  28. package/packages/extension/src/role-model-tools.ts +47 -6
  29. package/packages/extension/src/server-auto-start.ts +1 -1
  30. package/packages/extension/src/server-proof-probe.ts +117 -0
  31. package/packages/extension/src/session-sync.ts +42 -12
  32. package/packages/extension/src/vault-delivery.ts +11 -1
  33. package/packages/server/package.json +8 -8
  34. package/packages/server/src/access/access-grants.ts +61 -8
  35. package/packages/server/src/access/access-health.ts +10 -0
  36. package/packages/server/src/access/access-plane.ts +5 -1
  37. package/packages/server/src/access/containment-gate.ts +55 -17
  38. package/packages/server/src/access/cwd-verdict.ts +3 -3
  39. package/packages/server/src/access/pi-trust-live.ts +244 -0
  40. package/packages/server/src/access/pi-trust-mirror-service.ts +44 -11
  41. package/packages/server/src/access/planes.ts +106 -1
  42. package/packages/server/src/access/preview-egress-store.ts +153 -0
  43. package/packages/server/src/access/prompt-channel.ts +5 -0
  44. package/packages/server/src/access/provisioning-wiring.ts +113 -0
  45. package/packages/server/src/access/provisioning.ts +763 -0
  46. package/packages/server/src/access/yolo-session.ts +54 -2
  47. package/packages/server/src/acp-bridge/acp-session-adapter.ts +8 -3
  48. package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
  49. package/packages/server/src/auth/audit-log.ts +80 -0
  50. package/packages/server/src/auth/auth-plugin.ts +44 -25
  51. package/packages/server/src/auth/auth.ts +24 -4
  52. package/packages/server/src/auth/bearer-auth.ts +52 -12
  53. package/packages/server/src/auth/cors-origin.ts +76 -29
  54. package/packages/server/src/auth/csp-report-paths.ts +31 -0
  55. package/packages/server/src/auth/csp-report-sink.ts +302 -0
  56. package/packages/server/src/auth/csp-report-store.ts +406 -0
  57. package/packages/server/src/auth/csp.ts +105 -9
  58. package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
  59. package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
  60. package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
  61. package/packages/server/src/auth/local-proof.ts +69 -18
  62. package/packages/server/src/auth/localhost-guard.ts +48 -10
  63. package/packages/server/src/auth/nav-intent.ts +72 -0
  64. package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
  65. package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
  66. package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
  67. package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
  68. package/packages/server/src/auth/plugin-server-trust.ts +29 -0
  69. package/packages/server/src/auth/plugin-trust-store.ts +103 -0
  70. package/packages/server/src/auth/proven-tls.ts +45 -0
  71. package/packages/server/src/auth/provider-auth-storage.ts +6 -1
  72. package/packages/server/src/auth/radius-mcp.ts +1 -1
  73. package/packages/server/src/auth/request-principal.ts +32 -0
  74. package/packages/server/src/auth/secret-rotation.ts +246 -0
  75. package/packages/server/src/auth/secure-origin.ts +56 -0
  76. package/packages/server/src/auth/serve-app-host.ts +111 -11
  77. package/packages/server/src/auth/ws-ticket.ts +39 -1
  78. package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
  79. package/packages/server/src/browser-handlers/directory-handler.ts +23 -0
  80. package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
  81. package/packages/server/src/browser-handlers/handler-context.ts +25 -2
  82. package/packages/server/src/browser-handlers/session-action-handler.ts +9 -1
  83. package/packages/server/src/browser-handlers/subscription-handler.ts +100 -2
  84. package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
  85. package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
  86. package/packages/server/src/cli.ts +210 -39
  87. package/packages/server/src/config-api.ts +23 -1
  88. package/packages/server/src/config-snapshot.ts +48 -1
  89. package/packages/server/src/directory-service.ts +160 -54
  90. package/packages/server/src/event-wiring.ts +143 -108
  91. package/packages/server/src/git-worktree/git-operations.ts +44 -10
  92. package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
  93. package/packages/server/src/git-worktree/ref-arg.ts +39 -0
  94. package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
  95. package/packages/server/src/identity/http-road-classification.ts +13 -1
  96. package/packages/server/src/identity/ws-message-scope.ts +1 -0
  97. package/packages/server/src/identity/ws-road-classification.ts +1 -0
  98. package/packages/server/src/known-server-moves.ts +36 -15
  99. package/packages/server/src/lib/browse-roots.ts +118 -17
  100. package/packages/server/src/lib/client-dist.ts +36 -21
  101. package/packages/server/src/lib/dashboard-state-guard.ts +230 -0
  102. package/packages/server/src/lib/diagram-render.ts +4 -6
  103. package/packages/server/src/lib/eml.ts +3 -8
  104. package/packages/server/src/lib/file-cwd-admission.ts +145 -0
  105. package/packages/server/src/lib/grep-worker.ts +23 -0
  106. package/packages/server/src/lib/grep.ts +93 -7
  107. package/packages/server/src/lib/index-html.ts +81 -0
  108. package/packages/server/src/lib/office-preview.ts +2 -3
  109. package/packages/server/src/lib/path-containment.ts +7 -0
  110. package/packages/server/src/lib/resolve-file-mention.ts +11 -9
  111. package/packages/server/src/lib/route-admission.ts +80 -0
  112. package/packages/server/src/lib/writable-md-target.ts +4 -0
  113. package/packages/server/src/lifecycle/recovery-server.ts +65 -18
  114. package/packages/server/src/live-server/capability-redact.ts +15 -0
  115. package/packages/server/src/live-server/live-browser-gate.ts +22 -0
  116. package/packages/server/src/live-server/live-capability.ts +224 -17
  117. package/packages/server/src/live-server/live-csp-report.ts +63 -0
  118. package/packages/server/src/live-server/live-csp.ts +93 -0
  119. package/packages/server/src/live-server/live-egress.ts +435 -0
  120. package/packages/server/src/live-server/live-exposure.ts +149 -0
  121. package/packages/server/src/live-server/live-log.ts +21 -0
  122. package/packages/server/src/live-server/live-origin-scan.ts +298 -0
  123. package/packages/server/src/live-server/live-server-manager.ts +209 -33
  124. package/packages/server/src/live-server/live-server-proxy.ts +162 -17
  125. package/packages/server/src/live-server/live-static.ts +228 -0
  126. package/packages/server/src/openspec/dependencies-file.ts +122 -0
  127. package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
  128. package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
  129. package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
  130. package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
  131. package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
  132. package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
  133. package/packages/server/src/openspec/workflow-schema.ts +141 -267
  134. package/packages/server/src/package/npm-search-proxy.ts +5 -2
  135. package/packages/server/src/package/provider-probe.ts +8 -2
  136. package/packages/server/src/pairing/browser-gateway.ts +188 -12
  137. package/packages/server/src/pairing/device-token-services.ts +26 -0
  138. package/packages/server/src/pairing/paired-devices.ts +335 -22
  139. package/packages/server/src/pairing/pairing.ts +34 -4
  140. package/packages/server/src/pairing/socket-locality.ts +26 -0
  141. package/packages/server/src/persistence/preferences-store.ts +9 -0
  142. package/packages/server/src/pi/bridge-channel.ts +33 -0
  143. package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
  144. package/packages/server/src/pi/gateway-listeners.ts +9 -3
  145. package/packages/server/src/pi/host-project-trust.ts +14 -6
  146. package/packages/server/src/pi/pi-gateway.ts +191 -21
  147. package/packages/server/src/pi/resource-toggle-trust.ts +1 -1
  148. package/packages/server/src/plugin-discovery-wiring.ts +142 -0
  149. package/packages/server/src/plugin-event-seam.ts +116 -4
  150. package/packages/server/src/plugin-runtime-clients.ts +89 -0
  151. package/packages/server/src/routes/access-routes.ts +159 -9
  152. package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
  153. package/packages/server/src/routes/canvas-types-routes.ts +20 -6
  154. package/packages/server/src/routes/csp-violations-routes.ts +162 -0
  155. package/packages/server/src/routes/file-routes.ts +329 -209
  156. package/packages/server/src/routes/file-write-binary-routes.ts +77 -20
  157. package/packages/server/src/routes/folder-project-routes.ts +18 -12
  158. package/packages/server/src/routes/git-routes.ts +319 -203
  159. package/packages/server/src/routes/grep-routes.ts +38 -14
  160. package/packages/server/src/routes/known-servers-routes.ts +189 -91
  161. package/packages/server/src/routes/live-server-routes.ts +378 -15
  162. package/packages/server/src/routes/local-proof-routes.ts +14 -0
  163. package/packages/server/src/routes/nav-intent-routes.ts +46 -0
  164. package/packages/server/src/routes/openspec-group-routes.ts +53 -44
  165. package/packages/server/src/routes/openspec-routes.ts +379 -28
  166. package/packages/server/src/routes/package-routes.ts +58 -10
  167. package/packages/server/src/routes/pairing-routes.ts +146 -10
  168. package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
  169. package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
  170. package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
  171. package/packages/server/src/routes/provider-auth-routes.ts +15 -2
  172. package/packages/server/src/routes/resource-activation-routes.ts +18 -4
  173. package/packages/server/src/routes/session-routes.ts +51 -4
  174. package/packages/server/src/routes/system-routes.ts +84 -15
  175. package/packages/server/src/routes/ui-link-base.ts +88 -0
  176. package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
  177. package/packages/server/src/server.ts +648 -137
  178. package/packages/server/src/session/hydration-state.ts +148 -0
  179. package/packages/server/src/session/memory-session-manager.ts +7 -0
  180. package/packages/server/src/session/replay-exit-controller.ts +221 -0
  181. package/packages/server/src/session/retained-transcript.ts +9 -2
  182. package/packages/server/src/session/session-load-worker.ts +11 -2
  183. package/packages/server/src/spawn-process/headless-pid-registry.ts +14 -9
  184. package/packages/server/src/terminal/terminal-manager.ts +54 -46
  185. package/packages/server/src/tls/tls-bridge-route.ts +61 -0
  186. package/packages/server/src/tls/tls-config-validation.ts +2 -0
  187. package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
  188. package/packages/server/src/vault/vault-delivery-hub.ts +155 -25
  189. package/packages/server/src/watch-files-handler.ts +66 -0
  190. package/packages/shared/package.json +1 -1
  191. package/packages/shared/src/browser-protocol.ts +148 -2
  192. package/packages/shared/src/canvas-declare.ts +27 -0
  193. package/packages/shared/src/config.ts +372 -53
  194. package/packages/shared/src/containment-guard.ts +35 -0
  195. package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +9 -0
  196. package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
  197. package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
  198. package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
  199. package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
  200. package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
  201. package/packages/shared/src/dashboard-plugin/index.ts +2 -0
  202. package/packages/shared/src/dashboard-plugin/manifest-types.ts +54 -1
  203. package/packages/shared/src/dashboard-plugin/plugin-status.ts +54 -0
  204. package/packages/shared/src/dashboard-plugin/slot-props.ts +45 -3
  205. package/packages/shared/src/dashboard-plugin/slot-types.ts +8 -0
  206. package/packages/shared/src/dashboard-plugin/subagent-types.ts +219 -0
  207. package/packages/shared/src/dashboard-plugin/ui-primitives.ts +28 -0
  208. package/packages/shared/src/display-prefs.ts +13 -0
  209. package/packages/shared/src/doctor-core.ts +94 -27
  210. package/packages/shared/src/live-server.ts +141 -0
  211. package/packages/shared/src/local-proof-signal.ts +16 -0
  212. package/packages/shared/src/loopback-host.ts +26 -0
  213. package/packages/shared/src/mcp/verb-tiers.generated.ts +178 -0
  214. package/packages/shared/src/mdns-discovery.ts +25 -6
  215. package/packages/shared/src/nav-intent.ts +29 -0
  216. package/packages/shared/src/openspec-dependencies.ts +760 -0
  217. package/packages/shared/src/openspec-poller.ts +3 -2
  218. package/packages/shared/src/pairing-knock-client.ts +44 -4
  219. package/packages/shared/src/pi-trust-live-query.ts +93 -0
  220. package/packages/shared/src/pi-trust-mirror-snapshot.ts +5 -7
  221. package/packages/shared/src/pi-trust-mirror-types.ts +36 -3
  222. package/packages/shared/src/pi-trust-mirror.ts +29 -3
  223. package/packages/shared/src/pi-trust-resource-digest.ts +255 -0
  224. package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
  225. package/packages/shared/src/platform/git-source.ts +88 -26
  226. package/packages/shared/src/platform/git.ts +14 -8
  227. package/packages/shared/src/platform/process.ts +48 -4
  228. package/packages/shared/src/platform/resolve-pi-shell.ts +76 -0
  229. package/packages/shared/src/platform/select-git-source.ts +7 -0
  230. package/packages/shared/src/plugin-route-cwd.ts +95 -0
  231. package/packages/shared/src/preview-egress.ts +138 -0
  232. package/packages/shared/src/project-root.ts +16 -0
  233. package/packages/shared/src/protocol.ts +40 -1
  234. package/packages/shared/src/recommended-extensions.ts +18 -0
  235. package/packages/shared/src/recovery-timing.ts +27 -0
  236. package/packages/shared/src/remote-credentials.ts +63 -0
  237. package/packages/shared/src/rest-api.ts +55 -8
  238. package/packages/shared/src/route-tiers.ts +55 -1
  239. package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
  240. package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
  241. package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
  242. package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
  243. package/packages/shared/src/safe-local-path.ts +24 -0
  244. package/packages/shared/src/sanitize-profiles.ts +98 -0
  245. package/packages/shared/src/server-launcher.ts +9 -1
  246. package/packages/shared/src/server-pinning.ts +55 -2
  247. package/packages/shared/src/server-routes.ts +462 -0
  248. package/packages/shared/src/session-ui-path.ts +11 -0
  249. package/packages/shared/src/tls-only-token.ts +16 -0
  250. package/packages/shared/src/tool-registry/definitions.ts +5 -5
  251. package/packages/shared/src/tool-registry/strategies.ts +12 -11
  252. package/packages/shared/src/types.ts +66 -0
  253. package/packages/shared/src/url-policy.ts +96 -0
  254. package/packages/shared/src/vault-delivery.ts +15 -0
  255. package/packages/shared/src/ws-message-tiers.ts +1 -0
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Rate-limited, single-line log for REST refusals whose only fault is missing
3
+ * local proof (`local_proof_required`), so an operator can see which local
4
+ * caller needs migrating and a container probing the host is visible.
5
+ *
6
+ * Line: `[local-proof] refused peer=<addr> host=<sanitized> method=<M> route=<pattern>[ suppressed=<n>]`.
7
+ *
8
+ * The limiter key is (route pattern, reason) — NEVER the caller-chosen Host — so a
9
+ * flood of random Host values cannot grow state. At most one line per key per
10
+ * window; the first line after a window carries the suppressed count. State is
11
+ * capped at `maxKeys`: once full, a new key folds into one shared overflow bucket
12
+ * (`route=<other>`) instead of evicting, so a key never re-emits inside its window.
13
+ * `host` is length-capped and every non-printable or whitespace byte is replaced,
14
+ * so a line is always exactly one line.
15
+ *
16
+ * One instance per server. See change: close-container-loopback-impersonation (D6).
17
+ */
18
+ interface LocalProofRefusal {
19
+ peer: string | undefined;
20
+ host: string | undefined;
21
+ method: string;
22
+ /** Fastify route pattern (`/api/paired-devices/:id`), never the raw URL. */
23
+ route: string | undefined;
24
+ reason: string;
25
+ }
26
+
27
+ export interface LocalProofRefusalLoggerOptions {
28
+ windowMs?: number;
29
+ maxKeys?: number;
30
+ now?: () => number;
31
+ log?: (line: string) => void;
32
+ }
33
+
34
+ export interface LocalProofRefusalLogger {
35
+ log(refusal: LocalProofRefusal): void;
36
+ /** Rate-limit keys currently tracked (bounded by `maxKeys`). */
37
+ trackedKeys(): number;
38
+ }
39
+
40
+ const MAX_HOST_CHARS = 64;
41
+ const OVERFLOW_KEY = "<other>|overflow";
42
+
43
+ /** One-line, bounded rendering of a caller-chosen header or token. */
44
+ export function sanitizeForLog(value: string | undefined, max = MAX_HOST_CHARS): string {
45
+ if (!value) return "-";
46
+ const clipped = value.length > max ? `${value.slice(0, max)}...` : value;
47
+ return clipped.replace(/[^\x21-\x7e]/g, "?");
48
+ }
49
+
50
+ export function createLocalProofRefusalLogger(opts: LocalProofRefusalLoggerOptions = {}): LocalProofRefusalLogger {
51
+ const windowMs = opts.windowMs ?? 60_000;
52
+ const maxKeys = opts.maxKeys ?? 256;
53
+ const now = opts.now ?? Date.now;
54
+ const emit = opts.log ?? ((line: string) => console.warn(line));
55
+ const state = new Map<string, { windowStart: number; suppressed: number }>();
56
+
57
+ function prune(t: number): void {
58
+ for (const [k, v] of state) if (t - v.windowStart >= windowMs) state.delete(k);
59
+ }
60
+
61
+ return {
62
+ log(r) {
63
+ const t = now();
64
+ const route = sanitizeForLog(r.route ?? "<unmatched>", 96);
65
+ let key = `${route}|${r.reason}`;
66
+ let shownRoute = route;
67
+ if (!state.has(key) && state.size >= maxKeys) {
68
+ prune(t);
69
+ if (state.size >= maxKeys) {
70
+ key = OVERFLOW_KEY;
71
+ shownRoute = "<other>";
72
+ }
73
+ }
74
+ const entry = state.get(key);
75
+ if (entry && t - entry.windowStart < windowMs) {
76
+ entry.suppressed++;
77
+ return;
78
+ }
79
+ const suppressed = entry?.suppressed ?? 0;
80
+ state.set(key, { windowStart: t, suppressed: 0 });
81
+ emit(
82
+ `[local-proof] refused peer=${sanitizeForLog(r.peer, 45)} host=${sanitizeForLog(r.host)}` +
83
+ ` method=${sanitizeForLog(r.method, 12)} route=${shownRoute}` +
84
+ (suppressed > 0 ? ` suppressed=${suppressed}` : ""),
85
+ );
86
+ },
87
+ trackedKeys: () => state.size,
88
+ };
89
+ }
@@ -6,16 +6,24 @@
6
6
  * additionally present PROOF: the `X-Pi-Local-Token` header or a `pi_dash_local`
7
7
  * cookie bootstrapped from the local token (`pi-dashboard open` / Electron).
8
8
  *
9
- * Cookie value: `<id>.<expiresAt>.<HMAC(k_local, "<id>.<expiresAt>")>` with
10
- * `k_local = HMAC(localToken, "pi-dashboard/local-proof/v1")`. Rotating the local
11
- * token invalidates every proof cookie.
12
- * See change: harden-trust-and-credential-boundaries (D2).
9
+ * Cookie value: `<id>.<issuedAt>.<lastUse>.<port>.<HMAC(k_local, "<id>.<issuedAt>.<lastUse>.<port>")>`
10
+ * with `k_local = HMAC(localToken, "pi-dashboard/local-proof/v1")`. It is bound to the port
11
+ * of the listener that issued it (a browser sends it to every `localhost:<port>` site, so a
12
+ * cookie captured by another local web app only replays against the right port), expires
13
+ * after 12 h idle (re-signed when a request arrives more than 1 h after the last refresh) and
14
+ * has an absolute 30-day cap. Rotating the local token invalidates every proof cookie.
15
+ * See change: harden-trust-and-credential-boundaries (D2); close-container-loopback-impersonation (D12).
13
16
  */
14
17
  import crypto from "node:crypto";
15
18
  import { hasLocalCredential } from "./local-credential.js";
16
19
 
17
20
  export const LOCAL_PROOF_COOKIE = "pi_dash_local";
21
+ /** Absolute cap from `issuedAt`, and the cookie's browser `Max-Age`. */
18
22
  export const LOCAL_PROOF_MAX_AGE_S = 30 * 24 * 60 * 60;
23
+ /** A cookie unused (never re-signed) for longer than this is no longer proof. */
24
+ const LOCAL_PROOF_IDLE_MS = 12 * 60 * 60 * 1000;
25
+ /** An admitted request this long after the last refresh gets a re-signed cookie. */
26
+ const LOCAL_PROOF_REFRESH_AFTER_MS = 60 * 60 * 1000;
19
27
  const CODE_TTL_MS = 60_000;
20
28
 
21
29
  export interface LocalTrustContext {
@@ -24,13 +32,20 @@ export interface LocalTrustContext {
24
32
  localToken: string;
25
33
  /** `HMAC(localToken, "pi-dashboard/local-proof/v1")`. */
26
34
  proofKey: Buffer;
35
+ /** The listening port the cookie is bound to; absent ⇒ 0 (a context with no listener, e.g. `inject()`). */
36
+ port?: () => number;
27
37
  }
28
38
 
29
- export function createLocalTrustContext(localToken: string, strict: () => boolean): LocalTrustContext {
39
+ export function createLocalTrustContext(
40
+ localToken: string,
41
+ strict: () => boolean,
42
+ port?: () => number,
43
+ ): LocalTrustContext {
30
44
  return {
31
45
  strict,
32
46
  localToken,
33
47
  proofKey: crypto.createHmac("sha256", localToken).update("pi-dashboard/local-proof/v1").digest(),
48
+ ...(port ? { port } : {}),
34
49
  };
35
50
  }
36
51
 
@@ -38,27 +53,63 @@ function mac(key: Buffer, payload: string): string {
38
53
  return crypto.createHmac("sha256", key).update(payload).digest("base64url");
39
54
  }
40
55
 
41
- /** Mint a `pi_dash_local` cookie value. */
42
- export function signLocalProof(ctx: LocalTrustContext, now = Date.now(), maxAgeS = LOCAL_PROOF_MAX_AGE_S): string {
43
- const payload = `${crypto.randomBytes(12).toString("base64url")}.${now + maxAgeS * 1000}`;
56
+ const ctxPort = (ctx: LocalTrustContext): number => ctx.port?.() ?? 0;
57
+
58
+ function seal(ctx: LocalTrustContext, id: string, issuedAt: number, lastUse: number): string {
59
+ const payload = `${id}.${issuedAt}.${lastUse}.${ctxPort(ctx)}`;
44
60
  return `${payload}.${mac(ctx.proofKey, payload)}`;
45
61
  }
46
62
 
47
- /** Valid, unexpired, correctly signed proof cookie value? */
48
- export function verifyLocalProofCookie(value: string | undefined, ctx: LocalTrustContext, now = Date.now()): boolean {
49
- if (!value) return false;
63
+ /** Mint a `pi_dash_local` cookie value bound to this context's port. */
64
+ export function signLocalProof(ctx: LocalTrustContext, now = Date.now()): string {
65
+ return seal(ctx, crypto.randomBytes(12).toString("base64url"), now, now);
66
+ }
67
+
68
+ export interface LocalProofCookieInfo {
69
+ /** True when a request this long after `lastUse` should be given a re-signed cookie. */
70
+ needsRefresh: boolean;
71
+ /** A re-signed value (same id and `issuedAt`, `lastUse = now`). */
72
+ refreshed: string;
73
+ /** Seconds the re-signed cookie may live (remaining time to the absolute cap). */
74
+ maxAgeS: number;
75
+ }
76
+
77
+ /**
78
+ * `null` unless the cookie is correctly signed, bound to this port, within the idle window and
79
+ * within the absolute cap. Otherwise what a refresh would look like.
80
+ */
81
+ export function inspectLocalProofCookie(
82
+ value: string | undefined,
83
+ ctx: LocalTrustContext,
84
+ now = Date.now(),
85
+ ): LocalProofCookieInfo | null {
86
+ if (!value) return null;
50
87
  const parts = value.split(".");
51
- if (parts.length !== 3) return false;
52
- const [id, exp, sig] = parts as [string, string, string];
53
- const expiresAt = Number(exp);
54
- if (!id || !Number.isFinite(expiresAt) || expiresAt <= now) return false;
55
- const want = Buffer.from(mac(ctx.proofKey, `${id}.${exp}`));
88
+ if (parts.length !== 5) return null;
89
+ const [id, issued, last, port, sig] = parts as [string, string, string, string, string];
90
+ const issuedAt = Number(issued);
91
+ const lastUse = Number(last);
92
+ if (!id || !Number.isFinite(issuedAt) || !Number.isFinite(lastUse) || Number(port) !== ctxPort(ctx)) return null;
93
+ const want = Buffer.from(mac(ctx.proofKey, `${id}.${issued}.${last}.${port}`));
56
94
  const got = Buffer.from(sig);
57
- return want.length === got.length && crypto.timingSafeEqual(want, got);
95
+ if (want.length !== got.length || !crypto.timingSafeEqual(want, got)) return null;
96
+ if (lastUse < issuedAt || now - lastUse > LOCAL_PROOF_IDLE_MS) return null;
97
+ const absoluteEnd = issuedAt + LOCAL_PROOF_MAX_AGE_S * 1000;
98
+ if (now > absoluteEnd) return null;
99
+ return {
100
+ needsRefresh: now - lastUse > LOCAL_PROOF_REFRESH_AFTER_MS,
101
+ refreshed: seal(ctx, id, issuedAt, now),
102
+ maxAgeS: Math.max(1, Math.floor((absoluteEnd - now) / 1000)),
103
+ };
104
+ }
105
+
106
+ /** Valid, unexpired, port-bound, correctly signed proof cookie value? */
107
+ export function verifyLocalProofCookie(value: string | undefined, ctx: LocalTrustContext, now = Date.now()): boolean {
108
+ return inspectLocalProofCookie(value, ctx, now) !== null;
58
109
  }
59
110
 
60
111
  /** Read one cookie from a raw `Cookie` header (works on WS upgrade paths). */
61
- function readCookie(headers: Record<string, unknown> | undefined, name: string): string | undefined {
112
+ export function readCookie(headers: Record<string, unknown> | undefined, name: string): string | undefined {
62
113
  const raw = headers?.cookie;
63
114
  const header = Array.isArray(raw) ? raw.join("; ") : raw;
64
115
  if (typeof header !== "string") return undefined;
@@ -7,7 +7,7 @@ import { isIPv4, isIPv6 } from "node:net";
7
7
  import os from "node:os";
8
8
  import { routeTier } from "@blackbelt-technology/pi-dashboard-shared/route-tiers.js";
9
9
  import type { FastifyReply, FastifyRequest } from "fastify";
10
- import { redactCapability } from "../live-server/live-capability.js";
10
+ import { redactCapability } from "../live-server/capability-redact.js";
11
11
  import { blockEvents } from "../tunnel/tunnel-block-events.js";
12
12
  import { isBypassed } from "./bypass-urls.js";
13
13
  import { hasLocalCredential } from "./local-credential.js";
@@ -38,7 +38,7 @@ const PROXY_FORWARDING_HEADERS = [
38
38
  * Core callers keep the 5-header list above: widening the shared constant
39
39
  * would change core admission; plugin scopes get the stricter set.
40
40
  */
41
- const PLUGIN_PROXY_FORWARDING_HEADERS = [
41
+ export const PLUGIN_PROXY_FORWARDING_HEADERS = [
42
42
  ...PROXY_FORWARDING_HEADERS,
43
43
  "via",
44
44
  "x-forwarded-server",
@@ -99,6 +99,21 @@ export function isLocallyTrusted(
99
99
  return hasLocalProof(input.headers, ctx);
100
100
  }
101
101
 
102
+ /**
103
+ * Is this a genuinely-local caller that the strict default refuses ONLY for want
104
+ * of proof — i.e. the remedy is `pi-dashboard open`? Built from the one shared
105
+ * predicate: the call without ctx means "genuinely local", the call with ctx
106
+ * means "trusted now". A signed-in or paired caller is not asked for proof.
107
+ * See change: close-container-loopback-impersonation (D3).
108
+ */
109
+ export function needsLocalProof(
110
+ request: { ip: string; headers: unknown; isAuthenticated?: boolean },
111
+ ctx: LocalTrustContext | undefined,
112
+ ): boolean {
113
+ const input = { ip: request.ip, headers: request.headers as HeaderBag };
114
+ return isLocallyTrusted(input) && !isLocallyTrusted(input, ctx) && request.isAuthenticated !== true;
115
+ }
116
+
102
117
  /**
103
118
  * May this request see the access-prompting posture (host-gate mode, whether
104
119
  * prompting is on, why a denial was not asked about)? Authenticated OR
@@ -146,13 +161,20 @@ export function isPluginScopePeerLocal(
146
161
  hostHeader: string | undefined,
147
162
  headers: HeaderBag,
148
163
  ctx?: LocalTrustContext,
164
+ /**
165
+ * `peerCredential: "plugin"` scope: the plugin authenticates the peer itself (a ticket in the URL), so
166
+ * ONLY the strict local-proof requirement is skipped here; loopback peer, loopback Host and
167
+ * no-forwarding-header still hold. See change: close-container-loopback-impersonation (D10).
168
+ */
169
+ opts: { pluginAuthenticatesPeer?: boolean } = {},
149
170
  ): boolean {
150
171
  return (
151
172
  isLoopback(ip) &&
152
173
  isLoopbackHostHeader(hostHeader) &&
153
174
  !hasProxyForwardingHeaders(headers, { extended: true }) &&
154
- // Strict: a marker-less relay is indistinguishable here; require proof.
155
- (!ctx || !ctx.strict() || hasLocalProof(headers, ctx))
175
+ // Strict: a marker-less relay is indistinguishable here; require proof (unless the plugin
176
+ // authenticates the peer with its own credential).
177
+ (opts.pluginAuthenticatesPeer === true || !ctx || !ctx.strict() || hasLocalProof(headers, ctx))
156
178
  );
157
179
  }
158
180
 
@@ -325,6 +347,19 @@ function readRequestOrigin(headers: FastifyRequest["headers"]): string | undefin
325
347
  */
326
348
  let networkDenialObserver: ((request: FastifyRequest) => void) | null = null;
327
349
 
350
+ /**
351
+ * Observer told about every REST refusal whose only fault is missing local proof
352
+ * (`local_proof_required`). The server installs its rate-limited logger here and
353
+ * clears it on stop. Best-effort: a throwing observer never alters the refusal.
354
+ * See change: close-container-loopback-impersonation (D6).
355
+ */
356
+ let localProofRefusalObserver: ((request: FastifyRequest) => void) | null = null;
357
+
358
+ /** Install (or clear, with `null`) the local-proof refusal observer. */
359
+ export function setLocalProofRefusalObserver(observer: ((request: FastifyRequest) => void) | null): void {
360
+ localProofRefusalObserver = observer;
361
+ }
362
+
328
363
  /** Install (or clear, with `null`) the network-denial observer. */
329
364
  export function setNetworkDenialObserver(observer: ((request: FastifyRequest) => void) | null): void {
330
365
  networkDenialObserver = observer;
@@ -344,17 +379,20 @@ function sendNetworkDenied(request: FastifyRequest, reply: FastifyReply, localTr
344
379
  // No grant prompt for a relayed-loopback peer: "trust 127.0.0.1?" would name
345
380
  // the tunnel agent, and the resulting entry is inert under isTrustedSource
346
381
  // (grant->deny loop). See change: fix-trusted-network-tunnel-bypass (D4).
347
- if (!isRelayedLoopback(request.ip, request.headers as Record<string, unknown>)) {
382
+ // Nor for a bare-loopback caller that merely lacks proof: the remedy is `pi-dashboard open`,
383
+ // and an unproven local caller must not be able to raise an operator prompt.
384
+ // See change: close-container-loopback-impersonation (D3, D8).
385
+ const proofNeeded = needsLocalProof(request as unknown as { ip: string; headers: unknown; isAuthenticated?: boolean }, localTrust);
386
+ if (!proofNeeded && !isRelayedLoopback(request.ip, request.headers as Record<string, unknown>)) {
348
387
  try {
349
388
  networkDenialObserver?.(request);
350
389
  } catch { /* observing is best-effort, never blocks the denial */ }
351
390
  }
352
391
  // Strict mode: a bare-loopback caller lacking proof gets an actionable denial.
353
- if (
354
- localTrust?.strict() &&
355
- isGenuinelyLocal(request.ip, request.headers as Record<string, unknown>) &&
356
- !hasLocalProof(request.headers as Record<string, unknown>, localTrust)
357
- ) {
392
+ if (proofNeeded) {
393
+ try {
394
+ localProofRefusalObserver?.(request);
395
+ } catch { /* logging is best-effort, never blocks the refusal */ }
358
396
  reply.code(403).send({
359
397
  success: false,
360
398
  error: "network_not_allowed",
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Server-signed navigation intents (change: harden-client-sinks, design D10).
3
+ *
4
+ * `ni = base64url(e) "." base64url(HMAC-SHA256(key, p \0 k \0 canon(target) \0 e))`
5
+ *
6
+ * Only the expiry `e` (epoch seconds, exactly {@link NAV_INTENT_TTL_S} after
7
+ * minting) and the MAC travel in the URL. The principal `p`, the kind `k`
8
+ * (`url-view` | `file-view`) and the canonical target are NOT in the value —
9
+ * the verifier takes them from its own request context and the route, then
10
+ * recomputes the MAC (constant-time compare). The key is a per-process random
11
+ * 32 bytes (the `SignedChallenges` pattern): a restart invalidates every
12
+ * intent, by design. An intent only upgrades a route-backed overlay's
13
+ * provenance from `agent` to `operator`; without one, the overlay keeps
14
+ * today's fail-closed agent provenance.
15
+ */
16
+ import crypto from "node:crypto";
17
+ import type { NavIntentKind, NavIntentTarget } from "@blackbelt-technology/pi-dashboard-shared/nav-intent.js";
18
+
19
+ export const NAV_INTENT_TTL_S = 600;
20
+ const MAX_NI_LENGTH = 256;
21
+
22
+ export type { NavIntentKind, NavIntentTarget };
23
+
24
+ export function isNavIntentKind(v: unknown): v is NavIntentKind {
25
+ return v === "url-view" || v === "file-view";
26
+ }
27
+
28
+ /** Canonical target bytes for the MAC; `null` when `target` does not fit `kind`. */
29
+ export function canonicalNavTarget(kind: NavIntentKind, target: unknown): string | null {
30
+ if (!target || typeof target !== "object") return null;
31
+ const t = target as Record<string, unknown>;
32
+ if (kind === "url-view") return typeof t.url === "string" && t.url.length > 0 && t.url.length <= 4096 ? t.url : null;
33
+ if (typeof t.cwd !== "string" || typeof t.path !== "string" || !t.cwd || !t.path) return null;
34
+ if (t.cwd.length > 4096 || t.path.length > 4096) return null;
35
+ return `${t.cwd}\u0000${t.path}`;
36
+ }
37
+
38
+ export class NavIntents {
39
+ private readonly key: Buffer;
40
+ private readonly now: () => number;
41
+
42
+ constructor(now: () => number = Date.now, key: Buffer = crypto.randomBytes(32)) {
43
+ this.now = now;
44
+ this.key = key;
45
+ }
46
+
47
+ private mac(principal: string, kind: NavIntentKind, canon: string, e: number): Buffer {
48
+ return crypto.createHmac("sha256", this.key).update(`${principal}\u0000${kind}\u0000${canon}\u0000${e}`).digest();
49
+ }
50
+
51
+ /** Mint an intent for `principal` opening `target`. Throws on a target that does not fit `kind`. */
52
+ mint(principal: string, kind: NavIntentKind, target: NavIntentTarget): string {
53
+ const canon = canonicalNavTarget(kind, target);
54
+ if (canon === null) throw new TypeError("nav-intent: target does not match kind");
55
+ const e = Math.floor(this.now() / 1000) + NAV_INTENT_TTL_S;
56
+ return `${Buffer.from(String(e)).toString("base64url")}.${this.mac(principal, kind, canon, e).toString("base64url")}`;
57
+ }
58
+
59
+ /** True only for an unexpired intent minted by this process for exactly this principal, kind and target. */
60
+ verify(ni: unknown, principal: string, kind: NavIntentKind, target: unknown): boolean {
61
+ if (typeof ni !== "string" || ni.length > MAX_NI_LENGTH) return false;
62
+ const parts = ni.split(".");
63
+ if (parts.length !== 2) return false;
64
+ const e = Number(Buffer.from(parts[0], "base64url").toString("utf8"));
65
+ if (!Number.isSafeInteger(e) || e * 1000 <= this.now()) return false;
66
+ const canon = canonicalNavTarget(kind, target);
67
+ if (canon === null) return false;
68
+ const given = Buffer.from(parts[1], "base64url");
69
+ const want = this.mac(principal, kind, canon, e);
70
+ return given.length === want.length && crypto.timingSafeEqual(given, want);
71
+ }
72
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Static same-origin assets for the pre-auth passkey pages (`passkey-pages.ts`), served by
3
+ * `passkey-routes.ts` under `/auth/passkey/`. Moving the scripts/styles out of the HTML lets the strict
4
+ * CSP (`script-src 'self' 'nonce-…'`, no `'unsafe-inline'`) cover these pages with no nonce.
5
+ * Per-request data reaches `login.js` through a `<script type="application/json" id="pk-data">` island,
6
+ * never through script text. Sources are TS string constants so packaging needs no extra copy step.
7
+ *
8
+ * See change: harden-cors-and-csp-reporting (D9).
9
+ */
10
+
11
+ export interface PasskeyAsset {
12
+ /** `Content-Type` of the response. */
13
+ type: string;
14
+ body: string;
15
+ }
16
+
17
+ const COMMON_JS = `var MSG={
18
+ unstable_origin:"Passkeys are unavailable on this dashboard address.",
19
+ passkeys_disabled:"Passkey sign-in is not enabled.",
20
+ invite_invalid:"This invite link is not valid.",invite_expired:"This invite has expired. Ask an operator for a new one.",
21
+ invite_exhausted:"This invite has already been used. Ask an operator for a new one.",
22
+ orphaned_credential:"This passkey belongs to a previous dashboard address. Ask an operator for a new invite, or use sign in with phone.",
23
+ unknown_credential:"This passkey is not registered (or the user was revoked).",
24
+ verification_failed:"The passkey could not be verified.",challenge_invalid:"The request expired. Please try again.",
25
+ duplicate_credential:"This passkey is already registered.",rate_limited:"Too many attempts. Wait a minute and try again.",
26
+ too_many_requests:"Too many pending sign-in requests. Try again shortly.",invalid:"That code is not valid or has expired.",
27
+ expired:"This sign-in request has expired.",origin_mismatch:"Open this page on the dashboard's primary address."};
28
+ function msg(c){return MSG[c]||"Something went wrong. Please try again.";}
29
+ async function post(u,b){var r=await fetch(u,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(b||{}),credentials:"same-origin"});var d={};try{d=await r.json();}catch(e){}return{ok:r.ok,d:d};}`;
30
+
31
+ const LOGIN_JS = `(function(){
32
+ var RET=JSON.parse(document.getElementById("pk-data").textContent).returnUrl;var err=document.getElementById("pk-err");function show(m){err.textContent=m;}
33
+ var opts=null;async function prefetch(){var o=await post("/auth/passkey/login/options");opts=o.ok?o.d:null;if(!o.ok)show(msg(o.d.error));}
34
+ prefetch();setInterval(prefetch,240000);
35
+ document.getElementById("pk-login").onclick=async function(){show("");if(!opts){await prefetch();if(!opts)return;}var o=opts;opts=null;
36
+ try{var resp=await SimpleWebAuthnBrowser.startAuthentication({optionsJSON:o.options});}catch(e){show("Passkey sign-in was cancelled.");prefetch();return;}
37
+ var v=await post("/auth/passkey/login/verify",{challengeId:o.challengeId,response:resp});if(v.ok){location.assign(RET);}else{show(msg(v.d.error));prefetch();}};
38
+ var timer=null;document.getElementById("pk-phone").onclick=async function(){show("");var s=await post("/auth/passkey/phone/start");if(!s.ok)return show(msg(s.d.error));
39
+ document.getElementById("pk-phone-box").hidden=false;document.getElementById("pk-qr").src=s.d.qrDataUrl;document.getElementById("pk-code").textContent=s.d.shortCode;
40
+ var st=document.getElementById("pk-status");st.textContent="Waiting for approval on your phone…";if(timer)clearInterval(timer);
41
+ timer=setInterval(async function(){var d={};try{var r=await fetch("/auth/passkey/phone/poll/"+encodeURIComponent(s.d.requestId),{credentials:"same-origin"});d=await r.json();}catch(e){return;}
42
+ if(d.status==="pending")return;clearInterval(timer);timer=null;
43
+ if(d.status==="approved"){location.assign(RET);}else if(d.status==="rejected"){st.textContent="Sign-in was declined on the phone.";}else{st.textContent="The sign-in request expired. Try again.";}},2000);};
44
+ })();`;
45
+
46
+ const INVITE_JS = `(function(){
47
+ var token=location.hash.slice(1);history.replaceState(null,"",location.pathname);
48
+ var m=document.getElementById("msg"),go=document.getElementById("go"),opts=null;
49
+ async function prefetch(){var o=await post("/auth/passkey/register/options",{token:token});if(!o.ok){m.textContent=msg(o.d.error);go.disabled=true;return;}
50
+ opts=o.d;go.disabled=false;var n=o.d.options&&o.d.options.user&&o.d.options.user.displayName;if(n)document.getElementById("who").textContent="Create a passkey for "+n+" on this device.";}
51
+ if(!token){m.textContent=msg("invite_invalid");}else{prefetch();}
52
+ go.onclick=async function(){m.textContent="";if(!opts)return;var o=opts;opts=null;go.disabled=true;
53
+ try{var resp=await SimpleWebAuthnBrowser.startRegistration({optionsJSON:o.options});}catch(e){m.textContent="Passkey creation was cancelled.";prefetch();return;}
54
+ var v=await post("/auth/passkey/register/verify",{challengeId:o.challengeId,token:token,response:resp});
55
+ if(v.ok){m.className="muted";m.textContent="Your passkey is ready. You can now sign in to the dashboard with it, or approve sign-ins from this phone.";document.getElementById("open").hidden=false;}
56
+ else{m.textContent=msg(v.d.error);if(v.d.error==="challenge_invalid")prefetch();}};
57
+ })();`;
58
+
59
+ const PHONE_JS = `(function(){
60
+ var token=location.hash.slice(1);history.replaceState(null,"",location.pathname);
61
+ var m=document.getElementById("msg"),ap=document.getElementById("approve"),opts=null;
62
+ function done(t,ok){document.getElementById("req").hidden=true;document.getElementById("code-form").hidden=true;m.className=ok?"muted":"err";m.textContent=t;}
63
+ async function prefetch(){var o=await post("/auth/passkey/login/options");if(!o.ok){m.textContent=msg(o.d.error);return;}opts=o.d;ap.disabled=false;}
64
+ async function load(){var v=await post("/auth/passkey/phone/view",{token:token});if(!v.ok)return done(msg(v.d.error||"expired"),false);
65
+ var r=v.d.requester;document.getElementById("r-browser").textContent=r.browser;document.getElementById("r-os").textContent=r.os;
66
+ document.getElementById("r-host").textContent=r.host;document.getElementById("r-ip").textContent=r.ip;document.getElementById("r-code").textContent=v.d.shortCode;
67
+ document.getElementById("code-form").hidden=true;document.getElementById("req").hidden=false;prefetch();}
68
+ document.getElementById("code-go").onclick=async function(){m.textContent="";var c=await post("/auth/passkey/phone/lookup",{code:document.getElementById("code").value});
69
+ if(!c.ok)return(m.textContent=msg(c.d.error));token=c.d.approvalToken;load();};
70
+ ap.onclick=async function(){m.textContent="";if(!opts)return;var o=opts;opts=null;ap.disabled=true;
71
+ try{var resp=await SimpleWebAuthnBrowser.startAuthentication({optionsJSON:o.options});}catch(e){m.textContent="Passkey approval was cancelled.";prefetch();return;}
72
+ var a=await post("/auth/passkey/phone/approve",{token:token,challengeId:o.challengeId,response:resp});
73
+ if(a.ok)done("Approved. The other screen is now signed in. You can close this page.",true);else{m.textContent=msg(a.d.error);prefetch();}};
74
+ document.getElementById("deny").onclick=async function(){var d=await post("/auth/passkey/phone/deny",{token:token});done(d.ok?"Sign-in denied.":msg(d.d.error||"expired"),d.ok);};
75
+ if(token){load();}else{document.getElementById("code-form").hidden=false;}
76
+ })();`;
77
+
78
+ const PAGES_CSS = `body{font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#0f172a;color:#e2e8f0;}
79
+ .card{background:#1e293b;padding:40px;border-radius:12px;max-width:400px;width:100%;text-align:center;box-sizing:border-box;}
80
+ h1{margin:0 0 24px;font-size:24px;}
81
+ .btn{display:block;width:100%;margin:10px 0;padding:12px 24px;background:#2563eb;color:#fff;border:0;border-radius:6px;font-size:16px;cursor:pointer;text-decoration:none;box-sizing:border-box;}
82
+ .btn.secondary{background:#334155;}
83
+ .btn:disabled{background:#475569;color:#94a3b8;cursor:not-allowed;}
84
+ .muted{color:#94a3b8;font-size:14px;}
85
+ .err{color:#fca5a5;min-height:1.2em;}
86
+ dl{display:grid;grid-template-columns:auto 1fr;gap:4px 12px;text-align:left;margin:16px 0;}
87
+ dt{color:#94a3b8;}dd{margin:0;word-break:break-all;}
88
+ input{font-size:20px;padding:8px;width:100%;box-sizing:border-box;text-align:center;letter-spacing:2px;text-transform:uppercase;border-radius:6px;border:1px solid #475569;background:#0f172a;color:#e2e8f0;}
89
+ img.qr{background:#fff;padding:8px;border-radius:8px;width:200px;height:200px;}
90
+ hr{border:0;border-top:1px solid #334155;margin:20px 0;}`;
91
+
92
+ /** `/auth/passkey/<name>` → asset. The page HTML references exactly these names. */
93
+ export const PASSKEY_ASSETS: Readonly<Record<string, PasskeyAsset>> = {
94
+ "common.js": { type: "application/javascript; charset=utf-8", body: COMMON_JS },
95
+ "login.js": { type: "application/javascript; charset=utf-8", body: LOGIN_JS },
96
+ "invite.js": { type: "application/javascript; charset=utf-8", body: INVITE_JS },
97
+ "phone.js": { type: "application/javascript; charset=utf-8", body: PHONE_JS },
98
+ "pages.css": { type: "text/css; charset=utf-8", body: PAGES_CSS },
99
+ };