@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.12.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/AGENTS.md +4 -2
- package/README.md +64 -18
- package/docs/architecture.md +2325 -270
- package/package.json +36 -20
- package/packages/extension/package.json +18 -9
- package/packages/extension/src/bridge-context.ts +6 -0
- package/packages/extension/src/bridge-handlers/dispatch.ts +109 -70
- package/packages/extension/src/bridge-handlers/forwarders.ts +19 -42
- package/packages/extension/src/bridge-handlers/instance.ts +31 -13
- package/packages/extension/src/bridge-handlers/lifecycle.ts +149 -66
- package/packages/extension/src/bridge-shutdown.ts +44 -0
- package/packages/extension/src/bridge-ticket-client.ts +61 -7
- package/packages/extension/src/bridge-tls-checks.ts +79 -0
- package/packages/extension/src/bridge.ts +309 -284
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +106 -37
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +153 -38
- package/packages/extension/src/credential-guard.ts +300 -0
- package/packages/extension/src/custom-entry-forward.ts +27 -18
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/default-model-apply.ts +83 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/flow-event-wiring.ts +19 -95
- package/packages/extension/src/followup-drain.ts +19 -5
- package/packages/extension/src/git-link-builder.ts +11 -2
- package/packages/extension/src/inbound-limits.ts +138 -0
- package/packages/extension/src/local-token-header.ts +77 -6
- package/packages/extension/src/model-refresh.ts +69 -0
- package/packages/extension/src/path-gate/decide.ts +68 -5
- package/packages/extension/src/path-gate/handler.ts +16 -8
- package/packages/extension/src/path-gate/index.ts +2 -2
- package/packages/extension/src/path-gate/roots.ts +15 -3
- package/packages/extension/src/path-gate/suppression.ts +3 -0
- package/packages/extension/src/pi-env.d.ts +8 -1
- package/packages/extension/src/pi-retry-settings.ts +11 -2
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +90 -14
- package/packages/extension/src/preview-path-link.ts +151 -0
- package/packages/extension/src/project-init/scaffold.ts +98 -35
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +178 -30
- package/packages/extension/src/provider-model-cache.ts +118 -0
- package/packages/extension/src/provider-register.ts +487 -46
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/retry-tracker.ts +90 -7
- package/packages/extension/src/role-manager.ts +4 -2
- package/packages/extension/src/role-model-tools.ts +68 -10
- package/packages/extension/src/server-auto-start.ts +69 -3
- package/packages/extension/src/server-launcher.ts +26 -8
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-sync.ts +53 -24
- package/packages/extension/src/spawn-new-session.ts +22 -0
- package/packages/extension/src/steer-buffer.ts +164 -0
- package/packages/extension/src/stream-forward-buffer.ts +64 -15
- package/packages/extension/src/sudo-askpass/config-reader.ts +32 -0
- package/packages/extension/src/sudo-askpass/controller.ts +405 -0
- package/packages/extension/src/sudo-askpass/helper-script.ts +69 -0
- package/packages/extension/src/sudo-askpass/in-flight.ts +79 -0
- package/packages/extension/src/sudo-askpass/index.ts +11 -0
- package/packages/extension/src/sudo-askpass/install.ts +143 -0
- package/packages/extension/src/sudo-askpass/password-cache.ts +118 -0
- package/packages/extension/src/sudo-askpass/prompt-text.ts +55 -0
- package/packages/extension/src/sudo-askpass/protocol.ts +18 -0
- package/packages/extension/src/sudo-askpass/sudo-mask-registry.ts +52 -0
- package/packages/extension/src/terminal-reload.ts +19 -5
- package/packages/extension/src/tool-update-filter-registry.ts +210 -0
- package/packages/extension/src/vault-delivery.ts +11 -1
- package/packages/extension/src/vault-redaction.ts +4 -3
- package/packages/server/package.json +17 -14
- package/packages/server/src/access/access-denials.ts +8 -0
- package/packages/server/src/access/access-grants.ts +303 -64
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +12 -1
- package/packages/server/src/access/containment-gate.ts +113 -30
- package/packages/server/src/access/cwd-verdict.ts +3 -3
- package/packages/server/src/access/denial-hold.ts +3 -0
- package/packages/server/src/access/grant-coordinator.ts +17 -1
- package/packages/server/src/access/named-grant.ts +3 -0
- package/packages/server/src/access/pending-grant-registry.ts +32 -5
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +50 -11
- package/packages/server/src/access/planes.ts +107 -1
- package/packages/server/src/access/preview-egress-store.ts +153 -0
- package/packages/server/src/access/prompt-channel.ts +5 -0
- package/packages/server/src/access/provisioning-wiring.ts +113 -0
- package/packages/server/src/access/provisioning.ts +763 -0
- package/packages/server/src/access/verified-read.ts +24 -7
- package/packages/server/src/access/yolo-session.ts +54 -2
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +18 -5
- package/packages/server/src/acp-bridge/server-requests.ts +10 -4
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/auth/audit-log.ts +108 -0
- package/packages/server/src/auth/auth-plugin.ts +230 -38
- package/packages/server/src/auth/auth.ts +104 -4
- package/packages/server/src/auth/bearer-auth.ts +52 -12
- package/packages/server/src/auth/bridge-ticket-eligibility.ts +53 -10
- package/packages/server/src/auth/cors-origin.ts +90 -30
- package/packages/server/src/auth/credential-envelope.ts +233 -0
- package/packages/server/src/auth/credential-key-worker.d.mts +16 -0
- package/packages/server/src/auth/credential-key-worker.mjs +108 -0
- package/packages/server/src/auth/credential-key.ts +479 -0
- package/packages/server/src/auth/credential-migration.ts +162 -0
- package/packages/server/src/auth/csp-report-paths.ts +26 -0
- package/packages/server/src/auth/csp-report-sink.ts +302 -0
- package/packages/server/src/auth/csp-report-store.ts +406 -0
- package/packages/server/src/auth/csp.ts +145 -11
- package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
- package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
- package/packages/server/src/auth/device-proof.ts +202 -0
- package/packages/server/src/auth/duplicate-cookie-gate.ts +271 -0
- package/packages/server/src/auth/host-admission.ts +7 -0
- package/packages/server/src/auth/host-gate.ts +13 -2
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +69 -18
- package/packages/server/src/auth/localhost-guard.ts +98 -33
- package/packages/server/src/auth/locked-json-file.ts +68 -6
- package/packages/server/src/auth/models-json-store.ts +269 -0
- package/packages/server/src/auth/mutation-origin-gate.ts +5 -2
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/node-guard.ts +36 -49
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
- package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
- package/packages/server/src/auth/plugin-credential-store.ts +81 -10
- package/packages/server/src/auth/plugin-server-trust.ts +29 -0
- package/packages/server/src/auth/plugin-trust-store.ts +103 -0
- package/packages/server/src/auth/proven-tls.ts +45 -0
- package/packages/server/src/auth/provider-auth-storage.ts +214 -12
- package/packages/server/src/auth/provider-block-checks.ts +321 -0
- package/packages/server/src/auth/provider-host-detect.ts +151 -0
- package/packages/server/src/auth/provider-key-file.ts +71 -0
- package/packages/server/src/auth/provider-readiness.ts +91 -0
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/route-tier-gate.ts +3 -2
- package/packages/server/src/auth/secret-rotation.ts +246 -0
- package/packages/server/src/auth/secure-origin.ts +56 -0
- package/packages/server/src/auth/serve-app-host.ts +111 -11
- package/packages/server/src/auth/vertex-key-check.ts +140 -0
- package/packages/server/src/auth/ws-ticket.ts +40 -2
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/browse.ts +73 -20
- package/packages/server/src/browser-handlers/acp-guard.ts +1 -4
- package/packages/server/src/browser-handlers/directory-handler.ts +34 -24
- package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
- package/packages/server/src/browser-handlers/handler-context.ts +25 -2
- package/packages/server/src/browser-handlers/session-action-handler.ts +167 -63
- package/packages/server/src/browser-handlers/spawn-choice.ts +138 -1
- package/packages/server/src/browser-handlers/subscription-handler.ts +146 -3
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/build-plugin-send-prompt.ts +18 -0
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli/credentials-command.ts +555 -0
- package/packages/server/src/cli.ts +229 -53
- package/packages/server/src/config-api.ts +53 -35
- package/packages/server/src/config-snapshot.ts +197 -1
- package/packages/server/src/directory-service.ts +193 -68
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +13 -3
- package/packages/server/src/event-wiring.ts +322 -207
- package/packages/server/src/git-worktree/ensure-worktree.ts +185 -0
- package/packages/server/src/git-worktree/git-operations.ts +45 -11
- package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
- package/packages/server/src/git-worktree/ref-arg.ts +39 -0
- package/packages/server/src/git-worktree/repo-lock.ts +42 -0
- package/packages/server/src/git-worktree/start-worktree-init.ts +151 -0
- package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
- package/packages/server/src/git-worktree/worktree-init.ts +5 -1
- package/packages/server/src/identity/http-road-classification.ts +18 -2
- package/packages/server/src/identity/identity-floor.ts +5 -2
- package/packages/server/src/identity/ws-message-scope.ts +11 -3
- package/packages/server/src/identity/ws-road-classification.ts +3 -1
- package/packages/server/src/known-server-moves.ts +36 -15
- package/packages/server/src/lib/browse-roots.ts +129 -17
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/content-disposition.ts +20 -0
- package/packages/server/src/lib/dashboard-state-guard.ts +513 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/eml.ts +5 -10
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/frame-policy-probe.ts +308 -0
- package/packages/server/src/lib/frame-policy-test-seam.ts +99 -0
- package/packages/server/src/lib/frame-policy-verdict.ts +125 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +96 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/mention-fuzzy-index.ts +263 -0
- package/packages/server/src/lib/office-preview.ts +49 -13
- package/packages/server/src/lib/path-containment.ts +50 -10
- package/packages/server/src/lib/resolve-file-mention.ts +234 -40
- package/packages/server/src/lib/resolve-mentions-batch.ts +143 -0
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-handler-target.ts +4 -0
- package/packages/server/src/lib/writable-md-target.ts +26 -0
- package/packages/server/src/lifecycle/boot-parent-liveness.ts +10 -25
- package/packages/server/src/lifecycle/credential-exit-barrier.ts +207 -0
- package/packages/server/src/lifecycle/exit-signal.ts +43 -0
- package/packages/server/src/lifecycle/recovery-server.ts +65 -18
- package/packages/server/src/live-server/capability-redact.ts +31 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +615 -44
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +141 -0
- package/packages/server/src/live-server/live-egress.ts +435 -0
- package/packages/server/src/live-server/live-exposure.ts +149 -0
- package/packages/server/src/live-server/live-log.ts +25 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +220 -33
- package/packages/server/src/live-server/live-server-proxy.ts +411 -50
- package/packages/server/src/live-server/live-static.ts +231 -0
- package/packages/server/src/live-server/preview-dispatch.ts +286 -0
- package/packages/server/src/live-server/preview-observe.ts +53 -0
- package/packages/server/src/live-server/preview-origin.ts +182 -0
- package/packages/server/src/live-server/preview-path-bridge.ts +70 -0
- package/packages/server/src/live-server/preview-path-store.ts +420 -0
- package/packages/server/src/live-server/preview-path.ts +40 -0
- package/packages/server/src/live-server/preview-pool.ts +385 -0
- package/packages/server/src/live-server/preview-preflight.ts +41 -0
- package/packages/server/src/live-server/preview-reserve.ts +44 -0
- package/packages/server/src/live-server/preview-tier.ts +217 -0
- package/packages/server/src/live-server/preview-viewers.ts +54 -0
- package/packages/server/src/live-server/preview-ws-registry.ts +43 -0
- package/packages/server/src/model-proxy/custom-provider-discovery.ts +4 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +5 -1
- package/packages/server/src/model-proxy/internal-registry.ts +283 -21
- package/packages/server/src/model-proxy/models-block-apply.ts +291 -0
- package/packages/server/src/model-proxy/pi-models-validator.ts +164 -0
- package/packages/server/src/model-proxy/registry-singleton.ts +44 -9
- package/packages/server/src/model-proxy/server-model-runtime.ts +17 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
- package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
- package/packages/server/src/openspec/readiness.ts +1 -1
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +141 -267
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/provider-probe.ts +202 -7
- package/packages/server/src/pairing/browser-gateway.ts +325 -51
- package/packages/server/src/pairing/device-key-intake.ts +120 -0
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/paired-devices.ts +702 -27
- package/packages/server/src/pairing/pairing.ts +103 -11
- package/packages/server/src/pairing/{subagent-resync-routing.ts → resync-requester-registry.ts} +6 -10
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/pairing/ws-tier-gate.ts +74 -0
- package/packages/server/src/pending/pending-attach-registry.ts +15 -0
- package/packages/server/src/pending/pending-initial-prompt-registry.ts +15 -0
- package/packages/server/src/persistence/memory-event-store.ts +251 -296
- package/packages/server/src/persistence/preferences-store.ts +61 -2
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-contention.ts +84 -2
- package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/host-project-trust.ts +29 -15
- package/packages/server/src/pi/pi-gateway.ts +398 -41
- package/packages/server/src/pi/provisional-registration.ts +4 -1
- package/packages/server/src/pi/resource-toggle-trust.ts +18 -7
- package/packages/server/src/pi-agent-settings.ts +95 -301
- package/packages/server/src/pi-default-remirror.ts +89 -0
- package/packages/server/src/plugin-append-event.ts +35 -0
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-entry-stats.ts +61 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-local-request.ts +207 -0
- package/packages/server/src/plugin-ownership.ts +111 -0
- package/packages/server/src/plugin-policy-registry.ts +297 -0
- package/packages/server/src/plugin-request-lane.ts +92 -16
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/preferences-relay.ts +20 -0
- package/packages/server/src/project-seed.ts +347 -0
- package/packages/server/src/push/push-transports/webhook-url.ts +8 -5
- package/packages/server/src/questions/question-store.ts +3 -2
- package/packages/server/src/routes/access-routes.ts +182 -15
- package/packages/server/src/routes/acme-routes.ts +14 -4
- package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
- package/packages/server/src/routes/canvas-types-routes.ts +20 -6
- package/packages/server/src/routes/csp-violations-routes.ts +162 -0
- package/packages/server/src/routes/file-routes.ts +640 -279
- package/packages/server/src/routes/file-write-binary-routes.ts +97 -24
- package/packages/server/src/routes/folder-project-routes.ts +18 -12
- package/packages/server/src/routes/frame-policy-routes.ts +215 -0
- package/packages/server/src/routes/git-routes.ts +340 -273
- package/packages/server/src/routes/grep-routes.ts +64 -14
- package/packages/server/src/routes/known-servers-routes.ts +189 -91
- package/packages/server/src/routes/live-server-routes.ts +572 -15
- package/packages/server/src/routes/local-proof-routes.ts +14 -0
- package/packages/server/src/routes/models-introspection-routes.ts +1 -1
- package/packages/server/src/routes/nav-intent-routes.ts +46 -0
- package/packages/server/src/routes/openspec-group-routes.ts +53 -44
- package/packages/server/src/routes/openspec-routes.ts +396 -31
- package/packages/server/src/routes/package-routes.ts +58 -10
- package/packages/server/src/routes/pairing-routes.ts +342 -17
- package/packages/server/src/routes/pi-settings-routes.ts +2 -0
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/preferences-auto-name-routes.ts +5 -2
- package/packages/server/src/routes/preferences-claude-compat-routes.ts +49 -0
- package/packages/server/src/routes/provider-auth-routes.ts +181 -10
- package/packages/server/src/routes/provider-override-routes.ts +158 -0
- package/packages/server/src/routes/provider-routes.ts +348 -86
- package/packages/server/src/routes/resource-activation-routes.ts +18 -4
- package/packages/server/src/routes/session-routes.ts +75 -25
- package/packages/server/src/routes/system-routes.ts +169 -52
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/rpc-keeper/keeper-manager.ts +196 -25
- package/packages/server/src/rpc-keeper/keeper.cjs +37 -23
- package/packages/server/src/runtime-overlay/extension-reload.ts +16 -10
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/runtime-overlay/runtime-stager.ts +4 -2
- package/packages/server/src/server.ts +1139 -291
- package/packages/server/src/services/cli-service.ts +59 -10
- package/packages/server/src/services/secrets-resolver.ts +46 -30
- package/packages/server/src/session/custom-event-group-annotation.ts +3 -3
- package/packages/server/src/session/custom-event-group-resolver.ts +10 -5
- package/packages/server/src/session/death-reason.ts +11 -7
- package/packages/server/src/session/event-status-extraction.ts +5 -1
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/memory-session-manager.ts +31 -2
- package/packages/server/src/session/open-tool-calls.ts +81 -47
- package/packages/server/src/session/pid-target.ts +127 -0
- package/packages/server/src/session/replay-compaction.ts +18 -5
- package/packages/server/src/session/replay-exit-controller.ts +221 -0
- package/packages/server/src/session/retained-transcript.ts +9 -2
- package/packages/server/src/session/seed-discovered-history.ts +85 -0
- package/packages/server/src/session/server-pid-context.ts +14 -0
- package/packages/server/src/session/session-api.ts +78 -29
- package/packages/server/src/session/session-archive.ts +7 -0
- package/packages/server/src/session/session-bootstrap.ts +9 -54
- package/packages/server/src/session/session-load-worker-pool.ts +11 -1
- package/packages/server/src/session/session-load-worker.ts +32 -4
- package/packages/server/src/spawn-process/abort-spawned-run.ts +28 -9
- package/packages/server/src/spawn-process/acp-spawn.ts +8 -2
- package/packages/server/src/spawn-process/headless-pid-registry.ts +393 -77
- package/packages/server/src/spawn-process/link-register.ts +42 -0
- package/packages/server/src/spawn-process/plugin-spawn-choice.ts +48 -0
- package/packages/server/src/spawn-process/plugin-spawn-worktree.ts +290 -0
- package/packages/server/src/spawn-process/process-classifier.ts +8 -3
- package/packages/server/src/spawn-process/process-manager.ts +61 -6
- package/packages/server/src/spawn-process/restored-identity.ts +112 -0
- package/packages/server/src/spawn-process/session-terminator.ts +179 -18
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +2 -1
- package/packages/server/src/spawn-process/spawn-failure-log.ts +9 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +44 -19
- package/packages/server/src/sudo-credential/relay.ts +337 -0
- package/packages/server/src/terminal/terminal-gateway.ts +10 -0
- package/packages/server/src/terminal/terminal-manager.ts +54 -46
- package/packages/server/src/tls/sources/acme/credentials.ts +3 -2
- package/packages/server/src/tls/sources/acme/runtime.ts +2 -1
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +2 -0
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +172 -26
- package/packages/server/src/vault/vault-routes.ts +9 -2
- package/packages/server/src/vault/vault-store.ts +87 -24
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/server/vendor/xlsx/LICENSE +201 -0
- package/packages/server/vendor/xlsx/PROVENANCE.json +13 -0
- package/packages/server/vendor/xlsx/xlsx.d.mts +1065 -0
- package/packages/server/vendor/xlsx/xlsx.mjs +28228 -0
- package/packages/shared/package.json +4 -2
- package/packages/shared/src/agent-credential-files.ts +32 -0
- package/packages/shared/src/browser-protocol.ts +285 -59
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/canvas-detect.ts +1 -1
- package/packages/shared/src/canvas-types.ts +2 -2
- package/packages/shared/src/config.ts +443 -187
- package/packages/shared/src/containment-guard.ts +45 -0
- package/packages/shared/src/credential-encryption.ts +87 -0
- package/packages/shared/src/custom-event-groups.ts +2 -0
- package/packages/shared/src/dashboard-plugin/claude-compat.ts +159 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
- package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
- package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
- package/packages/shared/src/dashboard-plugin/index.ts +2 -0
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +100 -1
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +58 -3
- package/packages/shared/src/dashboard-plugin/replay-entry-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +47 -3
- package/packages/shared/src/dashboard-plugin/slot-types.ts +9 -1
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +39 -3
- package/packages/shared/src/device-key-proof.ts +309 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +94 -27
- package/packages/shared/src/event-forward-declaration.ts +85 -12
- package/packages/shared/src/forbidden-subjects.ts +126 -14
- package/packages/shared/src/heap-limits.ts +0 -30
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/index.ts +7 -6
- package/packages/shared/src/live-server.ts +161 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +176 -0
- package/packages/shared/src/mdns-discovery.ts +25 -6
- package/packages/shared/src/models-json-reader.ts +41 -0
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/network-denial-signal.ts +15 -0
- package/packages/shared/src/node-version.ts +63 -60
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-poller.ts +3 -2
- package/packages/shared/src/pairing-knock-client.ts +135 -11
- package/packages/shared/src/pi-agent-settings-lock.ts +311 -0
- package/packages/shared/src/pi-path-compare.ts +31 -0
- package/packages/shared/src/pi-settings-schema.ts +52 -9
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +21 -11
- package/packages/shared/src/pi-trust-mirror-types.ts +38 -3
- package/packages/shared/src/pi-trust-mirror.ts +47 -11
- package/packages/shared/src/pi-trust-resource-digest.ts +261 -0
- package/packages/shared/src/pid-namespace.ts +86 -0
- package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
- package/packages/shared/src/platform/git-source.ts +88 -26
- package/packages/shared/src/platform/git.ts +14 -8
- package/packages/shared/src/platform/native-ts-register.mjs +1 -1
- package/packages/shared/src/platform/process.ts +452 -5
- package/packages/shared/src/platform/resolve-pi-shell.ts +105 -0
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/platform/spawn-runtime.ts +193 -7
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +192 -0
- package/packages/shared/src/preview-origins.ts +398 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/prompt-answer.ts +9 -5
- package/packages/shared/src/protocol.ts +187 -86
- package/packages/shared/src/provider-env-catalog.ts +413 -0
- package/packages/shared/src/provider-overrides.ts +112 -0
- package/packages/shared/src/question-types.ts +6 -0
- package/packages/shared/src/recommended-extensions.ts +97 -26
- package/packages/shared/src/recovery-timing.ts +27 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/renderer-by-ext.ts +5 -2
- package/packages/shared/src/rest-api.ts +148 -11
- package/packages/shared/src/role-schema.ts +24 -0
- package/packages/shared/src/route-tiers.ts +149 -4
- package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
- package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
- package/packages/shared/src/runtime-overlay/compat.ts +70 -6
- package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/secret-patterns.ts +49 -0
- package/packages/shared/src/server-launcher.ts +9 -1
- package/packages/shared/src/server-pinning.ts +55 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/source-matching.ts +2 -2
- package/packages/shared/src/state-replay.ts +40 -24
- package/packages/shared/src/sudo-credential.ts +71 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tool-path-resolve.ts +16 -1
- package/packages/shared/src/tool-registry/definitions.ts +5 -5
- package/packages/shared/src/tool-registry/strategies.ts +13 -12
- package/packages/shared/src/tool-workdir.ts +56 -0
- package/packages/shared/src/trusted-types-mode.ts +72 -0
- package/packages/shared/src/types.ts +134 -109
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +15 -0
- package/packages/shared/src/vertex-regions.ts +81 -0
- package/packages/shared/src/ws-message-tiers.ts +11 -3
- package/packages/extension/src/subagent-fanout-admission.ts +0 -234
- package/packages/extension/src/subagent-forward-sites.ts +0 -69
- package/packages/extension/src/subagent-frame-buffer.ts +0 -245
- package/packages/extension/src/subagent-frame-strip.ts +0 -109
- package/packages/extension/src/subagent-saturation.ts +0 -196
- package/packages/extension/src/subagent-tick-throttle.ts +0 -252
- package/packages/shared/src/anthropic-messages-source.ts +0 -8
|
@@ -12,9 +12,15 @@
|
|
|
12
12
|
* See change: improve-content-editor (live-server-preview §6).
|
|
13
13
|
*/
|
|
14
14
|
import net from "node:net";
|
|
15
|
-
import type {
|
|
16
|
-
import {
|
|
15
|
+
import type { LiveServerTarget, StaticTarget } from "@blackbelt-technology/pi-dashboard-shared/live-server.js";
|
|
16
|
+
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
17
|
+
import { isBrowserOriginated } from "./live-browser-gate.js";
|
|
18
|
+
import { type LiveCapabilityGrant, stripCapabilitySegment } from "./live-capability.js";
|
|
19
|
+
import { buildLiveCsp, type LiveCspResult } from "./live-csp.js";
|
|
20
|
+
import { registerCspReportParsers } from "./live-csp-report.js";
|
|
17
21
|
import type { LiveServerManager } from "./live-server-manager.js";
|
|
22
|
+
import { serveStatic } from "./live-static.js";
|
|
23
|
+
import { parsePreviewPath } from "./preview-path.js";
|
|
18
24
|
|
|
19
25
|
/** Dashboard cookie namespace (`pi_dash_token`, `pi_dash_device`, `pi_dash_local`, …). */
|
|
20
26
|
const DASHBOARD_COOKIE_PREFIX = "pi_dash_";
|
|
@@ -43,6 +49,10 @@ function filterSetCookie(value: string | string[] | undefined): string[] | undef
|
|
|
43
49
|
/** A request/upgrade header bag the credential stripper edits in place. */
|
|
44
50
|
type HeaderBag = Record<string, unknown>;
|
|
45
51
|
|
|
52
|
+
/** The request shape the channel classifier reads (`socket.encrypted` + headers). */
|
|
53
|
+
type ProxyRequestLike = Pick<import("node:http").IncomingMessage, "socket" | "headers">;
|
|
54
|
+
type DeviceBearerCheck = (token: string, req: ProxyRequestLike | undefined) => boolean;
|
|
55
|
+
|
|
46
56
|
/**
|
|
47
57
|
* Strip dashboard credentials from headers bound for the preview upstream:
|
|
48
58
|
* every `pi_dash_*` cookie, and an `Authorization` header that verifies as a
|
|
@@ -50,7 +60,9 @@ type HeaderBag = Record<string, unknown>;
|
|
|
50
60
|
*/
|
|
51
61
|
function stripDashboardCredentials(
|
|
52
62
|
headers: HeaderBag,
|
|
53
|
-
isDeviceBearer:
|
|
63
|
+
isDeviceBearer: DeviceBearerCheck,
|
|
64
|
+
req: ProxyRequestLike | undefined,
|
|
65
|
+
isKnownBearer: (token: string) => boolean,
|
|
54
66
|
): HeaderBag {
|
|
55
67
|
const cookie = headers.cookie;
|
|
56
68
|
if (typeof cookie === "string") {
|
|
@@ -62,11 +74,70 @@ function stripDashboardCredentials(
|
|
|
62
74
|
if (typeof authz === "string") {
|
|
63
75
|
const m = /^Bearer\s+(.+)$/i.exec(authz.trim());
|
|
64
76
|
// Device bearers and the host's own operator (`pi_op_`) bearer are dashboard credentials.
|
|
65
|
-
|
|
77
|
+
// `isDeviceBearer` judges (and records the channel of) the request; `isKnownBearer` then strips EVERY
|
|
78
|
+
// registry-known bearer, so a refused `pi_tls_` bearer is never forwarded off-hub.
|
|
79
|
+
// See change: prove-vault-bridge-tls (D4).
|
|
80
|
+
if (m && (isDeviceBearer(m[1], req) || isKnownBearer(m[1]) || m[1].startsWith("pi_op_"))) delete headers.authorization;
|
|
66
81
|
}
|
|
67
82
|
return headers;
|
|
68
83
|
}
|
|
69
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Tier 5: the upstream already serves under `prefix`, so a redirect inside it is left as is (never prefixed twice);
|
|
87
|
+
* any other root-absolute redirect, or an absolute one back to the same upstream, is rewritten into the prefix.
|
|
88
|
+
*/
|
|
89
|
+
function rewriteFullPathLocation(location: string, prefix: string, host: string, port: number): string {
|
|
90
|
+
const intoPrefix = (local: string): string => {
|
|
91
|
+
if (staysInside(local, prefix)) return local;
|
|
92
|
+
const prefixed = `${prefix}${local}`;
|
|
93
|
+
return staysInside(prefixed, prefix) ? prefixed : `${prefix}/`;
|
|
94
|
+
};
|
|
95
|
+
if (location.startsWith("/")) return intoPrefix(location);
|
|
96
|
+
try {
|
|
97
|
+
const u = new URL(location);
|
|
98
|
+
if (u.hostname === host && u.port === String(port)) return intoPrefix(`${u.pathname}${u.search}`);
|
|
99
|
+
} catch {
|
|
100
|
+
/* not an absolute URL — leave as-is */
|
|
101
|
+
}
|
|
102
|
+
return location;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Merge `Origin` into `Vary` (once): the answer of a tier-5 response depends on the request `Origin`. */
|
|
106
|
+
function mergeVaryOrigin(headers: Record<string, unknown>): void {
|
|
107
|
+
const vary = headers.vary;
|
|
108
|
+
const list = (Array.isArray(vary) ? vary.join(",") : typeof vary === "string" ? vary : "")
|
|
109
|
+
.split(",")
|
|
110
|
+
.map((v) => v.trim())
|
|
111
|
+
.filter(Boolean);
|
|
112
|
+
if (!list.some((v) => v.toLowerCase() === "origin" || v === "*")) list.push("Origin");
|
|
113
|
+
headers.vary = list.join(", ");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Tier 5 CORS (P6): only on a VALID `/preview/<pid>/` response to `Origin: null`. Overwrites whatever the upstream said
|
|
118
|
+
* (a single `ACAO: null`, never credentials), and merges `Origin` into `Vary` without duplicating it.
|
|
119
|
+
*/
|
|
120
|
+
function applyNullCors(headers: Record<string, unknown>): void {
|
|
121
|
+
for (const k of Object.keys(headers)) if (k.toLowerCase().startsWith("access-control-")) delete headers[k];
|
|
122
|
+
headers["access-control-allow-origin"] = "null";
|
|
123
|
+
mergeVaryOrigin(headers);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Tiers 1-5 carry a secret in the URL (label / pid), so `Referrer-Policy: no-referrer` REPLACES any upstream value
|
|
128
|
+
* there (design D3); the legacy path keeps "only when the app set none".
|
|
129
|
+
*/
|
|
130
|
+
function applyReferrerPolicy(headers: Record<string, unknown>, grant: LiveCapabilityGrant | undefined, capabilityPrefix: string | undefined): void {
|
|
131
|
+
if (grant && grant.tier !== "legacy") headers["referrer-policy"] = "no-referrer";
|
|
132
|
+
else if (capabilityPrefix && headers["referrer-policy"] === undefined) headers["referrer-policy"] = "no-referrer";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Tier-5 CORS: `ACAO: null` for an opaque-origin request; `Vary: Origin` is present even where no ACAO is granted. */
|
|
136
|
+
function applyTier5Cors(headers: Record<string, unknown>, requestOrigin: string | undefined): void {
|
|
137
|
+
if (requestOrigin === "null") applyNullCors(headers);
|
|
138
|
+
else mergeVaryOrigin(headers);
|
|
139
|
+
}
|
|
140
|
+
|
|
70
141
|
/**
|
|
71
142
|
* Keep an upstream redirect inside the proxied prefix (`/live/<id>` or the
|
|
72
143
|
* capability prefix). A relative or root-relative `Location` is prefixed; an
|
|
@@ -74,7 +145,8 @@ function stripDashboardCredentials(
|
|
|
74
145
|
* rewritten into the prefix so the browser stays on the dashboard origin and the
|
|
75
146
|
* single-port tunnel keeps working. Foreign absolute redirects are untouched.
|
|
76
147
|
*/
|
|
77
|
-
function rewriteLocation(location: string, prefix: string, host: string, port: number): string {
|
|
148
|
+
function rewriteLocation(location: string, prefix: string, host: string, port: number, fullPath = false): string {
|
|
149
|
+
if (fullPath) return rewriteFullPathLocation(location, prefix, host, port);
|
|
78
150
|
const relative = location.startsWith("./") ? `${prefix}/${location.slice(2)}` : location.startsWith("/") ? `${prefix}${location}` : null;
|
|
79
151
|
if (relative !== null) return staysInside(relative, prefix) ? relative : `${prefix}/`;
|
|
80
152
|
try {
|
|
@@ -104,8 +176,67 @@ function staysInside(path: string, prefix: string): boolean {
|
|
|
104
176
|
}
|
|
105
177
|
|
|
106
178
|
export interface LiveProxyDeps {
|
|
107
|
-
/**
|
|
108
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Is this absolute URL an origin the dashboard app itself is served on (host-admitted, dashboard port, not preview-shaped)?
|
|
181
|
+
* Tiers 1-4 never deliver an upstream `Location` / `Refresh` aimed at it (D3(c)). Absent ⇒ no containment.
|
|
182
|
+
* See change: serve-live-previews-on-capability-origin (D3(c), T.F40).
|
|
183
|
+
*/
|
|
184
|
+
isDashboardUrl?: (url: URL) => boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Does this token verify as a dashboard device bearer on THIS request's channel? Absent ⇒ never
|
|
187
|
+
* strip `Authorization`. Receives the request so the registry can record a non-proven channel.
|
|
188
|
+
*/
|
|
189
|
+
isDeviceBearer?: DeviceBearerCheck;
|
|
190
|
+
/** Is this token ANY bearer the registry knows (valid, expired or refused)? Always stripped. */
|
|
191
|
+
isKnownBearer?: (token: string) => boolean;
|
|
192
|
+
/**
|
|
193
|
+
* The raw file-read gate for a static target's real path, re-run on EVERY static
|
|
194
|
+
* request. Absent ⇒ static targets serve nothing (fail closed).
|
|
195
|
+
*/
|
|
196
|
+
staticGate?: (cwd: string, absPath: string) => Promise<boolean>;
|
|
197
|
+
/**
|
|
198
|
+
* Granted egress origins `<G>` for a token's CSP: project grants ∪ the viewer's
|
|
199
|
+
* allow-once set. Absent ⇒ none.
|
|
200
|
+
*/
|
|
201
|
+
grantedOrigins?: (grant: LiveCapabilityGrant) => readonly string[];
|
|
202
|
+
/** An HTML document of a static target was served under this token (feeds the lazy origin scan). */
|
|
203
|
+
onStaticHtmlServed?: (grant: LiveCapabilityGrant, realPath: string) => void;
|
|
204
|
+
/**
|
|
205
|
+
* Handler for the reserved `/__pi/…` namespace under a valid capability prefix
|
|
206
|
+
* (CSP reports, …). It is never forwarded upstream and never served from disk;
|
|
207
|
+
* absent ⇒ 404. Return the reply you sent.
|
|
208
|
+
*/
|
|
209
|
+
reservedHandler?: (
|
|
210
|
+
request: FastifyRequest,
|
|
211
|
+
reply: FastifyReply,
|
|
212
|
+
ctx: { grant: LiveCapabilityGrant; subPath: string },
|
|
213
|
+
) => Promise<FastifyReply> | FastifyReply;
|
|
214
|
+
/**
|
|
215
|
+
* Tier 5: a `/preview/<pid>/` response is now in flight. The pid's drop destroys it, so a revoked preview cannot keep an
|
|
216
|
+
* HTTP stream (SSE, long download) open to its dev server (test-plan #P11).
|
|
217
|
+
*/
|
|
218
|
+
trackPreviewResponse?: (pid: string, res: import("node:http").ServerResponse) => void;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** `/__pi` as a whole path segment (the reserved namespace under a capability prefix). */
|
|
222
|
+
const isReservedPath = (subPath: string): boolean => {
|
|
223
|
+
const q = subPath.search(/[?#]/);
|
|
224
|
+
const p = q >= 0 ? subPath.slice(0, q) : subPath;
|
|
225
|
+
return p === "/__pi" || p.startsWith("/__pi/");
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/** The scheme the dashboard is reached on, as far as this hop can tell. `http` is the safe default (`http://` matches https too). */
|
|
229
|
+
const schemeOf = (request: FastifyRequest): "http" | "https" => (request.protocol === "https" ? "https" : "http");
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* APPEND our CSP to the upstream's response headers —
|
|
233
|
+
* never replacing or stripping the upstream's: browsers enforce every header, so the
|
|
234
|
+
* result is the stricter intersection.
|
|
235
|
+
*/
|
|
236
|
+
function appendCsp(headers: Record<string, unknown>, csp: LiveCspResult): void {
|
|
237
|
+
const upstreamCsp = headers["content-security-policy"];
|
|
238
|
+
const existing = upstreamCsp === undefined ? [] : Array.isArray(upstreamCsp) ? upstreamCsp : [upstreamCsp];
|
|
239
|
+
headers["content-security-policy"] = [...existing, csp.csp];
|
|
109
240
|
}
|
|
110
241
|
|
|
111
242
|
/** localhost/::1 resolve to 127.0.0.1 for the upstream TCP connect. */
|
|
@@ -113,54 +244,158 @@ function upstreamHost(host: string): string {
|
|
|
113
244
|
return host === "::1" ? "::1" : "127.0.0.1";
|
|
114
245
|
}
|
|
115
246
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
247
|
+
/**
|
|
248
|
+
* A preview-origin request reaches the upstream as if the browser had been talking to it directly:
|
|
249
|
+
* `Origin` (except the opaque `null`) and a same-origin `Referer` are rewritten to the upstream origin.
|
|
250
|
+
*/
|
|
251
|
+
function rewritePreviewOrigin(headers: HeaderBag, upstreamOrigin: string, previewHost: string | undefined): void {
|
|
252
|
+
if (typeof headers.origin === "string" && headers.origin !== "null") headers.origin = upstreamOrigin;
|
|
253
|
+
if (typeof headers.referer === "string") {
|
|
254
|
+
try {
|
|
255
|
+
const r = new URL(headers.referer);
|
|
256
|
+
if (r.host === previewHost) headers.referer = `${upstreamOrigin}${r.pathname}${r.search}`;
|
|
257
|
+
} catch {
|
|
258
|
+
delete headers.referer;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
129
262
|
|
|
263
|
+
/** `url=<target>` of a `Refresh` header value (`0; url=http://x/`, `5;URL='x'`); `null` when it names none. */
|
|
264
|
+
function refreshTarget(value: string): string | null {
|
|
265
|
+
const m = /;\s*url\s*=\s*(?:"([^"]*)"|'([^']*)'|([^;]*))/i.exec(value);
|
|
266
|
+
const raw = (m?.[1] ?? m?.[2] ?? m?.[3] ?? "").trim();
|
|
267
|
+
return raw === "" ? null : raw;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** The absolute http(s) URL `value` names, or `null` for a relative / non-http / malformed one (those resolve on the preview origin). */
|
|
271
|
+
function absoluteHttpUrl(value: string): URL | null {
|
|
272
|
+
try {
|
|
273
|
+
const u = new URL(value);
|
|
274
|
+
return u.protocol === "http:" || u.protocol === "https:" ? u : null;
|
|
275
|
+
} catch {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* D3(c), tiers 1-4: an upstream must not steer the frame onto the dashboard origin by header. A `Refresh` whose
|
|
282
|
+
* target is a dashboard origin is dropped; such a `Location` is rewritten onto the preview origin (same path + query).
|
|
283
|
+
* JS and `<meta refresh>` navigation are not header-contained: the client guard (D6/D7) handles them.
|
|
284
|
+
*/
|
|
285
|
+
export function containDashboardRedirects(headers: Record<string, unknown>, previewOrigin: string, isDashboardUrl: (u: URL) => boolean): void {
|
|
286
|
+
const dashboard = (v: string): URL | null => {
|
|
287
|
+
const u = absoluteHttpUrl(v);
|
|
288
|
+
return u && u.origin !== previewOrigin && isDashboardUrl(u) ? u : null;
|
|
289
|
+
};
|
|
290
|
+
if (typeof headers.refresh === "string") {
|
|
291
|
+
const target = refreshTarget(headers.refresh);
|
|
292
|
+
if (target !== null && dashboard(target)) delete headers.refresh;
|
|
293
|
+
}
|
|
294
|
+
if (typeof headers.location === "string") {
|
|
295
|
+
const u = dashboard(headers.location);
|
|
296
|
+
if (u) headers.location = `${previewOrigin}${u.pathname}${u.search}${u.hash}`;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Options of a forwarded port request that differ between `/live/<id>` and a preview origin. */
|
|
301
|
+
export interface ForwardPortOptions {
|
|
302
|
+
/** Preview origin: the browser's `Origin`/`Referer` carry the preview origin, which the upstream must see as itself. */
|
|
303
|
+
rewriteOrigin?: boolean;
|
|
130
304
|
/**
|
|
131
|
-
* `
|
|
132
|
-
*
|
|
133
|
-
*
|
|
305
|
+
* Tier 5: `subPath` is relative to `capabilityPrefix` (reserved-path / CSP decisions) but the upstream receives the
|
|
306
|
+
* FULL `<prefix><subPath>` — the site was started under that base (D8) — and a `Location` already inside the
|
|
307
|
+
* prefix is left alone instead of being prefixed again.
|
|
134
308
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!target) return null;
|
|
140
|
-
let rest = match[2] || "";
|
|
141
|
-
if (capabilityPrefix && url.startsWith(capabilityPrefix)) rest = url.slice(capabilityPrefix.length);
|
|
142
|
-
const subPath = rest.startsWith("?") ? `/${rest}` : rest.startsWith("/") ? rest : "/";
|
|
143
|
-
return { target, subPath };
|
|
144
|
-
}
|
|
309
|
+
fullPath?: boolean;
|
|
310
|
+
/** Tier 5: a valid response to an opaque `Origin: null` gets `Access-Control-Allow-Origin: null` (no credentials). */
|
|
311
|
+
nullCors?: boolean;
|
|
312
|
+
}
|
|
145
313
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
314
|
+
/**
|
|
315
|
+
* The target-forwarding core shared by the main-origin `/live/:id/*` proxy and the preview-origin
|
|
316
|
+
* `previewApp` (D3): one CSP/cookie/credential/redirect policy, two entry points. The caller's
|
|
317
|
+
* Fastify instance must have `@fastify/reply-from` registered.
|
|
318
|
+
*/
|
|
319
|
+
export function createLiveForwarder(manager: LiveServerManager, deps: LiveProxyDeps = {}) {
|
|
320
|
+
const isDeviceBearer = deps.isDeviceBearer ?? (() => false);
|
|
321
|
+
const isKnownBearer = deps.isKnownBearer ?? (() => false);
|
|
322
|
+
|
|
323
|
+
/** CSP for a capability response, or `null` (fail closed) when no safe header can be built. */
|
|
324
|
+
function cspFor(request: FastifyRequest, grant: LiveCapabilityGrant, prefix: string): LiveCspResult | null {
|
|
325
|
+
const host = request.headers.host;
|
|
326
|
+
if (typeof host !== "string") return null;
|
|
327
|
+
let granted: readonly string[] = [];
|
|
328
|
+
try {
|
|
329
|
+
granted = deps.grantedOrigins?.(grant) ?? [];
|
|
330
|
+
} catch {
|
|
331
|
+
granted = []; // a failing grant lookup must not widen the policy
|
|
151
332
|
}
|
|
152
|
-
|
|
333
|
+
// Tiers 1-4 are origin-bound: the policy comes from the entry, not from the request Host / scheme (D6).
|
|
334
|
+
const bound = grant.tier !== "legacy" && grant.tier !== 5;
|
|
335
|
+
if (bound && grant.origin === undefined) return null; // an origin-bound entry without its origin: fail closed
|
|
336
|
+
return buildLiveCsp({
|
|
337
|
+
policy: grant.policy,
|
|
338
|
+
host,
|
|
339
|
+
scheme: schemeOf(request),
|
|
340
|
+
prefix,
|
|
341
|
+
granted,
|
|
342
|
+
...(bound ? { origin: grant.origin, ancestors: grant.ancestors } : {}),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const notFoundReply = (reply: FastifyReply) => reply.code(404).send({ error: "live-server target not found" });
|
|
347
|
+
|
|
348
|
+
/** A static target, reachable ONLY through a valid capability, by any caller. */
|
|
349
|
+
const forwardStatic = (
|
|
350
|
+
request: FastifyRequest,
|
|
351
|
+
reply: FastifyReply,
|
|
352
|
+
target: StaticTarget,
|
|
353
|
+
subPath: string,
|
|
354
|
+
grant: LiveCapabilityGrant | undefined,
|
|
355
|
+
capabilityPrefix: string | undefined,
|
|
356
|
+
) => {
|
|
357
|
+
if (!grant || capabilityPrefix === undefined) return notFoundReply(reply);
|
|
358
|
+
if (isReservedPath(subPath)) return reservedOr404(request, reply, grant, subPath);
|
|
359
|
+
const csp = cspFor(request, grant, capabilityPrefix);
|
|
360
|
+
if (!csp) return notFoundReply(reply);
|
|
361
|
+
manager.use(target.id);
|
|
362
|
+
const extra: Record<string, string> = { "content-security-policy": csp.csp };
|
|
363
|
+
return serveStatic(request, reply, target, subPath, extra, {
|
|
364
|
+
gate: deps.staticGate ?? (async () => false),
|
|
365
|
+
onHtmlServed: (real) => deps.onStaticHtmlServed?.(grant, real),
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const forwardPort = (
|
|
370
|
+
request: FastifyRequest,
|
|
371
|
+
reply: FastifyReply,
|
|
372
|
+
target: LiveServerTarget,
|
|
373
|
+
subPath: string,
|
|
374
|
+
grant: LiveCapabilityGrant | undefined,
|
|
375
|
+
capabilityPrefix: string | undefined,
|
|
376
|
+
opts: ForwardPortOptions = {},
|
|
377
|
+
) => {
|
|
378
|
+
if (grant && isReservedPath(subPath)) return reservedOr404(request, reply, grant, subPath);
|
|
379
|
+
const csp = grant && capabilityPrefix !== undefined ? cspFor(request, grant, capabilityPrefix) : null;
|
|
380
|
+
// A capability response without a buildable CSP would be less isolated than promised.
|
|
381
|
+
if (grant && !csp) return notFoundReply(reply);
|
|
382
|
+
manager.use(target.id);
|
|
153
383
|
// Redirects stay inside the capability prefix when the request used one.
|
|
154
384
|
const prefix = capabilityPrefix ?? `/live/${target.id}`;
|
|
155
385
|
const host = upstreamHost(target.host);
|
|
156
|
-
|
|
386
|
+
const upstreamPath = opts.fullPath && capabilityPrefix !== undefined ? `${capabilityPrefix}${subPath}` : subPath;
|
|
387
|
+
reply.from(`http://${host}:${target.port}${upstreamPath}`, {
|
|
157
388
|
rewriteRequestHeaders: (_req, headers) => {
|
|
158
389
|
headers.host = `${host}:${target.port}`;
|
|
159
390
|
// Dashboard credentials never reach the previewed app; its own cookies
|
|
160
391
|
// and bearer pass through. See change: retire-trusted-networks-bypass (D5).
|
|
161
|
-
stripDashboardCredentials(headers as HeaderBag, isDeviceBearer);
|
|
392
|
+
stripDashboardCredentials(headers as HeaderBag, isDeviceBearer, request.raw, isKnownBearer);
|
|
393
|
+
// The hop to the loopback upstream is a PROXIED hop: mark it so nothing the
|
|
394
|
+
// upstream does with this request can pass for "genuinely local".
|
|
395
|
+
headers["x-forwarded-for"] = [headers["x-forwarded-for"], request.ip].filter(Boolean).join(", ");
|
|
162
396
|
// A forwarded Referer must not carry the capability token upstream.
|
|
163
397
|
if (typeof headers.referer === "string") headers.referer = stripCapabilitySegment(headers.referer);
|
|
398
|
+
if (opts.rewriteOrigin) rewritePreviewOrigin(headers as HeaderBag, `http://${host}:${target.port}`, request.headers.host);
|
|
164
399
|
return headers;
|
|
165
400
|
},
|
|
166
401
|
rewriteHeaders: (headers) => {
|
|
@@ -168,22 +403,98 @@ export function registerLiveServerProxy(
|
|
|
168
403
|
const setCookie = filterSetCookie(headers["set-cookie"] as string | string[] | undefined);
|
|
169
404
|
if (setCookie === undefined) delete headers["set-cookie"];
|
|
170
405
|
else headers["set-cookie"] = setCookie;
|
|
171
|
-
// The token is in this page's URL: keep it out of Referer headers the
|
|
172
|
-
|
|
173
|
-
if (
|
|
174
|
-
|
|
406
|
+
// The token is in this page's URL: keep it out of Referer headers the page sends to third parties.
|
|
407
|
+
applyReferrerPolicy(headers, grant, capabilityPrefix);
|
|
408
|
+
if (csp) appendCsp(headers, csp);
|
|
409
|
+
if (opts.nullCors) applyTier5Cors(headers, request.headers.origin);
|
|
410
|
+
if (grant && grant.tier !== "legacy" && grant.tier !== 5 && grant.origin !== undefined && deps.isDashboardUrl) {
|
|
411
|
+
containDashboardRedirects(headers, grant.origin, deps.isDashboardUrl);
|
|
175
412
|
}
|
|
176
413
|
const location = headers.location;
|
|
177
414
|
if (typeof location === "string") {
|
|
178
|
-
headers.location = rewriteLocation(location, prefix, host, target.port);
|
|
415
|
+
headers.location = rewriteLocation(location, prefix, host, target.port, opts.fullPath === true);
|
|
179
416
|
}
|
|
180
417
|
return headers;
|
|
181
418
|
},
|
|
182
419
|
});
|
|
183
420
|
};
|
|
184
421
|
|
|
422
|
+
const reservedOr404 = (request: FastifyRequest, reply: FastifyReply, grant: LiveCapabilityGrant, subPath: string) =>
|
|
423
|
+
deps.reservedHandler
|
|
424
|
+
? deps.reservedHandler(request, reply, { grant, subPath })
|
|
425
|
+
: notFoundReply(reply);
|
|
426
|
+
|
|
427
|
+
return { forwardStatic, forwardPort, notFoundReply, cspFor, reservedOr404 };
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export function registerLiveServerProxy(
|
|
431
|
+
fastify: FastifyInstance,
|
|
432
|
+
manager: LiveServerManager,
|
|
433
|
+
deps: LiveProxyDeps = {},
|
|
434
|
+
) {
|
|
435
|
+
// Register the `@fastify/reply-from` proxy plugin. live-server-proxy is now
|
|
436
|
+
// the SOLE consumer of the `from` decorator — the editor proxy that used to
|
|
437
|
+
// provide it was deleted in change: remove-external-editor-integration, which
|
|
438
|
+
// orphaned this call and produced `reply.from is not a function` on
|
|
439
|
+
// `/live/:id/*`. Owning the dependency here keeps the proxy self-contained.
|
|
440
|
+
// See change: improve-content-editor, fix-live-server-proxy-reply-from.
|
|
441
|
+
fastify.register(import("@fastify/reply-from"));
|
|
442
|
+
// CSP reports arrive as `application/csp-report` / `application/reports+json`.
|
|
443
|
+
if (deps.reservedHandler) registerCspReportParsers(fastify);
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* `capabilityPrefix` is set (by the capability hook, only after the token
|
|
447
|
+
* validated) when the request arrived under `/live/<id>/~c/<token>/`: that
|
|
448
|
+
* exact segment is removed from the upstream path and kept in redirects.
|
|
449
|
+
*/
|
|
450
|
+
function resolve(url: string, capabilityPrefix?: string) {
|
|
451
|
+
const match = url.match(/^\/live\/([^/?]+)(.*)$/);
|
|
452
|
+
if (!match) return null;
|
|
453
|
+
let rest = match[2] || "";
|
|
454
|
+
if (capabilityPrefix && url.startsWith(capabilityPrefix)) rest = url.slice(capabilityPrefix.length);
|
|
455
|
+
const subPath = rest.startsWith("?") ? `/${rest}` : rest.startsWith("/") ? rest : "/";
|
|
456
|
+
return { id: match[1], subPath };
|
|
457
|
+
}
|
|
458
|
+
const { forwardStatic, forwardPort, notFoundReply } = createLiveForwarder(manager, deps);
|
|
459
|
+
|
|
460
|
+
const forward = (request: FastifyRequest, reply: FastifyReply) => {
|
|
461
|
+
const capabilityPrefix = (request as { liveCapabilityPrefix?: string }).liveCapabilityPrefix;
|
|
462
|
+
const grant = (request as { liveCapability?: LiveCapabilityGrant }).liveCapability;
|
|
463
|
+
// A browser-originated request (opaque `Origin: null` / `Sec-Fetch-*`) needs a capability.
|
|
464
|
+
if (!grant && isBrowserOriginated(request.headers as Record<string, unknown>)) return notFoundReply(reply);
|
|
465
|
+
const resolved = resolve(request.url, capabilityPrefix);
|
|
466
|
+
if (!resolved) return notFoundReply(reply);
|
|
467
|
+
const { id, subPath } = resolved;
|
|
468
|
+
const staticTarget = manager.getStatic(id);
|
|
469
|
+
if (staticTarget) return forwardStatic(request, reply, staticTarget, subPath, grant, capabilityPrefix);
|
|
470
|
+
const target = manager.get(id);
|
|
471
|
+
if (!target) return notFoundReply(reply);
|
|
472
|
+
return forwardPort(request, reply, target, subPath, grant, capabilityPrefix);
|
|
473
|
+
};
|
|
474
|
+
|
|
185
475
|
fastify.all("/live/:id/*", forward);
|
|
186
476
|
fastify.all("/live/:id", forward);
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Tier 5 (D8): `/preview/<pid>[/…]`. The capability hook validated the pid and set `liveCapability`; any request
|
|
480
|
+
* without one (browser-originated or not) is 404, as is a path the raw-path validator refuses.
|
|
481
|
+
*/
|
|
482
|
+
const forwardPreview = (request: FastifyRequest, reply: FastifyReply) => {
|
|
483
|
+
const grant = (request as { liveCapability?: LiveCapabilityGrant }).liveCapability;
|
|
484
|
+
const path = parsePreviewPath(request.raw.url);
|
|
485
|
+
if (!grant || grant.tier !== 5 || !path) return notFoundReply(reply);
|
|
486
|
+
const target = manager.get(grant.targetId);
|
|
487
|
+
if (!target) return notFoundReply(reply);
|
|
488
|
+
deps.trackPreviewResponse?.(path.pid, reply.raw);
|
|
489
|
+
return forwardPort(request, reply, target, path.rest, grant, path.prefix, { fullPath: true, nullCors: true });
|
|
490
|
+
};
|
|
491
|
+
// A dead or resetting upstream is a bad gateway (never a dashboard 500), like the preview-origin and pool forwarders.
|
|
492
|
+
const badGateway = (error: { statusCode?: number }, _request: FastifyRequest, reply: FastifyReply) => {
|
|
493
|
+
const status = error.statusCode !== undefined && error.statusCode < 500 ? error.statusCode : error.statusCode === 504 ? 504 : 502;
|
|
494
|
+
return reply.code(status).header("cache-control", "no-store").type("application/json").send({ error: status === 502 ? "bad_gateway" : status === 504 ? "gateway_timeout" : "bad_request" });
|
|
495
|
+
};
|
|
496
|
+
fastify.all("/preview/:pid/*", { errorHandler: badGateway }, forwardPreview);
|
|
497
|
+
fastify.all("/preview/:pid", { errorHandler: badGateway }, forwardPreview);
|
|
187
498
|
}
|
|
188
499
|
|
|
189
500
|
/** Longest upstream 101 head we will buffer before giving up. */
|
|
@@ -205,6 +516,7 @@ function forwardHandshakeFiltered(upstream: net.Socket, socket: import("node:str
|
|
|
205
516
|
return;
|
|
206
517
|
}
|
|
207
518
|
upstream.off("data", onData);
|
|
519
|
+
upstream.setTimeout(0); // the handshake finished: the pipe owns the socket lifetime from here
|
|
208
520
|
const headText = buf.subarray(0, end).toString("latin1");
|
|
209
521
|
const filtered = headText
|
|
210
522
|
.split("\r\n")
|
|
@@ -225,32 +537,62 @@ export function handleLiveServerUpgrade(
|
|
|
225
537
|
deps: LiveProxyDeps & {
|
|
226
538
|
/** `/live/<id>/~c/<token>` when the upgrade was admitted by a validated capability. */
|
|
227
539
|
capabilityPrefix?: string;
|
|
540
|
+
/** Tier 5: the upgrade was admitted by a valid `/preview/<pid>/` capability for this target; the FULL path is forwarded. */
|
|
541
|
+
previewTargetId?: string;
|
|
228
542
|
} = {},
|
|
229
543
|
) {
|
|
544
|
+
if (deps.previewTargetId !== undefined) return upgradePreview(manager, request, socket, head, deps, deps.previewTargetId);
|
|
230
545
|
const match = request.url?.match(/^\/live\/([^/?]+)(.*)$/);
|
|
231
546
|
if (!match) {
|
|
232
547
|
socket.destroy();
|
|
233
548
|
return;
|
|
234
549
|
}
|
|
550
|
+
// A browser-originated upgrade (opaque `Origin: null` / `Sec-Fetch-*`) needs a capability.
|
|
551
|
+
if (!deps.capabilityPrefix && isBrowserOriginated(request.headers as Record<string, unknown>)) {
|
|
552
|
+
socket.destroy();
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
235
555
|
const target = manager.get(match[1]);
|
|
236
556
|
if (!target) {
|
|
237
557
|
socket.destroy();
|
|
238
558
|
return;
|
|
239
559
|
}
|
|
560
|
+
manager.use(target.id);
|
|
240
561
|
const capabilityPrefix = deps.capabilityPrefix;
|
|
241
562
|
let rest = match[2] || "";
|
|
242
563
|
if (capabilityPrefix && request.url?.startsWith(capabilityPrefix)) rest = request.url.slice(capabilityPrefix.length);
|
|
243
564
|
const subPath = rest.startsWith("?") ? `/${rest}` : rest.startsWith("/") ? rest : "/";
|
|
565
|
+
pipeUpgradeToTarget(target, subPath, request, socket, head, deps);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Open the upstream socket for an admitted upgrade and pipe both directions. Shared by the
|
|
570
|
+
* main-origin `/live/<id>` upgrade and the preview-origin upgrade (D3). The browser `Origin` is
|
|
571
|
+
* never forwarded; `Host` is rewritten to the upstream.
|
|
572
|
+
*/
|
|
573
|
+
export function pipeUpgradeToTarget(
|
|
574
|
+
target: LiveServerTarget,
|
|
575
|
+
subPath: string,
|
|
576
|
+
request: import("node:http").IncomingMessage,
|
|
577
|
+
socket: import("node:stream").Duplex,
|
|
578
|
+
head: Buffer,
|
|
579
|
+
deps: LiveProxyDeps,
|
|
580
|
+
) {
|
|
244
581
|
const host = upstreamHost(target.host);
|
|
245
582
|
const isDeviceBearer = deps.isDeviceBearer ?? (() => false);
|
|
583
|
+
const isKnownBearer = deps.isKnownBearer ?? (() => false);
|
|
246
584
|
|
|
247
585
|
const upstream = net.connect(target.port, host, () => {
|
|
248
|
-
//
|
|
249
|
-
//
|
|
250
|
-
|
|
586
|
+
// The handshake timeout below stays armed until the upstream's 101 head is complete
|
|
587
|
+
// (`forwardHandshakeFiltered` clears it): an upstream that accepts TCP and never answers the upgrade
|
|
588
|
+
// must not hold the socket pair open forever.
|
|
251
589
|
// Dashboard credentials never reach the previewed app (same rule as the
|
|
252
590
|
// HTTP path); a forwarded Referer loses any capability segment.
|
|
253
|
-
const forwarded = stripDashboardCredentials({ ...request.headers } as HeaderBag, isDeviceBearer);
|
|
591
|
+
const forwarded = stripDashboardCredentials({ ...request.headers } as HeaderBag, isDeviceBearer, request, isKnownBearer);
|
|
592
|
+
// A proxied hop: the upstream must never see this upgrade as genuinely local.
|
|
593
|
+
forwarded["x-forwarded-for"] = [forwarded["x-forwarded-for"], request.socket?.remoteAddress]
|
|
594
|
+
.filter(Boolean)
|
|
595
|
+
.join(", ");
|
|
254
596
|
if (typeof forwarded.referer === "string") forwarded.referer = stripCapabilitySegment(forwarded.referer);
|
|
255
597
|
const headers = Object.entries(forwarded)
|
|
256
598
|
.filter(([k]) => !["host", "origin"].includes(k.toLowerCase()))
|
|
@@ -273,3 +615,22 @@ export function handleLiveServerUpgrade(
|
|
|
273
615
|
socket.on("close", () => upstream.destroy());
|
|
274
616
|
upstream.on("close", () => socket.destroy());
|
|
275
617
|
}
|
|
618
|
+
|
|
619
|
+
/** Tier 5 upgrade: re-parse the raw path (never trust the caller) and pipe the FULL path to the target. */
|
|
620
|
+
function upgradePreview(
|
|
621
|
+
manager: LiveServerManager,
|
|
622
|
+
request: import("node:http").IncomingMessage,
|
|
623
|
+
socket: import("node:stream").Duplex,
|
|
624
|
+
head: Buffer,
|
|
625
|
+
deps: LiveProxyDeps,
|
|
626
|
+
targetId: string,
|
|
627
|
+
) {
|
|
628
|
+
const path = parsePreviewPath(request.url);
|
|
629
|
+
const target = path ? manager.get(targetId) : undefined;
|
|
630
|
+
if (!path || !target) {
|
|
631
|
+
socket.destroy();
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
manager.use(target.id);
|
|
635
|
+
pipeUpgradeToTarget(target, request.url as string, request, socket, head, deps);
|
|
636
|
+
}
|