synabun 2.4.1 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +46 -6
- package/lib/data-home-files.js +4 -2
- package/lib/first-launch-protection.js +8 -2
- package/lib/release-npm-ci.mjs +23 -1
- package/lib/update-snapshot.js +11 -4
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +25 -2
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +62 -17
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-bench.d.ts +22 -22
- package/mcp-server/dist/services/memory-maintenance.d.ts +1 -0
- package/mcp-server/dist/services/memory-maintenance.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-maintenance.js +34 -45
- package/mcp-server/dist/services/memory-maintenance.js.map +1 -1
- package/mcp-server/dist/services/memory-migration-copy.d.ts +144 -0
- package/mcp-server/dist/services/memory-migration-copy.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-copy.js +467 -0
- package/mcp-server/dist/services/memory-migration-copy.js.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts +2 -0
- package/mcp-server/dist/services/memory-migration-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/memory-migration-worker.js +60 -0
- package/mcp-server/dist/services/memory-migration-worker.js.map +1 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts +4 -0
- package/mcp-server/dist/services/memory-retrieval.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-retrieval.js +188 -40
- package/mcp-server/dist/services/memory-retrieval.js.map +1 -1
- package/mcp-server/dist/services/memory-schema.d.ts +58 -2
- package/mcp-server/dist/services/memory-schema.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-schema.js +190 -13
- package/mcp-server/dist/services/memory-schema.js.map +1 -1
- package/mcp-server/dist/services/memory-sessions.d.ts +19 -1
- package/mcp-server/dist/services/memory-sessions.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-sessions.js +56 -20
- package/mcp-server/dist/services/memory-sessions.js.map +1 -1
- package/mcp-server/dist/services/memory-verification.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-verification.js +8 -5
- package/mcp-server/dist/services/memory-verification.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +5 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +19 -2
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts +2 -0
- package/mcp-server/dist/services/retrieval-reader-worker.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js +76 -0
- package/mcp-server/dist/services/retrieval-reader-worker.js.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts +38 -0
- package/mcp-server/dist/services/retrieval-reader.d.ts.map +1 -0
- package/mcp-server/dist/services/retrieval-reader.js +145 -0
- package/mcp-server/dist/services/retrieval-reader.js.map +1 -0
- package/mcp-server/dist/services/sqlite-write.d.ts +14 -0
- package/mcp-server/dist/services/sqlite-write.d.ts.map +1 -0
- package/mcp-server/dist/services/sqlite-write.js +94 -0
- package/mcp-server/dist/services/sqlite-write.js.map +1 -0
- package/mcp-server/dist/services/sqlite.d.ts +39 -0
- package/mcp-server/dist/services/sqlite.d.ts.map +1 -1
- package/mcp-server/dist/services/sqlite.js +249 -8
- package/mcp-server/dist/services/sqlite.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.d.ts +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +7 -1
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +32 -10
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/services/typesafe.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe.js +9 -7
- package/mcp-server/dist/services/typesafe.js.map +1 -1
- package/mcp-server/dist/services/vector-cache.d.ts +32 -0
- package/mcp-server/dist/services/vector-cache.d.ts.map +1 -1
- package/mcp-server/dist/services/vector-cache.js +161 -8
- package/mcp-server/dist/services/vector-cache.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +11 -7
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +27 -9
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +10 -3
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts +5 -0
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-extension-setup.js +29 -0
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -0
- package/mcp-server/dist/tools/browser-interact.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-interact.js +6 -1
- package/mcp-server/dist/tools/browser-interact.js.map +1 -1
- package/mcp-server/dist/tools/fb-groups.d.ts +2 -2
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/tool-groups.d.ts +1 -1
- package/mcp-server/package-lock.json +5 -5
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +20 -2
- package/mcp-server/src/index.ts +59 -17
- package/mcp-server/src/services/memory-maintenance.ts +31 -28
- package/mcp-server/src/services/memory-migration-copy.ts +419 -0
- package/mcp-server/src/services/memory-migration-worker.ts +55 -0
- package/mcp-server/src/services/memory-retrieval.ts +173 -32
- package/mcp-server/src/services/memory-schema.ts +194 -12
- package/mcp-server/src/services/memory-sessions.ts +54 -21
- package/mcp-server/src/services/memory-verification.ts +7 -4
- package/mcp-server/src/services/neural-interface.ts +22 -2
- package/mcp-server/src/services/retrieval-reader-worker.ts +67 -0
- package/mcp-server/src/services/retrieval-reader.ts +131 -0
- package/mcp-server/src/services/sqlite-write.ts +60 -0
- package/mcp-server/src/services/sqlite.ts +246 -8
- package/mcp-server/src/services/typesafe-config.ts +25 -6
- package/mcp-server/src/services/typesafe.ts +9 -7
- package/mcp-server/src/services/vector-cache.ts +154 -9
- package/mcp-server/src/tools/agents.ts +26 -9
- package/mcp-server/src/tools/browser-advanced.ts +10 -3
- package/mcp-server/src/tools/browser-extension-setup.ts +36 -0
- package/mcp-server/src/tools/browser-interact.ts +5 -1
- package/neural-interface/i18n/en.json +313 -2
- package/neural-interface/i18n/pt-BR.json +321 -10
- package/neural-interface/lib/agents/split.js +32 -4
- package/neural-interface/lib/assistant-api.js +52 -8
- package/neural-interface/lib/assistant-brains/claude.js +2 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-catalog.js +2 -2
- package/neural-interface/lib/assistant-config.js +0 -7
- package/neural-interface/lib/assistant-dispatch.js +281 -95
- package/neural-interface/lib/assistant-envelope.js +40 -0
- package/neural-interface/lib/assistant-persona.js +16 -4
- package/neural-interface/lib/assistant-pricing.js +65 -14
- package/neural-interface/lib/assistant-router.js +131 -47
- package/neural-interface/lib/assistant-run-wait.js +45 -28
- package/neural-interface/lib/assistant-runtime.js +133 -42
- package/neural-interface/lib/backup-contents.js +158 -0
- package/neural-interface/lib/backup-crypto-io.js +330 -0
- package/neural-interface/lib/backup-crypto-worker.js +130 -0
- package/neural-interface/lib/backup-crypto.js +525 -0
- package/neural-interface/lib/backup-download.js +268 -0
- package/neural-interface/lib/backup-encryption.js +318 -0
- package/neural-interface/lib/backup-groups.js +287 -0
- package/neural-interface/lib/backup-restore-session.js +176 -0
- package/neural-interface/lib/backup-restore-stage.js +60 -0
- package/neural-interface/lib/backup-service.js +788 -233
- package/neural-interface/lib/backup-zip-reader.js +30 -18
- package/neural-interface/lib/backup-zip-writer.js +34 -10
- package/neural-interface/lib/browser-extension-adapter.js +89 -15
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +24 -10
- package/neural-interface/lib/browser-extension-folder.js +596 -76
- package/neural-interface/lib/browser-extension-package.js +200 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +33 -0
- package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +91 -6
- package/neural-interface/lib/browser-extension-setup.js +105 -18
- package/neural-interface/lib/claude-agent-bridge.js +1 -0
- package/neural-interface/lib/claude-session-cleanup.js +5 -1
- package/neural-interface/lib/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +171 -9
- package/neural-interface/lib/client-diagnostics.js +42 -0
- package/neural-interface/lib/confined-fs.js +7 -2
- package/neural-interface/lib/coordination/README.md +8 -2
- package/neural-interface/lib/coordination/contract.js +161 -0
- package/neural-interface/lib/coordination/database.js +999 -0
- package/neural-interface/lib/coordination/operations.js +436 -0
- package/neural-interface/lib/coordination/service.js +68 -537
- package/neural-interface/lib/coordination/storage-worker.js +101 -0
- package/neural-interface/lib/coordination/store.js +219 -1111
- package/neural-interface/lib/db.js +70 -32
- package/neural-interface/lib/health-count.js +37 -0
- package/neural-interface/lib/loop-stall.js +139 -0
- package/neural-interface/lib/maritaca/client.js +2 -2
- package/neural-interface/lib/maritaca/models.js +12 -17
- package/neural-interface/lib/maritaca/opencode.js +4 -2
- package/neural-interface/lib/memory-api.js +9 -1
- package/neural-interface/lib/memory-session-capture.js +42 -10
- package/neural-interface/lib/memory-store-gate.js +313 -0
- package/neural-interface/lib/memory-store-migrate.js +65 -0
- package/neural-interface/lib/memory-timers.js +7 -7
- package/neural-interface/lib/native-loop-providers.js +23 -17
- package/neural-interface/lib/native-loop-runtime.js +48 -9
- package/neural-interface/lib/opencode-build-preflight.js +18 -1
- package/neural-interface/lib/opencode-native-boundary.js +69 -8
- package/neural-interface/lib/opencode-provider-view.js +14 -3
- package/neural-interface/lib/opencode-shell-read.js +107 -0
- package/neural-interface/lib/opencode-stop-failures.js +40 -0
- package/neural-interface/lib/opencode-turn-release.js +173 -0
- package/neural-interface/lib/opencode-v2-client.js +4 -1
- package/neural-interface/lib/opencode-v2-ws-requests.js +65 -1
- package/neural-interface/lib/opencode2-client.js +343 -7
- package/neural-interface/lib/opencode2-translate.js +161 -4
- package/neural-interface/lib/recall-impact.js +122 -0
- package/neural-interface/lib/scratch-evidence.js +420 -0
- package/neural-interface/lib/scratch-process-guard.js +139 -0
- package/neural-interface/lib/scratch-references.js +279 -0
- package/neural-interface/lib/scratch-retention-core.js +385 -0
- package/neural-interface/lib/scratch-retention-worker.js +37 -0
- package/neural-interface/lib/scratch-retention.js +151 -0
- package/neural-interface/lib/session-cache-builder.js +31 -43
- package/neural-interface/lib/session-cache-worker.js +157 -0
- package/neural-interface/lib/session-indexer.js +28 -21
- package/neural-interface/lib/session-search-index.js +85 -0
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/sqlite-integrity-worker.js +3 -1
- package/neural-interface/lib/style-guide/store.js +43 -3
- package/neural-interface/lib/system-restore.js +50 -0
- package/neural-interface/lib/teams/api.js +15 -6
- package/neural-interface/lib/teams/claims.js +67 -31
- package/neural-interface/lib/teams/index.js +7 -7
- package/neural-interface/lib/teams/integration.js +40 -40
- package/neural-interface/lib/teams/landing.js +6 -6
- package/neural-interface/lib/teams/recovery.js +24 -23
- package/neural-interface/lib/teams/scheduler.js +194 -95
- package/neural-interface/lib/teams/state.js +14 -14
- package/neural-interface/lib/teams/worktrees.js +27 -27
- package/neural-interface/lib/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/whatsapp/bridge.js +54 -7
- package/neural-interface/lib/worker-confinement.js +47 -2
- package/neural-interface/lib/worker-mcp-channel.js +2 -0
- package/neural-interface/lib/worker-resume.js +5 -0
- package/neural-interface/lib/worker-stop.js +86 -0
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +5 -2
- package/neural-interface/public/index.html +233 -24
- package/neural-interface/public/onboarding.html +259 -34
- package/neural-interface/public/shared/agents/studio/ax-library.js +0 -6
- package/neural-interface/public/shared/agents/studio/ax-main.js +14 -7
- package/neural-interface/public/shared/agy/agy-options.js +11 -0
- package/neural-interface/public/shared/agy/agy-panel.js +67 -20
- package/neural-interface/public/shared/agy/agy-styles.js +14 -12
- package/neural-interface/public/shared/agy/agy-tabs-logic.js +4 -1
- package/neural-interface/public/shared/api.js +1 -1
- package/neural-interface/public/shared/assistant/asst-api.js +28 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +13 -6
- package/neural-interface/public/shared/assistant/asst-control.js +2 -0
- package/neural-interface/public/shared/assistant/asst-motion-gate.js +78 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +87 -3
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +27 -0
- package/neural-interface/public/shared/assistant/asst-render.js +243 -44
- package/neural-interface/public/shared/assistant/asst-route.js +100 -21
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +1 -1
- package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
- package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +4 -2
- package/neural-interface/public/shared/assistant/asst-state.js +11 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +11 -23
- package/neural-interface/public/shared/assistant/route-identity.js +2 -1
- package/neural-interface/public/shared/cdx/cdx-render.js +9 -0
- package/neural-interface/public/shared/cdx/cdx-settings.js +3 -1
- package/neural-interface/public/shared/cdx/cdx-styles.js +6 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +54 -9
- package/neural-interface/public/shared/client-diagnostics.js +94 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-styles.js +1 -1
- package/neural-interface/public/shared/effort-i18n.js +118 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/html-shell.js +4 -52
- package/neural-interface/public/shared/loading-diagnostic-entry.js +64 -0
- package/neural-interface/public/shared/memory-store-wait.js +52 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +1 -1
- package/neural-interface/public/shared/mtc/mtc-logic.js +2 -1
- package/neural-interface/public/shared/mtc/mtc-panel.js +25 -3
- package/neural-interface/public/shared/mtc/mtc-styles.js +13 -12
- package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +7 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-location-logic.js +109 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +8 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +152 -8
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +53 -4
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +52 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +22 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +67 -93
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-variantpicker.js +17 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
- package/neural-interface/public/shared/output-format.js +294 -0
- package/neural-interface/public/shared/provider-icons.js +6 -0
- package/neural-interface/public/shared/schedules-view.js +2 -1
- package/neural-interface/public/shared/server-presence.js +77 -0
- package/neural-interface/public/shared/settings/settings-backup-contents.js +241 -0
- package/neural-interface/public/shared/settings/settings-backup-download.js +298 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption-pane.js +335 -0
- package/neural-interface/public/shared/settings/settings-backup-encryption.js +545 -0
- package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
- package/neural-interface/public/shared/settings/settings-ia.js +1 -1
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/skills/studio/sx-geometry.js +12 -3
- package/neural-interface/public/shared/skills/studio/sx-main.js +14 -7
- package/neural-interface/public/shared/studio-attention.js +6 -0
- package/neural-interface/public/shared/styles.css +341 -437
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/transcript-rows.js +28 -3
- package/neural-interface/public/shared/tray-auto-close.js +49 -6
- package/neural-interface/public/shared/ui-agents.js +1 -2
- package/neural-interface/public/shared/ui-automation-studio.js +168 -108
- package/neural-interface/public/shared/ui-claude-panel.js +62 -65
- package/neural-interface/public/shared/ui-loading.js +124 -17
- package/neural-interface/public/shared/ui-native-loop-router.js +52 -0
- package/neural-interface/public/shared/ui-navbar.js +2 -1
- package/neural-interface/public/shared/ui-output.js +533 -0
- package/neural-interface/public/shared/ui-schedules-studio.js +165 -128
- package/neural-interface/public/shared/ui-scroll-follow.js +101 -6
- package/neural-interface/public/shared/ui-sessions.js +2 -2
- package/neural-interface/public/shared/ui-settings-entry.js +18 -0
- package/neural-interface/public/shared/ui-settings.js +224 -65
- package/neural-interface/public/shared/ui-sidepanel-tray.js +3 -2
- package/neural-interface/public/shared/ui-tooltip.js +16 -0
- package/neural-interface/public/shared/ui-tutorial.js +5 -6
- package/neural-interface/public/shared/ui-worker-end.js +27 -8
- package/neural-interface/public/shared/worker-end.js +9 -4
- package/neural-interface/public/variant/2d/main.js +5 -0
- package/neural-interface/public/variant/3d/app.js +10 -0
- package/neural-interface/public/variant/3d/main.js +5 -1
- package/neural-interface/scripts/scratch-retention.mjs +20 -0
- package/neural-interface/server.js +725 -173
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/scripts/restore-data-home-from-backup.mjs +175 -8
- package/setup.js +18 -4
- package/browser-extension/content.js +0 -189
- package/browser-extension/engine.js +0 -508
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +0 -56
- package/browser-extension/popup-strings.js +0 -250
- package/browser-extension/popup-view.js +0 -151
- package/browser-extension/popup.css +0 -166
- package/browser-extension/popup.html +0 -108
- package/browser-extension/popup.js +0 -359
- package/browser-extension/service-worker.js +0 -275
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { open } from 'node:fs/promises';
|
|
1
|
+
import { createWriteStream, mkdirSync, renameSync, rmSync } from 'node:fs';
|
|
3
2
|
import { createHash } from 'node:crypto';
|
|
4
3
|
import { Readable, Transform, Writable } from 'node:stream';
|
|
5
4
|
import { pipeline } from 'node:stream/promises';
|
|
6
5
|
import { createInflateRaw, crc32 } from 'node:zlib';
|
|
7
6
|
import { dirname } from 'node:path';
|
|
7
|
+
import { openPlainBackupSource } from './backup-crypto-io.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Streaming ZIP reader for backup archives.
|
|
@@ -28,15 +28,9 @@ const EOCD_MAX_SCAN = EOCD_MIN + 0xffff;
|
|
|
28
28
|
const MAX_CENTRAL_DIRECTORY_BYTES = 512 * 1024 * 1024;
|
|
29
29
|
const MAX_MANIFEST_BYTES = 64 * 1024 * 1024;
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
while (offset < length) {
|
|
35
|
-
const { bytesRead } = await handle.read(buffer, offset, length - offset, position + offset);
|
|
36
|
-
if (bytesRead === 0) throw new Error('Invalid ZIP: unexpected end of file');
|
|
37
|
-
offset += bytesRead;
|
|
38
|
-
}
|
|
39
|
-
return buffer;
|
|
31
|
+
// `handle` is a source (backup-crypto-io.js): the file itself, or the plaintext of an encrypted backup by position.
|
|
32
|
+
function readAt(handle, position, length) {
|
|
33
|
+
return handle.read(position, length);
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
function readUInt64(buffer, offset) {
|
|
@@ -157,10 +151,16 @@ function integrityCheck(entry) {
|
|
|
157
151
|
});
|
|
158
152
|
}
|
|
159
153
|
|
|
160
|
-
|
|
161
|
-
|
|
154
|
+
/**
|
|
155
|
+
* `source`: what the ZIP is read through, { size, read(position, length), stream(start, endInclusive), close() }
|
|
156
|
+
* (backup-crypto-io.js). Without one it is the file at `path`; an encrypted backup's source gives the ZIP inside it,
|
|
157
|
+
* decrypted and checked chunk by chunk as it is read, so no plaintext copy of the archive is ever written. Closing
|
|
158
|
+
* the archive closes its source.
|
|
159
|
+
*/
|
|
160
|
+
export async function openZipArchive(path, { source = null } = {}) {
|
|
161
|
+
const handle = source || await openPlainBackupSource(path);
|
|
162
162
|
try {
|
|
163
|
-
const
|
|
163
|
+
const fileSize = handle.size;
|
|
164
164
|
const directory = await locateCentralDirectory(handle, fileSize);
|
|
165
165
|
const buffer = await readAt(handle, directory.offset, directory.size);
|
|
166
166
|
const entries = parseCentralDirectory(buffer, directory.entryCount);
|
|
@@ -178,6 +178,9 @@ export async function openZipArchive(path) {
|
|
|
178
178
|
return {
|
|
179
179
|
path,
|
|
180
180
|
size: fileSize,
|
|
181
|
+
/** True when the ZIP was read out of an encrypted backup. */
|
|
182
|
+
encrypted: handle.encrypted === true,
|
|
183
|
+
source: handle,
|
|
181
184
|
entries,
|
|
182
185
|
getEntry: name => byName.get(name) || null,
|
|
183
186
|
/** Stream one entry's uncompressed bytes into `sink`, checking CRC and size. */
|
|
@@ -186,7 +189,7 @@ export async function openZipArchive(path) {
|
|
|
186
189
|
if (entry.method !== 0 && entry.method !== 8) throw new Error(`Unsupported ZIP: ${entry.name} uses compression method ${entry.method}`);
|
|
187
190
|
const { start, length } = await dataRange(entry);
|
|
188
191
|
const stages = [length > 0
|
|
189
|
-
?
|
|
192
|
+
? handle.stream(start, start + length - 1)
|
|
190
193
|
: Readable.from([])];
|
|
191
194
|
if (entry.method === 8) stages.push(createInflateRaw());
|
|
192
195
|
stages.push(integrityCheck(entry), sink);
|
|
@@ -254,14 +257,23 @@ export function backupEntryName(prefix, archivePath) {
|
|
|
254
257
|
return prefix ? `${prefix}/${archivePath}` : archivePath;
|
|
255
258
|
}
|
|
256
259
|
|
|
257
|
-
/**
|
|
258
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Stream every manifest-listed entry through sha256 and compare. `onBytes`: as for hashZipEntry. `signal`: an
|
|
262
|
+
* AbortSignal looked at between two entries; an aborted check throws an error whose code is BACKUP_CANCELLED.
|
|
263
|
+
*/
|
|
264
|
+
export async function verifyBackupChecksums(zip, { prefix, manifest, label = 'Backup verification failed', onBytes = null, signal = null }) {
|
|
259
265
|
for (const [archivePath, expected] of Object.entries(manifest.checksums || {})) {
|
|
266
|
+
if (signal?.aborted) throw Object.assign(new Error('The backup was cancelled.'), { code: 'BACKUP_CANCELLED' });
|
|
260
267
|
const entry = zip.getEntry(backupEntryName(prefix, archivePath));
|
|
261
268
|
if (!entry) throw new Error(`${label}: ${archivePath} is missing`);
|
|
262
269
|
let actual;
|
|
263
270
|
try { actual = `sha256:${await hashZipEntry(zip, entry, { onBytes })}`; }
|
|
264
|
-
catch (error) {
|
|
271
|
+
catch (error) {
|
|
272
|
+
// A failure of the encrypted container under the ZIP keeps its code (BACKUP_ENC_DAMAGED): the caller tells a
|
|
273
|
+
// changed file from an unreadable entry by it.
|
|
274
|
+
const code = typeof error?.code === 'string' && error.code.startsWith('BACKUP_') ? { code: error.code } : {};
|
|
275
|
+
throw Object.assign(new Error(`${label}: ${archivePath} is unreadable (${error.message})`), code);
|
|
276
|
+
}
|
|
265
277
|
if (actual !== expected) throw new Error(`${label}: checksum mismatch for ${archivePath}`);
|
|
266
278
|
}
|
|
267
279
|
}
|
|
@@ -26,6 +26,9 @@ const SIG_EOCD = 0x06054b50;
|
|
|
26
26
|
const SIG_ZIP64_EOCD = 0x06064b50;
|
|
27
27
|
const SIG_ZIP64_LOCATOR = 0x07064b50;
|
|
28
28
|
const UTF8_NAMES = 0x0800;
|
|
29
|
+
const SIG_DESCRIPTOR = 0x08074b50;
|
|
30
|
+
/** General-purpose bit 3: the entry's CRC-32 follows its data, in a data descriptor. */
|
|
31
|
+
const HAS_DESCRIPTOR = 0x0008;
|
|
29
32
|
const MAX32 = 0xffffffff;
|
|
30
33
|
const MAX16 = 0xffff;
|
|
31
34
|
const CHUNK = 4 * 1024 * 1024;
|
|
@@ -57,9 +60,14 @@ function zip64Extra(fields) {
|
|
|
57
60
|
* sha256 }]): a manifest that lists the checksums of the entries before it
|
|
58
61
|
* onProgress({ bytes, totalBytes }) as data goes in, at most every 64 MB and at the end
|
|
59
62
|
* forceZip64 write ZIP64 records even when nothing needs them (tests)
|
|
63
|
+
* sink where the bytes go instead of a file at `path`: { write(buffer) → Promise, finish() → Promise,
|
|
64
|
+
* abort() → Promise } (the encrypted backup writer of backup-crypto-io.js, which copies what it is
|
|
65
|
+
* given). A sink only takes bytes in order, so nothing can be patched afterwards: a streamed entry's
|
|
66
|
+
* CRC-32 then follows its data in a data descriptor (its sizes are known and stay in its header).
|
|
67
|
+
* backup-zip-reader.js reads sizes and CRCs from the central directory, so it reads both shapes
|
|
60
68
|
* Resolves { bytes, entries: [{ name, size, crc32, sha256 }] } (sha256 in hex).
|
|
61
69
|
*/
|
|
62
|
-
export async function writeZipArchive(path, entries, { onProgress = null, now = () => new Date(), forceZip64 = false } = {}) {
|
|
70
|
+
export async function writeZipArchive(path, entries, { onProgress = null, now = () => new Date(), forceZip64 = false, sink = null } = {}) {
|
|
63
71
|
const report = typeof onProgress === 'function' ? onProgress : () => {};
|
|
64
72
|
const stamp = dosDateTime(now());
|
|
65
73
|
// Sizes first, so the progress has a total and a stored entry's headers carry its real size.
|
|
@@ -88,11 +96,13 @@ export async function writeZipArchive(path, entries, { onProgress = null, now =
|
|
|
88
96
|
}
|
|
89
97
|
};
|
|
90
98
|
|
|
91
|
-
const handle = await open(path, 'wx');
|
|
99
|
+
const handle = sink ? null : await open(path, 'wx');
|
|
92
100
|
const written = [];
|
|
93
101
|
let offset = 0;
|
|
102
|
+
let finished = false;
|
|
94
103
|
try {
|
|
95
104
|
const write = async (buffer) => {
|
|
105
|
+
if (sink) { await sink.write(buffer); offset += buffer.length; return; }
|
|
96
106
|
let at = 0;
|
|
97
107
|
while (at < buffer.length) {
|
|
98
108
|
const { bytesWritten } = await handle.write(buffer, at, buffer.length - at, offset + at);
|
|
@@ -125,13 +135,15 @@ export async function writeZipArchive(path, entries, { onProgress = null, now =
|
|
|
125
135
|
payload = deflateRawSync(data, { level: 6 });
|
|
126
136
|
}
|
|
127
137
|
const method = item.store ? 0 : 8;
|
|
138
|
+
// Streamed into a sink: the CRC is only known after the last byte and cannot be written back.
|
|
139
|
+
const flags = UTF8_NAMES | (sink && !payload ? HAS_DESCRIPTOR : 0);
|
|
128
140
|
const compressedSize = payload ? payload.length : item.size;
|
|
129
141
|
const zip64 = forceZip64 || item.size >= MAX32 || compressedSize >= MAX32 || localOffset >= MAX32;
|
|
130
142
|
const localExtra = zip64 ? zip64Extra([item.size, compressedSize]) : Buffer.alloc(0);
|
|
131
143
|
const header = Buffer.alloc(30);
|
|
132
144
|
header.writeUInt32LE(SIG_LOCAL, 0);
|
|
133
145
|
header.writeUInt16LE(zip64 ? 45 : method === 8 ? 20 : 10, 4);
|
|
134
|
-
header.writeUInt16LE(
|
|
146
|
+
header.writeUInt16LE(flags, 6);
|
|
135
147
|
header.writeUInt16LE(method, 8);
|
|
136
148
|
header.writeUInt16LE(stamp.time, 10);
|
|
137
149
|
header.writeUInt16LE(stamp.date, 12);
|
|
@@ -174,11 +186,20 @@ export async function writeZipArchive(path, entries, { onProgress = null, now =
|
|
|
174
186
|
} finally {
|
|
175
187
|
await source.close();
|
|
176
188
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
if (sink) {
|
|
190
|
+
const descriptor = Buffer.alloc(zip64 ? 24 : 16);
|
|
191
|
+
descriptor.writeUInt32LE(SIG_DESCRIPTOR, 0);
|
|
192
|
+
descriptor.writeUInt32LE(crc >>> 0, 4);
|
|
193
|
+
if (zip64) { descriptor.writeBigUInt64LE(BigInt(compressedSize), 8); descriptor.writeBigUInt64LE(BigInt(item.size), 16); }
|
|
194
|
+
else { descriptor.writeUInt32LE(compressedSize, 8); descriptor.writeUInt32LE(item.size, 12); }
|
|
195
|
+
await write(descriptor);
|
|
196
|
+
} else {
|
|
197
|
+
const crcBuffer = Buffer.alloc(4);
|
|
198
|
+
crcBuffer.writeUInt32LE(crc >>> 0, 0);
|
|
199
|
+
await handle.write(crcBuffer, 0, 4, localOffset + 14);
|
|
200
|
+
}
|
|
180
201
|
}
|
|
181
|
-
written.push({ name: item.name, nameBytes, method, crc: crc >>> 0, size: item.size, compressedSize, localOffset, zip64, sha256: digest.digest('hex') });
|
|
202
|
+
written.push({ name: item.name, nameBytes, method, flags, crc: crc >>> 0, size: item.size, compressedSize, localOffset, zip64, sha256: digest.digest('hex') });
|
|
182
203
|
}
|
|
183
204
|
|
|
184
205
|
// The central directory: one record per entry, then the end records.
|
|
@@ -194,7 +215,7 @@ export async function writeZipArchive(path, entries, { onProgress = null, now =
|
|
|
194
215
|
record.writeUInt32LE(SIG_CENTRAL, 0);
|
|
195
216
|
record.writeUInt16LE((3 << 8) | 45, 4);
|
|
196
217
|
record.writeUInt16LE(entry.zip64 ? 45 : entry.method === 8 ? 20 : 10, 6);
|
|
197
|
-
record.writeUInt16LE(
|
|
218
|
+
record.writeUInt16LE(entry.flags, 8);
|
|
198
219
|
record.writeUInt16LE(entry.method, 10);
|
|
199
220
|
record.writeUInt16LE(stamp.time, 12);
|
|
200
221
|
record.writeUInt16LE(stamp.date, 14);
|
|
@@ -245,10 +266,13 @@ export async function writeZipArchive(path, entries, { onProgress = null, now =
|
|
|
245
266
|
end.writeUInt32LE(needs64 ? MAX32 : directoryOffset, 16);
|
|
246
267
|
end.writeUInt16LE(0, 20);
|
|
247
268
|
await write(end);
|
|
248
|
-
await
|
|
269
|
+
if (sink) await sink.finish();
|
|
270
|
+
else await handle.sync();
|
|
271
|
+
finished = true;
|
|
249
272
|
progress(true);
|
|
250
273
|
} finally {
|
|
251
|
-
await handle.close();
|
|
274
|
+
if (handle) await handle.close();
|
|
275
|
+
else if (!finished) await sink.abort().catch(() => {});
|
|
252
276
|
}
|
|
253
277
|
return {
|
|
254
278
|
bytes: offset,
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { basename, isAbsolute, resolve } from 'node:path';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { fail, handle, HISTORY, MAX_FILE, safeError } from '
|
|
2
|
+
import { basename, extname, isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { readConfinedFileWithMetadata } from './confined-fs.js';
|
|
5
|
+
import { EVALUATE_SCRIPT_MAX, EVALUATE_TIMEOUT_MAX, EVALUATE_WORLDS, fail, handle, HISTORY, LOAD_STATES, MAX_FILE, NETWORK_IDLE_TIMEOUT_MAX, safeError } from './browser-extension-protocol.js';
|
|
6
6
|
import sharp from 'sharp';
|
|
7
7
|
import { parseScreenshotOptions, screenshotPathRefusal, defaultScreenshotPath, writeScreenshotFile } from './browser-screenshot.js';
|
|
8
8
|
import { ownerOnlyCreateFields } from './browser-automation-routes.js';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// Use the server's static-file MIME table. Its bundled table predates these image formats.
|
|
11
|
+
export function uploadMimeType(name) {
|
|
12
|
+
const ext = extname(name).toLowerCase();
|
|
13
|
+
if (['.heic', '.heif', '.avif'].includes(ext)) return 'image/' + ext.slice(1);
|
|
14
|
+
return express.static.mime.lookup(ext);
|
|
15
|
+
}
|
|
11
16
|
const aliases = { 'screenshot-base64': 'screenshot' };
|
|
12
|
-
const supported = new Set(['navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload']);
|
|
17
|
+
const supported = new Set(['navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload', 'evaluate']);
|
|
13
18
|
const argumentKeys = ['url', 'ref', 'selector', 'nthMatch', 'value', 'text', 'key', 'direction', 'distance', 'maxChars', 'offset', 'timeout', 'state'];
|
|
14
19
|
const unsupported = reason => Object.assign(new Error(reason), { code: 'UNSUPPORTED_IN_EXTENSION_MODE' });
|
|
20
|
+
// A whole number of milliseconds from a request body, 1 to `most`; undefined when none (or nothing usable) was given.
|
|
21
|
+
const milliseconds = (value, most) => { const n = Number(value); return Number.isFinite(n) && n >= 1 ? Math.min(most, Math.floor(n)) : undefined; };
|
|
22
|
+
// A refusal always says what its code means, also when the extension answered the code alone.
|
|
23
|
+
const worded = result => (result && result.ok === false && result.code && typeof result.error !== 'string' ? { ...result, error: safeError(result).error } : result);
|
|
24
|
+
// evaluate refusals after which the page's script certainly did not run (a paced write then takes no slot).
|
|
25
|
+
const NOTHING_RAN = ['USER_SCRIPTS_DISABLED', 'USER_SCRIPTS_UNSUPPORTED', 'EXTENSION_RELOAD_REQUIRED', 'EXTENSION_NOT_CONNECTED', 'BLANK_PAGE', 'FRAME_NOT_FOUND',
|
|
26
|
+
'RESTRICTED_PAGE', 'SYNABUN_PAGE_BLOCKED', 'SITE_NOT_APPROVED', 'NOT_OWNED', 'AUTH_FAILED', 'INVALID_MESSAGE'];
|
|
15
27
|
// What an agent may see of its tab's address. Full control: the address. Restricted mode: an approved site's URL, or
|
|
16
28
|
// the blank start page; a page that history (or a redirect) took the tab to on an unapproved site stays the owner's:
|
|
17
29
|
// the session listing shows no URL for it.
|
|
@@ -32,7 +44,11 @@ export function listedUrl(url) {
|
|
|
32
44
|
const HISTORY_DESTINATION = 'The page this history step reached is not on an approved site (or an approval was revoked meanwhile). No page content was returned. The tab stays there and refuses commands until the owner shares that site in the extension popup (or switches to full control); release the session to stop using it.';
|
|
33
45
|
|
|
34
46
|
/** Owns routing only; extension sessions intentionally expose no Playwright/CDP surface. */
|
|
35
|
-
|
|
47
|
+
// `evaluateGate` holds page JavaScript to the rules the Playwright evaluate route holds a loop's tab to (server.js):
|
|
48
|
+
// `refusal({ session, req, tabId, script })` answers the X publish gate's refusal (or null), `run({ session, req, execute })`
|
|
49
|
+
// spaces a social write (`pace` in the body) and answers { result } or { paced } with it. Without one, nothing is gated
|
|
50
|
+
// (tests of the adapter alone).
|
|
51
|
+
export function createExtensionAdapter({ bridge, sessions, uploadRoot, caller, ownerPage, selected, dataHome, log = () => {}, evaluateGate = null }) {
|
|
36
52
|
const salt = randomBytes(32).toString('hex');
|
|
37
53
|
const agent = owner => createHash('sha256').update(`${salt}:${owner}`).digest('hex');
|
|
38
54
|
let sessionId = null, chain = Promise.resolve();
|
|
@@ -130,9 +146,9 @@ export function createExtensionAdapter({ bridge, sessions, uploadRoot, caller, o
|
|
|
130
146
|
names: paths.map(path => basename(path)),
|
|
131
147
|
read(index) {
|
|
132
148
|
try {
|
|
133
|
-
const
|
|
134
|
-
remaining -= bytes.length;
|
|
135
|
-
return
|
|
149
|
+
const file = readConfinedFileWithMetadata(uploadRoot, resolve(paths[index]), { maxBytes: remaining });
|
|
150
|
+
remaining -= file.bytes.length;
|
|
151
|
+
return { ...file, type: uploadMimeType(paths[index]) };
|
|
136
152
|
} catch (error) {
|
|
137
153
|
if (error.status === 404) fail('UPLOAD_FILE_MISSING');
|
|
138
154
|
if (error.status === 413) fail('UPLOAD_TOO_LARGE');
|
|
@@ -141,19 +157,72 @@ export function createExtensionAdapter({ bridge, sessions, uploadRoot, caller, o
|
|
|
141
157
|
},
|
|
142
158
|
};
|
|
143
159
|
}
|
|
144
|
-
|
|
160
|
+
// Page JavaScript (extension 1.4.0 and later): the script of the Playwright route's body, as one expression, through
|
|
161
|
+
// chrome.userScripts.execute in the agent's own tab. The answer has that route's shape: { ok, result } with the
|
|
162
|
+
// script's value, or { ok: false, error }. Before anything is sent: the bridge's own rules for the tab (and its
|
|
163
|
+
// version gate), then the publish gate; a paced write then waits its gap and runs only if the agent still holds the tab.
|
|
164
|
+
async function evaluate(s, owner, tab, body, req) {
|
|
165
|
+
const script = body.script;
|
|
166
|
+
if (typeof script !== 'string' || !script.trim()) return { ok: false, error: 'script required' };
|
|
167
|
+
if (script.length > EVALUATE_SCRIPT_MAX) return { ok: false, error: `script exceeds ${EVALUATE_SCRIPT_MAX} characters` };
|
|
168
|
+
const args = { expression: script };
|
|
169
|
+
const timeout = milliseconds(body.timeout, EVALUATE_TIMEOUT_MAX), maxChars = milliseconds(body.maxChars, 1000000);
|
|
170
|
+
if (timeout) args.timeout = timeout;
|
|
171
|
+
if (maxChars) args.maxChars = maxChars;
|
|
172
|
+
if (body.world !== undefined && body.world !== null) { if (!EVALUATE_WORLDS.includes(body.world)) return { ok: false, error: `Invalid world. Use: ${EVALUATE_WORLDS.join(', ')}` }; args.world = body.world; }
|
|
173
|
+
if (body.frame !== undefined && body.frame !== null) { if (!Number.isSafeInteger(Number(body.frame)) || Number(body.frame) < 0) return { ok: false, error: 'Invalid frame id' }; args.frame = Number(body.frame); }
|
|
174
|
+
bridge.authorize('evaluate', tab, agent(owner), args);
|
|
175
|
+
const refusal = evaluateGate?.refusal?.({ session: s, req, tabId: tab, script }) || null;
|
|
176
|
+
if (refusal) return { ok: false, ...refusal };
|
|
177
|
+
let cut = null;
|
|
178
|
+
const execute = async () => {
|
|
179
|
+
// A paced write may have waited a minute: it runs only in the tab this request named, if the agent still holds it.
|
|
180
|
+
if (sessions.get(s.id) !== s || !ownsTab(s, owner, tab)) throw Object.assign(new Error('TAB_CLOSED'), { code: 'TAB_CLOSED', writeStarted: false });
|
|
181
|
+
let result;
|
|
182
|
+
try { result = finish(s, tab, await bridge.request('evaluate', tab, agent(owner), args)); }
|
|
183
|
+
catch (error) { if (NOTHING_RAN.includes(error?.code)) error.writeStarted = false; throw error; }
|
|
184
|
+
if (result.ok) {
|
|
185
|
+
// `value` is the JSON text of what the script returned. One that was cut is the beginning of that text (not
|
|
186
|
+
// valid JSON): it is answered as that text, flagged.
|
|
187
|
+
if (result.truncated) { cut = { truncated: true, valueLength: result.valueLength }; return result.value; }
|
|
188
|
+
try { return JSON.parse(result.value); } catch { fail('OPERATION_FAILED'); }
|
|
189
|
+
}
|
|
190
|
+
let answer = worded(result);
|
|
191
|
+
if (result.code === 'PAGE_ERROR') {
|
|
192
|
+
// What the page's script threw, in the words of a Playwright failure. No stack: the script did not compile.
|
|
193
|
+
const message = result.errorMessage || 'The script threw.';
|
|
194
|
+
answer = { ok: false, code: 'PAGE_ERROR', error: `page.evaluate: ${message}${result.errorStack ? '' : ' browser_evaluate takes one JavaScript expression: wrap statements in a function, (() => { …; return value; })().'}`,
|
|
195
|
+
...(result.errorStack ? { errorStack: result.errorStack } : {}) };
|
|
196
|
+
}
|
|
197
|
+
throw Object.assign(new Error(result.code || 'OPERATION_FAILED'), { answer, ...(NOTHING_RAN.includes(result.code) ? { writeStarted: false } : {}) });
|
|
198
|
+
};
|
|
199
|
+
let outcome;
|
|
200
|
+
try { outcome = evaluateGate?.run ? await evaluateGate.run({ session: s, req, execute }) : { result: await execute() }; }
|
|
201
|
+
catch (error) { if (error?.answer) return error.answer; throw error; }
|
|
202
|
+
if (outcome.paced?.pending) return { ok: true, paced: outcome.paced };
|
|
203
|
+
return { ok: true, result: outcome.result === undefined ? null : outcome.result, ...(cut || {}), ...(outcome.paced ? { paced: outcome.paced } : {}) };
|
|
204
|
+
}
|
|
205
|
+
async function operation(s, owner, tab, action, body = {}, req = null) {
|
|
145
206
|
if (!bridge.status().connected) fail('EXTENSION_NOT_CONNECTED');
|
|
146
207
|
if (!s || !tab || !s.tabs.has(tab)) fail('TAB_CLOSED');
|
|
147
208
|
if (!ownsTab(s, owner, tab)) fail('NOT_OWNED');
|
|
148
209
|
const op = aliases[action] || action;
|
|
149
|
-
if (!supported.has(op)) throw unsupported('This operation is not supported by the extension backend. No debugger
|
|
210
|
+
if (!supported.has(op)) throw unsupported('This operation is not supported by the extension backend. No debugger is attached; page JavaScript runs through browser_evaluate only.');
|
|
211
|
+
if (op === 'evaluate') return evaluate(s, owner, tab, body, req);
|
|
150
212
|
let shot;
|
|
151
213
|
if (op === 'screenshot') {
|
|
152
214
|
shot = parseScreenshotOptions(body);
|
|
153
215
|
if (shot.fullPage || shot.width || shot.height || ['selector', 'ref', 'clip', 'region'].some(k => body[k])) throw unsupported('Only the visible viewport can be captured: the extension has no debugger for viewport emulation, element crops or full-page capture. Use maxWidth to downscale the captured image.');
|
|
154
216
|
if (shot.path && screenshotPathRefusal(shot.path, { dataHome })) fail('SCREENSHOT_PATH_REFUSED');
|
|
155
217
|
}
|
|
156
|
-
if (op === 'wait' && body.loadState)
|
|
218
|
+
if (op === 'wait' && body.loadState) {
|
|
219
|
+
// A load-state wait (extension 1.4.0 and later): 'load' and 'networkidle', for the tab, not for an element (as in
|
|
220
|
+
// the Playwright route, a selector sent with it is not used). The extension has no DOMContentLoaded signal.
|
|
221
|
+
if (body.loadState === 'domcontentloaded') throw unsupported('Extension waits support loadState "load" and "networkidle" (and selectors and fixed delays), not "domcontentloaded".');
|
|
222
|
+
if (!LOAD_STATES.includes(body.loadState)) return { ok: false, error: 'Invalid loadState. Use: load, domcontentloaded, networkidle' };
|
|
223
|
+
const timeout = milliseconds(body.timeout, NETWORK_IDLE_TIMEOUT_MAX);
|
|
224
|
+
return worded(finish(s, tab, await bridge.request('wait', tab, agent(owner), { loadState: body.loadState, ...(timeout ? { timeout } : {}) })));
|
|
225
|
+
}
|
|
157
226
|
if (op === 'snapshot' && body.mode && body.mode !== 'ai') throw unsupported('Extension snapshots support mode="ai" (DOM refs) only.');
|
|
158
227
|
if (HISTORY.includes(op)) {
|
|
159
228
|
// Back and forward take no arguments on the wire; the server and the extension check the landing page.
|
|
@@ -170,6 +239,10 @@ export function createExtensionAdapter({ bridge, sessions, uploadRoot, caller, o
|
|
|
170
239
|
args.files = upload.names;
|
|
171
240
|
}
|
|
172
241
|
const result = finish(s, tab, await bridge.request(op, tab, agent(owner), args, upload));
|
|
242
|
+
if (op === 'upload' && result.ok && !result.files) {
|
|
243
|
+
// A still-loaded 1.3.0 extension may already have dispatched events. Do not replay it.
|
|
244
|
+
return { ok: false, error: 'The extension returned no file details. Check the page before retrying and reload SynaBun Browser Bridge.' };
|
|
245
|
+
}
|
|
173
246
|
if (op === 'wait' && result.ok) result.state = body.state || 'visible';
|
|
174
247
|
if (op === 'screenshot' && result.ok) {
|
|
175
248
|
const raw = Buffer.from(result.base64, 'base64'), meta = await sharp(raw).metadata();
|
|
@@ -256,8 +329,9 @@ export function createExtensionAdapter({ bridge, sessions, uploadRoot, caller, o
|
|
|
256
329
|
const tab = body.tabId || s._tabOwners.get(owner);
|
|
257
330
|
if (!['GET', 'POST'].includes(req.method)) throw unsupported('Tab management is through the extension popup.');
|
|
258
331
|
// Every extension session endpoint is intercepted, including CDP, raw screenshot and UI routes.
|
|
259
|
-
const result = await operation(s, owner, tab, match[2], body);
|
|
260
|
-
|
|
332
|
+
const result = await operation(s, owner, tab, match[2], body, req);
|
|
333
|
+
// 409: the publish gate's refusal, as the Playwright routes answer it.
|
|
334
|
+
return res.status(result.ok ? 200 : result.code === 'TAB_CLOSED' ? 410 : result.quoteGuard ? 409 : 400).json(result);
|
|
261
335
|
} catch (error) { try { log({ command: supported.has(match?.[2]) ? match[2] : 'session', tab: null, code: safeError(error).code }); } catch {} return denied(res, error); }
|
|
262
336
|
}
|
|
263
337
|
return { acquire, release, destroy, sync, operation, middleware, agent, session, ownerTabs, ownsTab };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// The extension package: which files an extension folder may hold, and the one zip form SynaBun writes and reads.
|
|
2
|
+
//
|
|
3
|
+
// One allowlist for everything (extensionFileAllowed): the manifest, scripts, pages, styles at the top and the PNGs
|
|
4
|
+
// in `icons/`. The folder the owner loads, a folder read as a source (Dev's build, tests) and a downloaded package
|
|
5
|
+
// are all held to it.
|
|
6
|
+
//
|
|
7
|
+
// The package is a zip SynaBun builds itself (scripts/extension/build-browser-extension.mjs, Dev only) in one fixed
|
|
8
|
+
// form, so two builds of the same files are the same bytes on any machine and any Node: entries sorted by name, every
|
|
9
|
+
// one STORED (no deflate, whose output depends on the zlib at hand), one fixed time, one fixed mode, no folder
|
|
10
|
+
// entries, no extra fields, no comments. readExtensionZip accepts only that form, which is also what makes a hostile
|
|
11
|
+
// file harmless: nothing is inflated (no zip bomb), a name outside the allowlist, a link, a second entry of a name, a
|
|
12
|
+
// gap or bytes after the directory are each a refusal, and every entry's CRC is checked. It returns bytes in memory and
|
|
13
|
+
// writes nothing; the caller has verified the file's size and SHA-256 before it calls (lib/browser-extension-package.js).
|
|
14
|
+
import { lstatSync, readdirSync, readFileSync } from 'node:fs';
|
|
15
|
+
import { join } from 'node:path';
|
|
16
|
+
import { crc32 } from 'node:zlib';
|
|
17
|
+
|
|
18
|
+
const FILE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(js|json|html|css|png)$/;
|
|
19
|
+
const ICON = /^[A-Za-z0-9][A-Za-z0-9._-]*\.png$/;
|
|
20
|
+
/** The most entries a package may hold, and the most bytes one of them may be. */
|
|
21
|
+
export const EXTENSION_MAX_FILES = 64;
|
|
22
|
+
export const EXTENSION_MAX_FILE_BYTES = 4 * 1024 * 1024;
|
|
23
|
+
|
|
24
|
+
const fail = (message) => { throw Object.assign(new Error(message), { code: 'EXTENSION_ARCHIVE_INVALID' }); };
|
|
25
|
+
|
|
26
|
+
/** Whether `rel` (forward slashes, relative to the extension folder) is a file an extension folder may hold. */
|
|
27
|
+
export function extensionFileAllowed(rel) {
|
|
28
|
+
if (typeof rel !== 'string') return false;
|
|
29
|
+
const parts = rel.split('/');
|
|
30
|
+
if (parts.length === 1) return FILE.test(parts[0]);
|
|
31
|
+
return parts.length === 2 && parts[0] === 'icons' && ICON.test(parts[1]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A folder's extension files, by path relative to it: regular files of the allowlist (a link is never followed), the
|
|
36
|
+
* top level and `icons/`, sorted by name. Returns [{ rel, bytes }].
|
|
37
|
+
*/
|
|
38
|
+
export function readExtensionSource(source) {
|
|
39
|
+
const files = [];
|
|
40
|
+
for (const [dir, prefix] of [[source, ''], [join(source, 'icons'), 'icons/']]) {
|
|
41
|
+
let names = [];
|
|
42
|
+
try { names = readdirSync(dir); } catch { continue; }
|
|
43
|
+
for (const name of names) {
|
|
44
|
+
const rel = prefix + name;
|
|
45
|
+
if (!extensionFileAllowed(rel)) continue;
|
|
46
|
+
const path = join(dir, name);
|
|
47
|
+
try { if (!lstatSync(path).isFile()) continue; } catch { continue; }
|
|
48
|
+
files.push({ rel, bytes: readFileSync(path) });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return files.sort((a, b) => (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 1980-01-01 00:00:00, the first moment a zip can name; rw-r--r-- on a regular file, written by "Unix".
|
|
55
|
+
const DOS_TIME = 0, DOS_DATE = 0x0021, MADE_BY = 0x031e, NEEDED = 10, MODE = 0o100644;
|
|
56
|
+
const LOCAL = 0x04034b50, CENTRAL = 0x02014b50, END = 0x06054b50;
|
|
57
|
+
|
|
58
|
+
function checkFiles(files) {
|
|
59
|
+
if (!Array.isArray(files) || !files.length) fail('The extension has no files.');
|
|
60
|
+
if (files.length > EXTENSION_MAX_FILES) fail('The extension has too many files.');
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
for (const file of files) {
|
|
63
|
+
if (!extensionFileAllowed(file?.rel)) fail('The extension holds a file that is not allowed.');
|
|
64
|
+
if (!Buffer.isBuffer(file.bytes) || file.bytes.length > EXTENSION_MAX_FILE_BYTES) fail('A file of the extension is too large.');
|
|
65
|
+
const key = file.rel.toLowerCase();
|
|
66
|
+
if (seen.has(key)) fail('The extension names a file twice.');
|
|
67
|
+
seen.add(key);
|
|
68
|
+
}
|
|
69
|
+
if (!seen.has('manifest.json')) fail('The extension has no manifest.');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The package of `files` ([{ rel, bytes }]) in SynaBun's one zip form. The same files give the same bytes. */
|
|
73
|
+
export function writeExtensionZip(files) {
|
|
74
|
+
checkFiles(files);
|
|
75
|
+
const sorted = [...files].sort((a, b) => (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0));
|
|
76
|
+
const parts = [], directory = [];
|
|
77
|
+
let offset = 0;
|
|
78
|
+
for (const { rel, bytes } of sorted) {
|
|
79
|
+
const name = Buffer.from(rel, 'ascii'), crc = crc32(bytes);
|
|
80
|
+
const local = Buffer.alloc(30);
|
|
81
|
+
local.writeUInt32LE(LOCAL, 0); local.writeUInt16LE(NEEDED, 4); local.writeUInt16LE(0, 6); local.writeUInt16LE(0, 8);
|
|
82
|
+
local.writeUInt16LE(DOS_TIME, 10); local.writeUInt16LE(DOS_DATE, 12); local.writeUInt32LE(crc, 14);
|
|
83
|
+
local.writeUInt32LE(bytes.length, 18); local.writeUInt32LE(bytes.length, 22); local.writeUInt16LE(name.length, 26); local.writeUInt16LE(0, 28);
|
|
84
|
+
const central = Buffer.alloc(46);
|
|
85
|
+
central.writeUInt32LE(CENTRAL, 0); central.writeUInt16LE(MADE_BY, 4); central.writeUInt16LE(NEEDED, 6); central.writeUInt16LE(0, 8); central.writeUInt16LE(0, 10);
|
|
86
|
+
central.writeUInt16LE(DOS_TIME, 12); central.writeUInt16LE(DOS_DATE, 14); central.writeUInt32LE(crc, 16);
|
|
87
|
+
central.writeUInt32LE(bytes.length, 20); central.writeUInt32LE(bytes.length, 24); central.writeUInt16LE(name.length, 28);
|
|
88
|
+
central.writeUInt16LE(0, 30); central.writeUInt16LE(0, 32); central.writeUInt16LE(0, 34); central.writeUInt16LE(0, 36);
|
|
89
|
+
central.writeUInt32LE((MODE << 16) >>> 0, 38); central.writeUInt32LE(offset, 42);
|
|
90
|
+
parts.push(local, name, bytes); directory.push(central, name);
|
|
91
|
+
offset += 30 + name.length + bytes.length;
|
|
92
|
+
}
|
|
93
|
+
const directoryBytes = Buffer.concat(directory);
|
|
94
|
+
const end = Buffer.alloc(22);
|
|
95
|
+
end.writeUInt32LE(END, 0); end.writeUInt16LE(0, 4); end.writeUInt16LE(0, 6); end.writeUInt16LE(sorted.length, 8); end.writeUInt16LE(sorted.length, 10);
|
|
96
|
+
end.writeUInt32LE(directoryBytes.length, 12); end.writeUInt32LE(offset, 16); end.writeUInt16LE(0, 20);
|
|
97
|
+
return Buffer.concat([...parts, directoryBytes, end]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The files of a package in SynaBun's one zip form: [{ rel, bytes }], sorted by name. Throws
|
|
102
|
+
* EXTENSION_ARCHIVE_INVALID for anything else (see the top of this file); never writes and never inflates.
|
|
103
|
+
*/
|
|
104
|
+
export function readExtensionZip(zip) {
|
|
105
|
+
if (!Buffer.isBuffer(zip) || zip.length < 22) fail('The package is not a zip file.');
|
|
106
|
+
const endAt = zip.length - 22;
|
|
107
|
+
if (zip.readUInt32LE(endAt) !== END) fail('The package does not end as SynaBun writes it.');
|
|
108
|
+
const count = zip.readUInt16LE(endAt + 10), directorySize = zip.readUInt32LE(endAt + 12), directoryAt = zip.readUInt32LE(endAt + 16);
|
|
109
|
+
if (zip.readUInt16LE(endAt + 4) || zip.readUInt16LE(endAt + 6) || zip.readUInt16LE(endAt + 8) !== count || zip.readUInt16LE(endAt + 20)) fail('The package is not a plain single zip file.');
|
|
110
|
+
if (!count || count > EXTENSION_MAX_FILES) fail('The package holds no files, or too many.');
|
|
111
|
+
if (directoryAt + directorySize !== endAt) fail('The package has bytes its directory does not account for.');
|
|
112
|
+
const files = [], seen = new Set();
|
|
113
|
+
let at = directoryAt, dataAt = 0, previous = '';
|
|
114
|
+
for (let i = 0; i < count; i++) {
|
|
115
|
+
if (at + 46 > endAt || zip.readUInt32LE(at) !== CENTRAL) fail('The package directory is damaged.');
|
|
116
|
+
const flags = zip.readUInt16LE(at + 8), method = zip.readUInt16LE(at + 10), crc = zip.readUInt32LE(at + 16);
|
|
117
|
+
const packed = zip.readUInt32LE(at + 20), size = zip.readUInt32LE(at + 24), nameLength = zip.readUInt16LE(at + 28);
|
|
118
|
+
const attributes = zip.readUInt32LE(at + 38), localAt = zip.readUInt32LE(at + 42);
|
|
119
|
+
if (flags !== 0 || method !== 0 || packed !== size) fail('The package holds an entry that is compressed, encrypted or streamed.');
|
|
120
|
+
if (zip.readUInt16LE(at + 30) || zip.readUInt16LE(at + 32) || zip.readUInt16LE(at + 34)) fail('The package holds an entry with extra data.');
|
|
121
|
+
// Every other field is the one value SynaBun's writer puts there: the version needed, the time, the date, the
|
|
122
|
+
// internal attributes (and, below, the same in the entry's own header).
|
|
123
|
+
if (zip.readUInt16LE(at + 6) !== NEEDED || zip.readUInt16LE(at + 12) !== DOS_TIME || zip.readUInt16LE(at + 14) !== DOS_DATE || zip.readUInt16LE(at + 36) !== 0) fail('The package holds an entry that SynaBun did not write.');
|
|
124
|
+
if (size > EXTENSION_MAX_FILE_BYTES) fail('The package holds a file that is too large.');
|
|
125
|
+
if (at + 46 + nameLength > endAt) fail('The package directory is damaged.');
|
|
126
|
+
const nameBytes = zip.subarray(at + 46, at + 46 + nameLength), rel = nameBytes.toString('latin1');
|
|
127
|
+
// A regular file and nothing else: a link, a folder, a device are told by the Unix mode a zip keeps for its maker.
|
|
128
|
+
if (zip.readUInt16LE(at + 4) !== MADE_BY || (attributes >>> 16) !== MODE) fail('The package holds an entry that is not a plain file.');
|
|
129
|
+
if (!extensionFileAllowed(rel)) fail('The package holds a file that is not part of the extension.');
|
|
130
|
+
const key = rel.toLowerCase();
|
|
131
|
+
if (seen.has(key)) fail('The package names a file twice.');
|
|
132
|
+
if (previous && !(previous < rel)) fail('The package is not in SynaBun\'s order.');
|
|
133
|
+
seen.add(key); previous = rel;
|
|
134
|
+
// The entry itself: where the last one ended, with a header that says what the directory says.
|
|
135
|
+
if (localAt !== dataAt || localAt + 30 + nameLength + size > directoryAt) fail('The package has a gap or an overlap between its files.');
|
|
136
|
+
if (zip.readUInt32LE(localAt) !== LOCAL || zip.readUInt16LE(localAt + 4) !== NEEDED || zip.readUInt16LE(localAt + 6) !== 0 || zip.readUInt16LE(localAt + 8) !== 0
|
|
137
|
+
|| zip.readUInt16LE(localAt + 10) !== DOS_TIME || zip.readUInt16LE(localAt + 12) !== DOS_DATE || zip.readUInt32LE(localAt + 14) !== crc
|
|
138
|
+
|| zip.readUInt32LE(localAt + 18) !== size || zip.readUInt32LE(localAt + 22) !== size || zip.readUInt16LE(localAt + 26) !== nameLength || zip.readUInt16LE(localAt + 28) !== 0
|
|
139
|
+
|| !zip.subarray(localAt + 30, localAt + 30 + nameLength).equals(nameBytes)) fail('The package has an entry whose header does not match its directory.');
|
|
140
|
+
const bytes = Buffer.from(zip.subarray(localAt + 30 + nameLength, localAt + 30 + nameLength + size));
|
|
141
|
+
if (crc32(bytes) !== crc) fail('The package holds a damaged file.');
|
|
142
|
+
files.push({ rel, bytes });
|
|
143
|
+
dataAt = localAt + 30 + nameLength + size;
|
|
144
|
+
at += 46 + nameLength;
|
|
145
|
+
}
|
|
146
|
+
if (at !== endAt || dataAt !== directoryAt) fail('The package has bytes its directory does not account for.');
|
|
147
|
+
if (!seen.has('manifest.json')) fail('The package has no manifest.');
|
|
148
|
+
return files;
|
|
149
|
+
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
|
-
import {
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
3
|
import { chmodSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { compareVersions } from './browser-extension-folder.js';
|
|
5
5
|
import { dirname } from 'node:path';
|
|
6
6
|
import { lookup } from 'node:dns/promises';
|
|
7
7
|
import { WebSocketServer } from 'ws';
|
|
8
|
-
import { anyOrigin, channel, command, COMMAND_WAIT, CONTROL, controlSurface, equalMac, ERROR_TEXT, fail, handle, HISTORY, inventory, localHost, mac, MAX_MESSAGE, nonce, object, pairingKey, parse, payload, portOf, publicOrigin, safeError, string } from '
|
|
8
|
+
import { anyOrigin, channel, command, COMMAND_WAIT, commandWait as operationWait, CONTROL, controlSurface, equalMac, ERROR_TEXT, fail, handle, HISTORY, inventory, localHost, LONG_OPS_SINCE, longOp, mac, MAX_MESSAGE, nonce, object, pairingKey, parse, payload, portOf, publicOrigin, safeError, string } from './browser-extension-protocol.js';
|
|
9
|
+
import { EXTENSION_ID } from './browser-extension-pin.js';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
// The wire contract is the app's own copy of the extension's protocol.js (kept byte-identical by
|
|
12
|
+
// scripts/extension/check-browser-extension-pin.mjs), and the extension's identity is the app's pin: the server
|
|
13
|
+
// starts, restores a pairing and checks an Origin with no extension folder anywhere.
|
|
14
|
+
export { EXTENSION_ID };
|
|
12
15
|
const empty = () => ({ tabs: [], sites: [], allowNewTabs: false, uploads: false, downloads: false });
|
|
13
16
|
export async function publicDestination(url, resolver = lookup) {
|
|
14
17
|
const origin = publicOrigin(url);
|
|
@@ -52,6 +55,8 @@ export function createBridgeStore(path) {
|
|
|
52
55
|
/** Isolated loopback transport. Constructing it neither listens nor reads/writes user data (restore() does). */
|
|
53
56
|
// `commandWait` is how long a request waits for the extension's answer (COMMAND_WAIT; smaller only in tests), on the
|
|
54
57
|
// monotonic `clock`. Each command carries what is left of that wait when it is sent, as its `deadline`.
|
|
58
|
+
// A long operation (protocol.js longOp: `evaluate`, `wait` with `loadState`) waits its own time instead: its timeout
|
|
59
|
+
// plus a margin, at most LONG_WAIT (protocol.js commandWait). A smaller `commandWait` (tests) bounds those too.
|
|
55
60
|
// `fullControl` is the mode before the owner chose one (on: agents may use any http(s) site and any tab of the paired
|
|
56
61
|
// browser; off: only what the owner shares). `store` keeps the pairing and the mode across restarts (createBridgeStore).
|
|
57
62
|
// SynaBun's own addresses stay out of reach in both modes: `forbiddenOrigins` (its public aliases, any port),
|
|
@@ -61,6 +66,7 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
61
66
|
commandWait = COMMAND_WAIT, clock = () => performance.now(), fullControl = true, store = null, blockedPorts = () => [], selfHosts = () => [],
|
|
62
67
|
lookupAddresses = host => lookup(host, { all: true }) } = {}) {
|
|
63
68
|
if (!Number.isSafeInteger(commandWait) || commandWait < 1 || commandWait > COMMAND_WAIT) fail('INVALID_MESSAGE');
|
|
69
|
+
const waitOf = (op, args) => commandWait < COMMAND_WAIT ? commandWait : operationWait(op, args);
|
|
64
70
|
let server, wss, listening, pair = null, credential = null, peer = null, state = empty(), enabled = true;
|
|
65
71
|
// The owner's mode and its version. The newer version wins on either side: the server's (Settings) or the
|
|
66
72
|
// extension's (its popup, reported in an inventory). Only the owner changes it: setMode() behind the owner route,
|
|
@@ -188,8 +194,9 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
188
194
|
}
|
|
189
195
|
try {
|
|
190
196
|
authorize('upload', p.tab, p.owner, p.args);
|
|
191
|
-
const bytes = p.upload.read(p.nextFile++);
|
|
192
|
-
res.writeHead(200, { 'Cache-Control': 'no-store', 'Content-Type':
|
|
197
|
+
const { bytes, type, lastModified } = p.upload.read(p.nextFile++);
|
|
198
|
+
res.writeHead(200, { 'Cache-Control': 'no-store', 'Content-Type': type, 'Content-Length': bytes.length,
|
|
199
|
+
'X-Content-Type-Options': 'nosniff', 'X-SynaBun-Last-Modified': lastModified }).end(bytes);
|
|
193
200
|
} catch (error) {
|
|
194
201
|
res.writeHead(400, { 'Cache-Control': 'no-store' }).end(safeError(error).code);
|
|
195
202
|
}
|
|
@@ -224,7 +231,8 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
224
231
|
outbound = outbound.catch(() => {}).then(async () => {
|
|
225
232
|
if (body.type === 'command') {
|
|
226
233
|
check();
|
|
227
|
-
|
|
234
|
+
const p = pending.get(body.id);
|
|
235
|
+
body = command({ ...body, deadline: Math.max(1, Math.min(p.wait, Math.floor(p.expires - clock()))) });
|
|
228
236
|
}
|
|
229
237
|
await wire.encode(body, raw => { check(); if (ws.readyState !== 1) fail('NOT_CONNECTED'); ws.send(raw); });
|
|
230
238
|
}); return outbound;
|
|
@@ -295,6 +303,9 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
295
303
|
function authorize(op, tab, owner, args = {}) {
|
|
296
304
|
authorizeAccess(op, tab, owner, args);
|
|
297
305
|
if (op === 'upload' && compareVersions(peer.version, '1.3.0') < 0) fail('UPLOAD_RELOAD_REQUIRED');
|
|
306
|
+
// An extension from before the long operations ends the connection on a command it does not know (its payload()
|
|
307
|
+
// throws while it authenticates the message): it is never sent one. The owner reloads the extension instead.
|
|
308
|
+
if (longOp(op, args) && compareVersions(peer.version, LONG_OPS_SINCE) < 0) fail('EXTENSION_RELOAD_REQUIRED');
|
|
298
309
|
}
|
|
299
310
|
function authorizeAccess(op, tab, owner, args) {
|
|
300
311
|
if (!enabled || !peer || peer.ws.readyState !== 1) fail('EXTENSION_NOT_CONNECTED');
|
|
@@ -325,7 +336,10 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
325
336
|
// The revocation generation this command was issued in; an owner revocation that begins later cancels it.
|
|
326
337
|
const issued = revocations, stale = () => !CONTROL.includes(op) && issued !== revocations;
|
|
327
338
|
if (pending.size >= 32) fail('TIMEOUT');
|
|
328
|
-
|
|
339
|
+
// This command's wait: an ordinary command's, or a long operation's own. The timer, `expires` and the deadline the
|
|
340
|
+
// command carries are all this one number.
|
|
341
|
+
const wait = waitOf(op, args);
|
|
342
|
+
const msg = command({ type: 'command', id: nonce(), op, tab, owner, args, ...targets(), deadline: wait });
|
|
329
343
|
try {
|
|
330
344
|
authorize(op, tab, owner, args);
|
|
331
345
|
const version = revision, connection = peer, full = mode.fullControl;
|
|
@@ -347,8 +361,8 @@ export function createExtensionBridge({ port = 3345, log = () => {}, onInventory
|
|
|
347
361
|
const timer = setTimeout(() => {
|
|
348
362
|
pending.delete(msg.id); reject(Object.assign(new Error('TIMEOUT'), { code: 'TIMEOUT' }));
|
|
349
363
|
if (peer === via && via.ws.readyState === 1) void via.send({ type: 'cancel', id: msg.id }).catch(() => {});
|
|
350
|
-
},
|
|
351
|
-
pending.set(msg.id, { resolve, reject, timer, op, tab, owner, args, upload, nextFile: 0, issued, expires: clock() +
|
|
364
|
+
}, wait);
|
|
365
|
+
pending.set(msg.id, { resolve, reject, timer, op, tab, owner, args, upload, nextFile: 0, issued, wait, expires: clock() + wait });
|
|
352
366
|
via.send(msg).catch(error => { clearTimeout(timer); pending.delete(msg.id); reject(['CANCELLED', 'TIMEOUT'].includes(error?.code) ? coded(error.code)() : notConnected()); });
|
|
353
367
|
});
|
|
354
368
|
if (HISTORY.includes(op) && result.ok) {
|