Skip to content

feat(remote-access): 中继可配置允许嵌入的页面(关联 #116) - #205

Merged
freedomkk-qfeng merged 3 commits into
ECNU:mainfrom
JunieXD:feat/116-relay-frame-ancestors
Oct 22, 2026
Merged

freedomkk-qfeng merged 3 commits into
ECNU:mainfrom
JunieXD:feat/116-relay-frame-ancestors

Conversation

@JunieXD

@JunieXD JunieXD commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

问题与修改

关联 #116。中继网页的 CSP 固定为 frame-ancestors 'none',机构门户无法用 iframe 嵌入远程访问页面。

  • 中继新增 RELAY_FRAME_ANCESTORS,列出允许嵌入中继网页的页面来源,多个用空格分隔:与中继同源的页面写 self,其他页面写来源,例如 https://portal.example.edu。不设置时仍为 'none'。
  • Shell 和 docker compose 读取的 env 文件都会去掉引号:实测 relay.env 中写 RELAY_FRAME_ANCESTORS='self',容器收到的是 self。CSP 会把不带引号的 self 当作主机名,嵌入被静默拒绝。因此关键字带不带引号都接受;无法识别的值(例如缺少协议、带路径)使中继拒绝启动并说明原因。
  • Service Worker 返回的 DSH 界面文档没有自己的嵌入限制,是否允许嵌入只由加载页决定。
  • 包 README 补充配置方法、iframe 不要加 sandbox、嵌入页面应与中继同站,以及安全提示:允许嵌入的页面能遮挡中继网页、诱导用户点击。

验证

  • packages/dsh-remote-access:npm run check,含类型检查、构建与 73 个测试,全部通过;新增取值解析和响应头测试。
  • node scripts/check-web.ts:Chromium 与 WebKit 各在根路径、/eduwork-remote/,以及中继在 /eduwork-remote/ 下被同域门户页面嵌入(RELAY_FRAME_ANCESTORS=self)时运行,配对、RPC、流、上传、下载、断线重连、撤销均通过。未设置时检查门户页面无法嵌入;临时让中继始终允许嵌入时,这项检查失败。
  • 构建后的 lib/relay.js 以不同取值启动,核对响应头:未设置或留空为 'none',self 与 'self' 为 'self',多个来源原样列出;缺少协议或带路径的值拒绝启动。
  • 跨站嵌入(门户在 localhost、中继在 127.0.0.1):Chromium 全流程通过;WebKit 中配对和 Service Worker 注册成功,但 Service Worker 无法加载电脑的界面,因此 README 要求同站嵌入。同站不同子域名需要 HTTPS 环境,未测。
  • tests/package-maintenance.test.mjs 5 个通过;source-receipt.json 已刷新,--verify-receipt 无错误。

兼容性与后续事项

不设置时行为不变。CHANGELOG 未改。

JunieXD and others added 3 commits October 22, 2026 23:58
The loader page refused every frame. RELAY_FRAME_ANCESTORS now lists the
pages that may embed it, as the CSP frame-ancestors sources: 'self' for a
portal on the relay's own origin, or origins such as
https://portal.example.edu. It stays 'none' when unset. Shells and the env
files docker compose reads strip the quotes, so the keywords are taken
with or without them; anything else stops the relay with a message
rather than leaving a policy that silently refuses the portal.

The interface document the Service Worker serves sets no frame policy of
its own, so the loader page's decides. check-web also runs a relay below
a path that lets its domain embed it, inside a portal page of that
domain, and checks that without the setting the portal gets no page.
@freedomkk-qfeng
freedomkk-qfeng merged commit aa6fa4c into ECNU:main Oct 22, 2026
6 checks passed
@JunieXD
JunieXD deleted the feat/116-relay-frame-ancestors branch October 28, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants