feat(web): preview .html refs in sandboxed iframe#59
Merged
Conversation
Previously .html refs fell through to the text/<pre> branch and showed escaped source code instead of a rendered page (designer mock html opened from a thread was unreadable). Add a dedicated branch in selectRef() that renders text/html (or any ref whose label ends in .html/.htm/.xhtml) via an iframe with `srcdoc` + `sandbox=""` (strictest: no scripts, forms, top-nav, same-origin). Safe for designer mocks; intentional executable html still needs an opt-in later.
🤖 bot-review (comment-only · phase 1)Diff: Red-line checks:
Phase 1: this bot leaves comments only. Auto-approve will be enabled per-path after 1–2 weeks of clean runs. Promotion plan: judy PR #42 follow-up. |
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.
问题: thread 里点开 .html ref(如 dora 的设计稿)会显示转义后的源码,不能直接 review。
根因:
web/app.js的selectRef()里只处理了 image / markdown / json,其它统统走<pre>escapeHtml(text)</pre>,HTML 因此被当文本贴出来。修法: 加一个分支,对
text/html或 .html/.htm/.xhtml 后缀的 ref 用 iframe +srcdoc+sandbox=""渲染。沙箱: 空字符串 sandbox = 最严格(无脚本、无 form 提交、无 top-nav、视为另一个 origin),design mock 完全够用,也防御 ref 里塞恶意脚本。后续若有真要执行 JS 的内部页面再做白名单开关。
Scope: 纯前端 11 行,server 端 mime 已经允许 text/* 不用动。