DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(csp): connect-src 放行本地实例,修复壳层 /api-ssh 被 CSP 拒绝
hairyfdc78347049be
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex 74a8c3b9..fe49b79a 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -12,8 +12,8 @@"app": {"macOSPrivateApi": true,"security": {- "csp": "default-src 'self'; connect-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost data: blob: https://*.githubusercontent.com; media-src 'self' data: blob: https://*.githubusercontent.com; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self'; frame-src http://127.0.0.1:*",- "devCsp": "default-src 'self'; connect-src 'self' ipc: http://ipc.localhost http://localhost:1420 ws://localhost:1421; img-src 'self' asset: http://asset.localhost data: blob: https://*.githubusercontent.com; media-src 'self' data: blob: https://*.githubusercontent.com; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self'; frame-src http://127.0.0.1:*"+ "csp": "default-src 'self'; connect-src 'self' ipc: http://ipc.localhost http://127.0.0.1:*; img-src 'self' asset: http://asset.localhost data: blob: https://*.githubusercontent.com; media-src 'self' data: blob: https://*.githubusercontent.com; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self'; frame-src http://127.0.0.1:*",+ "devCsp": "default-src 'self'; connect-src 'self' ipc: http://ipc.localhost http://localhost:1420 ws://localhost:1421 http://127.0.0.1:*; img-src 'self' asset: http://asset.localhost data: blob: https://*.githubusercontent.com; media-src 'self' data: blob: https://*.githubusercontent.com; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self'; frame-src http://127.0.0.1:*"}},"plugins": {diff --git a/test/shell-csp.test.ts b/test/shell-csp.test.tsnew file mode 100644index 00000000..73fb08c9--- /dev/null+++ b/test/shell-csp.test.ts@@ -0,0 +1,28 @@+import { readFileSync } from 'node:fs'+import { describe, expect, it } from 'vitest'++/**+ * 壳层自己(不是 iframe 里的网页)要跨源 POST 本地实例的 `/api-ssh`——远端机器+ * 切换器的秒级轮询走这条路。`connect-src` 漏掉本地实例来源时,fetch 被文档 CSP+ * 直接拒掉,控制台只刷「Refused to connect because it violates the document's+ * Content Security Policy」,切换器静默降级,功能整个不可用。端口因占用冲突会+ * 自动递增(见后端 runtime info),所以只能按 host 通配。+ */+const config = JSON.parse(+ readFileSync(new URL('../src-tauri/tauri.conf.json', import.meta.url), 'utf8'),+) as { app: { security: Record<'csp' | 'devCsp', string> } }++const serviceOrigin = /DSH_HOST: &str = "([^"]+)"/.exec(+ readFileSync(new URL('../src-tauri/src/config/constants.rs', import.meta.url), 'utf8'),+)?.[1]++describe('shell CSP loopback data plane', () => {+ it('reads the loopback service host from the Rust constants', () => {+ expect(serviceOrigin).toBe('http://127.0.0.1')+ })++ it.each(['csp', 'devCsp'] as const)('%s lets the shell fetch the local dsh instance', (key) => {+ const connectSrc = /(?:^|; )connect-src ([^;]+)/.exec(config.app.security[key])?.[1] ?? ''+ expect(connectSrc).toContain(`${serviceOrigin}:*`)+ })+})