修复移动端首屏并加固安全配置#133
Open
Hill-1024 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
这次修复来自对 OpenCodeUI 的一次前端问题排查与安全检查。检查过程中发现三个可以独立改善的问题:
package-lock.json中存在npm audit可识别、可自动修复的 transitive dependency 漏洞版本。security.csp为null,等于关闭 WebView 的 Content Security Policy,防护边界偏弱。本 PR 对这三点做了集中修复。
修复内容与修复方式
1. 修复移动端首屏误停在左侧栏
问题原因
移动端布局使用 pager 在左侧栏、聊天区、右侧面板之间切换。原逻辑在移动端初始化时会根据
sidebarExpanded决定应该滚动到哪个页面:rightPanelOpen为 true 时进入右侧面板;sidebarExpanded为 true,就进入左侧栏;这在桌面状态和移动状态复用同一个侧边栏展开状态时会出问题:如果侧边栏状态为默认展开,或者来自持久化状态,移动端首次进入时就会直接停在左侧栏,聊天主区域被挤到屏幕外。
修复方式
在
src/App.tsx中调整移动端 pager 初始化逻辑:isInitializing判断,区分首次初始化和后续交互同步。chat页面。setSidebarExpanded(false),避免桌面侧边栏展开状态继续影响移动端首屏。这样移动端首次打开时会稳定展示聊天主界面,同时不破坏侧边栏按钮的正常交互。
影响文件:
src/App.tsx2. 修复 npm audit 发现的依赖漏洞
问题原因
使用 npm 官方 registry 执行安全审计时,
package-lock.json中存在可修复的 transitive dependency 漏洞版本,涉及:@babel/coredompurifyjs-yamlundici这些依赖虽然不是全部由项目直接声明,但 lockfile 会决定
npm ci/npm install的实际安装版本,因此仍然会影响本地开发、CI 和打包环境的依赖安全状态。修复方式
执行:
修复结果:
package-lock.json中的解析版本。package.json的直接依赖声明。0 vulnerabilities。影响文件:
package-lock.json3. 启用 Tauri WebView CSP
问题原因
原配置中:
这会关闭 Tauri WebView 的 Content Security Policy。考虑到 OpenCodeUI 会渲染后端/模型返回的 Markdown、Mermaid/SVG 等内容,同时 Tauri 环境中存在 HTTP、文件和 bridge 能力,关闭 CSP 会降低 WebView 注入类问题出现时的防护能力。
这不是一个已经验证出可直接利用的 XSS 漏洞,但属于明显的安全加固点:即使当前 Markdown 渲染链路已有 sanitize/harden 和 Mermaid strict mode,CSP 仍然应作为额外防线存在。
修复方式
将
src-tauri/tauri.conf.json中的csp: null替换为显式 CSP:default-src 'self'script-src 'self' 'wasm-unsafe-eval'style-src 'self' 'unsafe-inline'img-src、font-src、connect-src、media-src、frame-srcobject-src 'none'base-uri 'self'这个策略保留应用当前运行所需的 Tauri IPC、wasm、样式、图片、字体、HTTP/HTTPS、WebSocket、媒体和 frame 场景,同时恢复浏览器层面的基础安全约束。
影响文件:
src-tauri/tauri.conf.json安全检查结果
修复后对当前工作树重新做了安全检查,结论是:当前改动范围内没有未修复的 reportable security finding。
检查中还记录了两个后续可选加固方向,但不作为本 PR 的阻塞项:
http/fscapability 后续可以根据实际产品需求进一步收窄。验证
已执行并通过:
验证结果:
npm run validate通过。npm audit --audit-level=moderate结果为0 vulnerabilities。git diff --check干净。src-tauri/tauri.conf.json可被 JSON 解析。npx tauri info可以读取配置并显示新的 CSP。另外做过浏览器 QA:
备注:浏览器 QA 时未启动 OpenCode backend,因此控制台里连接
127.0.0.1:4096的 fetch/SSE 报错属于预期现象。