Skip to content

[Bug] HTML 预览:工作区外文件点「临时解锁」仍 forbidden,刷新又回沙箱——解锁不解路径围栏,形成死循环(关联 #532) #571

Description

@Ztyss

现象

dsh-better-sidebar 0.18.0 / DSH Desktop(Web GUI)/ Windows 11。打开工作区外.html 文件(如 %TEMP% 下的本地 HTML):

  1. 沙箱状态栏显示"沙箱模式:已启用 · 页面无法访问界面数据与本地文件" → 页面正文显示 forbidden
  2. 点击「临时解锁(不安全)」:状态栏变为红色"未沙箱",但页面内容依然是 forbidden
  3. 点击刷新:回到沙箱模式(解锁态不保留);
  4. 结果:工作区外的 HTML 文件永远无法预览

根因(代码层面,供排查)

  1. forbidden 来自 host 路径围栏,不是 iframe 沙箱:HTML 预览走 /html 路由(html-route.ts),工作区外路径被 real-path guard 拒绝(403 + 裸文本 forbiddenapi.ts 注释:request-trust fence answers code forbidden with the bare message 'forbidden')。用户打开的文件在会话工作区之外(如 %TEMP%),路由必然拒绝。
  2. 「临时解锁」只改 iframe sandbox 属性localUnlock → noSandboxBrowserView.tsx / TextEditor.tsx),不影响 host 读取围栏——iframe 解锁后请求同一 /html/... URL 仍被 403,所以页面依旧 forbidden
  3. 解锁态是组件 useState,不写全局设置(SandboxStatusBar.tsx 注释明示 temporary unlock is component state only… lasts until the surface unmounts),刷新/切 tab 即复位 → 每次刷新都回到沙箱。

三条叠加 = "解锁无效 + 刷新即锁定"的死循环。

期望

  1. 「临时解锁」应同时放行该文件在 html 路由的只读读取(临时白名单:仅当前文件/当前 tab),或提供工作区外文件的只读预览兜底(关联 点击对话中工作区外的文件引用报 403 path is outside workspace,期望降级为只读预览或回退系统打开 #532 / [Feature] Add an option to access files outside the workspace #442);
  2. 临时解锁跨刷新保留(如 sessionStorage 按 tab 持久化),避免"解锁→刷新→锁定"死循环;
  3. 或扩展全局设置语义:现有 htmlViewerNoSandbox 只解 iframe 沙箱、不解路径围栏,文档需说明或联动路径放行。

关联

环境:DSH Desktop 2.0.4 / Windows 11 / dsh-better-sidebar 0.18.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions