mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): widen bounded wasm ui output
This commit is contained in:
1 parent
ab36825a56
commit
c3810a177a
6 files changed
+253
-10
No files matched your search
@@ -39,7 +39,8 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖
|
||||
|
||||
- 现有 JavaScript Worker 因缺少硬内存配额继续关闭;Wasmi 原型用独立 Worker、解释器内存上限、扩展燃料上限和超时终止运行非可信 Wasm。
|
||||
- 当前增量加入 `env.ui_emit_json`:单次运行最多输出一次、不超过 16 KiB 的 UTF-8 UI 数据。宿主只接收有界字符串,不执行 HTML/JS,也不允许通过该接口触发 TeamSpeak 动作。
|
||||
- 已实现严格 UTF-8 大小、JSON 与 schema v3 校验,以及供 `SkinPluginOutlet` 使用的安全合并入口;目前只有单元/SSR 测试通过该入口传入输出,尚无生产客户端把 Wasm 结果接到该属性。输出不能请求皮肤权限、替换页面、嵌入宿主控件或调用 TeamSpeak 动作;仅可使用组件本地状态和 `ui.setState` / `ui.toggleState`。
|
||||
- 已实现严格 UTF-8 大小、JSON 与 schema v3/v4 输出校验,以及供 `SkinPluginOutlet` 使用的合并入口;v4 输出可以组合较完整的安全 HTML/SVG 节点、ARIA/data 属性与包内图片引用。自定义标签会由宿主渲染为惰性占位 `div`,不实例化页面中可能注册的 Web Component。输出仍不能定义事件、读取数据、请求皮肤权限、替换页面、嵌入宿主控件或调用 TeamSpeak 动作;目前只有单元/SSR 测试经过该入口,尚无生产客户端把 Wasm 结果接到该属性。
|
||||
- 这一步只拓宽可生成的界面结构,不是完整插件运行时,也不是“万物皆插件”目标的替代品。后续还要为 Wasm 作者逻辑设计有界状态、用户事件协议、受权限控制的数据投影/宿主动作和完整插件生命周期,并接入实际客户端。
|
||||
- 这是一次性输出的受限原型,不构成完整插件运行时。生产开关关闭;后续须更换为有版本、权限、事件、生命周期和资源治理的插件协议,并做端到端与独立安全审查。
|
||||
|
||||
### R3.3:完整自定义插件运行时(未完成,优先阶段)
|
||||
@@ -53,12 +54,14 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖
|
||||
- 插件对 TeamSpeak 的读取和操作经明确列举的权限、脱敏投影和宿主能力桥接;命令总由宿主校验参数、当前会话和权限。双击等事件只改变插件化界面的触发方式,不更改 TeamSpeak 协议,也不影响未启用该插件的其他皮肤。
|
||||
- 沙箱架构还未选定。opaque-origin iframe 可以隔离父页面 DOM 和存储,但不等于网络隔离:浏览器仍允许 frame 自己导航,`sandbox` 主要阻止顶层导航;CSP `navigate-to` 也不能作为跨浏览器阻断保证。若 iframe 同时持有获批的会话数据,插件可尝试把数据编码进自己的导航 URL。详见 R3.3 问题记录。不得因此把任意 JS 放进有浏览 DOM 的 iframe。
|
||||
- 已有安全原型把作者 JavaScript 放在没有 DOM/导航上下文的 data Worker 中,由 opaque-origin iframe 只负责消息桥;Worker CSP 可限制常规网络请求,但没有硬内存上限,仍保持生产关闭。下一版运行时必须同时保留完整自定义 UI 能力和确定的计算/内存边界:优先评估有界解释器 + 宿主创建的通用自定义节点树/CSS;不能以牺牲 DOM/事件自定义为理由退回固定原生控件目录。
|
||||
- 新增一次 Wasm 生成 UI 的安全结构试验:输出 schema v4 提供常见安全 HTML/SVG、任意 `data-*`/`aria-*` 和惰性自定义元素占位,再由宿主渲染;节点/组件/属性/文本仍有硬上限,危险加载、导航、脚本和事件属性会被拒绝。它保留完整结构方向,但现在没有事件回调和宿主能力桥,且 Wasm 仍未接入生产生命周期。
|
||||
- 插件生命周期包括批准前不加载、逐插件/逐权限批准、版本变化重新确认、撤销立即销毁上下文、超时/输出限额/崩溃隔离、旧包兼容和宿主恢复 UI。完整威胁模型、资源耗尽与跨浏览器测试未完成前不启用生产运行开关。
|
||||
- 复核零新增预算约束:插件及本地素材随皮肤包分发,不依赖 CDN、外部脚本托管或付费沙箱服务。
|
||||
|
||||
#### R3.3 问题记录
|
||||
|
||||
- 首个 v4 沙箱候选把 opaque-origin iframe 当成了“无网络”边界。复核浏览器规则发现沙箱 frame 仍有自己的文档和 URL 导航能力,`allow-top-navigation` 仅控制顶层页面;当前 MDN browser-compat-data 也没有 `navigate-to` 指令条目。因而 `connect-src 'none'`、禁用表单/弹窗和 CSP 元标签不足以证明获批数据不会通过 frame 导航外传。否决 iframe 直接执行作者 JS 的方案;保留现有只运行于无 DOM Worker 的原型,但 JS 内存无硬上限,继续关闭生产执行。下一步必须通过可计量执行环境承载作者逻辑,并由可信宿主创建/校验通用自定义 UI 树与 CSS,再验证事件到 TeamSpeak 能力的桥接。
|
||||
- Wasm UI 输出原先经过扩展校验后又送入 v3 固定标签/属性解析器,导致打开节点协议时整份扩展 UI 被悄悄丢弃。现改为分别校验基础皮肤和生成输出,只在组件 ID 不冲突且合并数量有界时组合,并额外把自定义标签渲染为惰性 `div`。目前仍缺用户事件和能力授权桥接,不代表完整运行时已完成。
|
||||
|
||||
### R3.4:声明式自定义节点布局编辑(已实施)
|
||||
|
||||
@@ -85,7 +88,7 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖
|
||||
- surface 的“恢复内置皮肤”按钮误接到仅用于皮肤加载错误的回退函数,正常皮肤下点击无效。已改为明确切换到当前主题对应的内置皮肤,并增加授权/撤销回归。
|
||||
- 初版自定义服务器栏只有收藏数据,缺少最近连接项。新增 `servers.quickList` 和宿主切换动作,使用不透明令牌,不下放目标地址或凭据。
|
||||
- 收藏名/最近连接显示名有时会直接等于服务器地址;投影数据前增加地址匹配与泛化标签,避免通过“显示名”字段间接暴露连接目标。
|
||||
- KOOK 浏览器此前的读取和点击曾超时;恢复后已进入用户授权的前两个语音频道并检查频道页面截图,麦克风保持关闭,完成后断开连接。确认了服务器轨道、频道列表、中心聊天区、成员侧栏和语音控制卡的相对位置。没有记录频道标识、成员名单或聊天内容;陪玩店、活动通知、广告及其他运营页面不作为参考。
|
||||
- 已获准进入 KOOK 服务器的前两个语音房,包括用户管理的第二个房间。DOM 结构显示左侧服务器轨道与频道树、中间语音舞台、右侧房间消息栏,以及左下连接控制卡(降噪、麦克风、耳机);成员状态挂在语音频道下。未打开管理员菜单、未发消息、未启用麦克风,也未保留房间标识、成员姓名或聊天文本。浏览器截图接口超时,参考只来自可访问 DOM 与布局尺寸;返回原发现页后语音界面和连接卡消失,但没有单独验证服务端在线状态。陪玩店、活动通知、广告及其他运营页面不作为参考。
|
||||
- 用户指出“有限自定义”与目标不符。核查确认当前 v3 仍固定标签/属性白名单、六种可重复数据集、模板插值和有限宿主动作;一次 Wasm 输出尚未接进生产 UI 生命周期。此处列为 R3.3 的首要差距,不以增加几个声明式动作或宿主控件替代完整插件运行时。
|
||||
- 已确认 schema 支持 `dblclick`。KAAK 频道行现在只在双击时请求宿主加入频道;这属于单个皮肤包的界面映射,其他皮肤与 TeamSpeak 协议保持不变。
|
||||
|
||||
|
||||
@@ -98,5 +98,5 @@ v3 CSS 和 surface 可排列、替换或遮挡公开 UI,因此可能改变麦
|
||||
- 扩展数据字段或宿主动作时,增加精确 schema、权限、明确用户事件约束和宿主侧运行时验证,不暴露内部 SDK 对象。新增宿主控件也必须登记固定 ID、明确页面和确认只在宿主内处理其私有状态;自定义声明式 UI 不应被限制为只能拼装这组控件。
|
||||
- 对恶意输入、路径别名、拒绝授权、撤销、更新和皮肤切换增加测试;高敏能力必须单独设计。
|
||||
- 当前 JavaScript Worker 与 Wasm 扩展运行时都保持生产关闭。JavaScript Worker 缺少硬内存配额;Wasmi 解释器目前只是受限原型:解释器容器上限 64 MiB,扩展线性内存最多 4 MiB,燃料上限 10,000,000,外层 Worker 在 100 ms 后可终止执行。
|
||||
- Wasm 原型新增 `env.ui_emit_json`,每次运行最多提交一次、最多 16 KiB 的 UTF-8 字符串。当前已通过共享组件 schema v3 校验,再由 `SkinPluginOutlet` 以安全节点渲染;非法 JSON/schema、重复组件 ID 或超限输出会被拒绝并保留原皮肤 UI。该输出不能请求皮肤权限、替换页面、嵌入宿主控件或调用 TeamSpeak 动作,只能使用局部状态和 `ui.setState` / `ui.toggleState`。它不会被当成 HTML 或脚本执行,也不授予网络或存储权限。Wasm 执行仍未连接到生产客户端;完成扩展级授权/撤销衔接、资源耗尽测试、端到端验证和独立安全审查之前,不得启用运行开关。
|
||||
- Wasm 原型新增 `env.ui_emit_json`,每次运行最多提交一次、最多 16 KiB 的 UTF-8 字符串。输出 schema v3 仍可使用原有声明式节点;schema v4 允许较完整的安全 HTML/SVG 节点、ARIA/data 属性及包内图片引用。宿主独立校验后创建节点,不把输出当成 HTML 字符串执行;自定义标签映射为惰性宿主 `div`,避免触发页面已注册 Web Component。脚本/框架、事件属性、外部资源和导航目标会被拒绝,非法 JSON/schema、重名组件或超限输出会被丢弃并保留包内 UI。当前 v4 输出仍不能定义事件回调、读取数据、请求皮肤权限、替换页面、嵌入宿主控件或调用 TeamSpeak 动作。Wasm 执行仍未连接到生产客户端;它只是扩宽结构的安全试验,并非完整插件能力。完成有界事件与宿主能力桥、扩展级授权/撤销衔接、资源耗尽测试、端到端验证和独立安全审查之前,不得启用运行开关。
|
||||
- 商城发布、签名、下架、更新和撤销设计与管理员面板重做一起验收,且保持零新增服务费用为默认约束。
|
||||
@@ -147,7 +147,9 @@ components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。s
|
||||
|
||||
示例包见 [KAAK voice 示例](./examples/KAAK-VOICE.md),其 components.json 展示了公开频道列表和在线成员侧栏;[Open Voice Surface](./examples/OPEN-VOICE-SURFACE.md) 展示了完整首页和语音工作区 surface,是格式验证脚手架。KAAK 的语音视觉参考来自用户授权进入的前两个语音房间;只记录布局,不保留服务器/房间标识、成员名或聊天内容。当前数据权限和宿主动作以[开放皮肤规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)中的清单为准。组件按本地用户授权后才渲染;权限对每个皮肤版本、页面和组件分别保存,可在宿主权限入口撤销。页面替换时,宿主会额外显示“返回标准界面”和“恢复内置皮肤”入口;拒绝授权或离开 surface 后,普通页面可立即恢复。
|
||||
|
||||
组件树有硬上限:components.json 256 KiB。schema v1/v2 上限为 32 个组件、每组件 256 个模板节点、16 层深度和 100 条重复记录;schema v3 上限为 128 个组件、每组件 2048 个模板节点、32 层深度和 250 条重复记录,并允许 64 个本地标量状态与 64 个动作。图片资源只能从包内引用,CSS 不能读取外部 URL、脚本或浏览器存储。宿主动作需显式权限,并只能绑定可信的用户事件;输入或 change 事件不能触发宿主动作。focus/blur、hover 和 drag-start/over 等被动事件只可改动组件本地状态,不能触发语音操作。
|
||||
组件树有硬上限:components.json 256 KiB。schema v1/v2 上限为 32 个组件、每组件 256 个模板节点、16 层深度和 100 条重复记录;schema v3 上限为 128 个组件、每组件 2048 个模板节点、32 层深度和 250 条重复记录,并允许 64 个本地标量状态与 64 个动作。当前 Wasm 输出的 schema v4 另有 16 KiB 总输出上限、最多 64 个组件、每个节点最多 64 个属性和 256 个子节点,并沿用每组件节点/深度限制;它可使用更广的安全 HTML/SVG 结构、ARIA/data 属性和包内图片。任意自定义元素名称会映射为惰性 `div` 占位,不触发宿主页定义的 Web Component。外部 URL、脚本/框架、事件属性和导航目标会拒绝。该 v4 仅扩大 UI 结构,暂不提供事件回调、数据读取或 TeamSpeak 动作,也未连接生产插件生命周期,不能当作完整插件运行时。
|
||||
|
||||
图片资源只能从包内引用,CSS 不能读取外部 URL、脚本或浏览器存储。宿主动作需显式权限,并只能绑定可信的用户事件;输入或 change 事件不能触发宿主动作。focus/blur、hover 和 drag-start/over 等被动事件只可改动组件本地状态,不能触发语音操作。
|
||||
|
||||
注意:v3 CSS 和 surface 可以隐藏或遮挡普通语音控件。权限和返回标准界面提示由宿主在皮肤根之外绘制;其他界面控件仍受皮肤排版影响。测试时务必确保麦克风、设置、退出语音、屏幕共享操作和移动端导航仍有可达路径。组件演示页 /demo 使用合成数据,加入频道和聊天动作只更新演示状态;它不支持宿主控件或整页替换。
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
SKIN_PLUGIN_NODE_LIMIT,
|
||||
SKIN_PLUGIN_TREE_DEPTH_LIMIT,
|
||||
parseSkinPluginDocument,
|
||||
type SkinPluginAction,
|
||||
type SkinPluginComponent,
|
||||
type SkinPluginDocument,
|
||||
type SkinPluginNode,
|
||||
} from "./skin-plugin.js";
|
||||
@@ -8,6 +11,38 @@ import {
|
||||
export const SKIN_EXTENSION_UI_OUTPUT_LIMIT_BYTES = 16 * 1024;
|
||||
|
||||
const LOCAL_UI_ACTIONS = new Set<SkinPluginAction>(["ui.setState", "ui.toggleState"]);
|
||||
const GENERATED_COMPONENT_LIMIT = 64;
|
||||
const GENERATED_CHILD_LIMIT = 256;
|
||||
const GENERATED_ATTRIBUTE_LIMIT = 64;
|
||||
const GENERATED_BLOCKED_ELEMENTS = new Set([
|
||||
"base", "embed", "frame", "frameset", "iframe", "link", "meta", "object", "portal", "script", "style", "template",
|
||||
]);
|
||||
const GENERATED_SAFE_ELEMENTS = new Set([
|
||||
"a", "abbr", "address", "article", "aside", "b", "blockquote", "br", "button", "caption", "circle", "cite", "code", "col",
|
||||
"colgroup", "dd", "del", "details", "dfn", "div", "dl", "dt", "em", "fieldset", "figcaption", "figure", "footer", "g", "h1",
|
||||
"form", "h2", "h3", "h4", "h5", "h6", "header", "hr", "i", "img", "input", "kbd", "label", "legend", "li", "line", "main", "mark",
|
||||
"nav", "ol", "option", "output", "p", "path", "polygon", "polyline", "pre", "progress", "q", "rect", "s", "section", "select",
|
||||
"small", "span", "stop", "strong", "sub", "summary", "sup", "svg", "table", "tbody", "td", "text", "textarea", "tfoot", "th",
|
||||
"thead", "time", "tr", "u", "ul", "use", "wbr",
|
||||
]);
|
||||
const GENERATED_VOID_ELEMENTS = new Set([
|
||||
"br", "col", "hr", "img", "input", "line", "path", "polygon", "polyline", "rect", "stop", "use", "wbr",
|
||||
]);
|
||||
const GENERATED_SAFE_ATTRIBUTES = new Set([
|
||||
"accept", "alt", "aria-label", "aria-labelledby", "aria-describedby", "aria-live", "aria-current", "aria-expanded", "aria-hidden",
|
||||
"aria-pressed", "aria-selected", "autocomplete", "checked", "cite", "class", "colspan", "contenteditable", "controls", "coords",
|
||||
"datetime", "dir", "disabled", "draggable", "fill", "fill-rule", "height", "hidden", "high", "id", "inputmode", "label", "low",
|
||||
"max", "maxlength", "min", "minlength", "multiple", "muted", "name", "open", "optimum", "placeholder", "preload", "readonly",
|
||||
"required", "reversed", "role", "rows", "rowspan", "scope", "selected", "shape", "size", "span", "spellcheck", "start", "step",
|
||||
"stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-width", "tabindex",
|
||||
"href", "title", "transform", "type", "value", "viewbox", "width", "wrap", "x", "x1", "x2", "y", "y1", "y2", "cx", "cy", "d", "r", "rx",
|
||||
"ry", "points", "opacity", "preserveaspectratio", "vector-effect",
|
||||
]);
|
||||
const GENERATED_BLOCKED_ATTRIBUTES = new Set([
|
||||
"action", "archive", "background", "code", "codebase", "data", "download", "form", "formaction", "formmethod", "formenctype",
|
||||
"formtarget", "is", "manifest", "ping", "poster", "profile", "src", "srcdoc", "srcset", "style", "target", "xlink:href",
|
||||
"autofocus", "autoplay", "command", "commandfor", "http-equiv", "nonce", "slot",
|
||||
]);
|
||||
|
||||
export class SkinExtensionUiOutputError extends Error {
|
||||
constructor(readonly code: string, message: string) {
|
||||
@@ -25,7 +60,126 @@ function assertLocalUiNode(node: SkinPluginNode): void {
|
||||
node.children?.forEach(assertLocalUiNode);
|
||||
}
|
||||
|
||||
/** Parses Wasm output into the existing safe component tree, with no added host capabilities. */
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
||||
const prototype = Object.getPrototypeOf(value);
|
||||
return prototype === Object.prototype || prototype === null;
|
||||
}
|
||||
|
||||
function boundedText(value: unknown, maximum: number, code: string, field: string): string {
|
||||
if (typeof value !== "string" || !value.trim() || value.trim() !== value || value.length > maximum) {
|
||||
fail(code, `${field} must be bounded non-empty text.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function onlyKeys(value: Record<string, unknown>, allowed: readonly string[], context: string): void {
|
||||
if (Object.keys(value).some((key) => !allowed.includes(key))) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", `${context} has an unsupported field.`);
|
||||
}
|
||||
|
||||
function generatedNode(input: unknown, depth: number, count: { value: number }): SkinPluginNode {
|
||||
count.value += 1;
|
||||
if (count.value > SKIN_PLUGIN_NODE_LIMIT || depth > SKIN_PLUGIN_TREE_DEPTH_LIMIT || !isRecord(input)) {
|
||||
fail("SKIN_EXTENSION_UI_COMPLEXITY_LIMIT", "The generated UI tree exceeds its node or depth limit.");
|
||||
}
|
||||
onlyKeys(input, ["tag", "text", "part", "className", "attributes", "asset", "children"], "A generated UI node");
|
||||
const hasTag = input.tag !== undefined;
|
||||
const hasText = input.text !== undefined;
|
||||
if (Number(hasTag) + Number(hasText) !== 1) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "A generated node must contain either a tag or text.");
|
||||
|
||||
const node: SkinPluginNode = {};
|
||||
if (hasText) {
|
||||
if (typeof input.text !== "string" || input.text.length > 8_192) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Generated text exceeds its limit.");
|
||||
node.text = input.text;
|
||||
}
|
||||
if (hasTag) {
|
||||
const tag = boundedText(input.tag, 64, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "node.tag");
|
||||
const customElementName = /^[a-z][a-z0-9]*-[a-z0-9-]+$/.test(tag);
|
||||
if ((!GENERATED_SAFE_ELEMENTS.has(tag) && !customElementName) || GENERATED_BLOCKED_ELEMENTS.has(tag)) {
|
||||
fail("SKIN_EXTENSION_UI_ELEMENT_INVALID", `The generated element '${tag}' is not allowed.`);
|
||||
}
|
||||
node.tag = tag;
|
||||
}
|
||||
if (input.part !== undefined) {
|
||||
const part = boundedText(input.part, 64, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "node.part");
|
||||
if (!/^[a-z][a-z0-9-]*$/.test(part)) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "A generated part uses an invalid name.");
|
||||
node.part = part;
|
||||
}
|
||||
if (input.className !== undefined) {
|
||||
if (typeof input.className !== "string" || input.className.length > 512 || /[<>\u0000-\u001f]/.test(input.className)) {
|
||||
fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Generated class names must be bounded plain text.");
|
||||
}
|
||||
node.className = input.className;
|
||||
}
|
||||
if (input.attributes !== undefined) {
|
||||
if (!isRecord(input.attributes) || Object.keys(input.attributes).length > GENERATED_ATTRIBUTE_LIMIT) {
|
||||
fail("SKIN_EXTENSION_UI_ATTRIBUTE_INVALID", "Generated attributes must be a bounded object.");
|
||||
}
|
||||
const attributes: Record<string, string | number | boolean> = Object.create(null) as Record<string, string | number | boolean>;
|
||||
for (const [key, value] of Object.entries(input.attributes)) {
|
||||
const safeDataOrAria = key.startsWith("data-") || key.startsWith("aria-");
|
||||
if (!/^[a-z][a-z0-9:_-]{0,63}$/.test(key) || key.startsWith("on")
|
||||
|| key.startsWith("data-ws-") || GENERATED_BLOCKED_ATTRIBUTES.has(key)
|
||||
|| (!GENERATED_SAFE_ATTRIBUTES.has(key) && !safeDataOrAria)) {
|
||||
fail("SKIN_EXTENSION_UI_ATTRIBUTE_INVALID", `The generated attribute '${key}' is not allowed.`);
|
||||
}
|
||||
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
|
||||
fail("SKIN_EXTENSION_UI_ATTRIBUTE_INVALID", "Generated attribute values must be scalar.");
|
||||
}
|
||||
if (typeof value === "string" && value.length > 4_096) fail("SKIN_EXTENSION_UI_ATTRIBUTE_INVALID", "A generated attribute exceeds its size limit.");
|
||||
if (key === "href" && (typeof value !== "string" || !/^#[A-Za-z][A-Za-z0-9_.:-]{0,127}$/.test(value))) {
|
||||
fail("SKIN_EXTENSION_UI_ATTRIBUTE_INVALID", "Generated links may only target a same-document fragment.");
|
||||
}
|
||||
if (["fill", "stroke", "clip-path", "filter", "mask", "marker-start", "marker-mid", "marker-end"].includes(key)
|
||||
&& typeof value === "string" && /url\s*\(|javascript\s*:/i.test(value)) {
|
||||
fail("SKIN_EXTENSION_UI_ATTRIBUTE_INVALID", "SVG attributes cannot load external or executable resources.");
|
||||
}
|
||||
attributes[key] = value;
|
||||
}
|
||||
node.attributes = attributes;
|
||||
}
|
||||
if (input.asset !== undefined) {
|
||||
const asset = boundedText(input.asset, 120, "SKIN_EXTENSION_UI_ASSET_INVALID", "node.asset");
|
||||
if (node.tag !== "img" || !/^assets\/[A-Za-z0-9._/-]+$/.test(asset) || asset.split("/").some((part) => !part || part === "." || part === "..")) {
|
||||
fail("SKIN_EXTENSION_UI_ASSET_INVALID", "Generated image assets must use safe package-relative paths.");
|
||||
}
|
||||
node.asset = asset;
|
||||
}
|
||||
if (input.children !== undefined) {
|
||||
if (!Array.isArray(input.children) || input.children.length > GENERATED_CHILD_LIMIT) {
|
||||
fail("SKIN_EXTENSION_UI_COMPLEXITY_LIMIT", "A generated node has too many children.");
|
||||
}
|
||||
if (node.tag && GENERATED_VOID_ELEMENTS.has(node.tag) && input.children.length > 0) {
|
||||
fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Void generated elements cannot contain children.");
|
||||
}
|
||||
node.children = input.children.map((child) => generatedNode(child, depth + 1, count));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function parseGeneratedDocument(input: Record<string, unknown>): SkinPluginDocument {
|
||||
onlyKeys(input, ["schemaVersion", "components"], "Generated UI document");
|
||||
if (!Array.isArray(input.components) || input.components.length < 1 || input.components.length > GENERATED_COMPONENT_LIMIT) {
|
||||
fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "The generated document has an unsupported component count.");
|
||||
}
|
||||
const ids = new Set<string>();
|
||||
const components: SkinPluginComponent[] = input.components.map((raw, index) => {
|
||||
if (!isRecord(raw)) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", `Generated component ${index} must be an object.`);
|
||||
onlyKeys(raw, ["id", "name", "page", "accessibleName", "root"], "Generated component");
|
||||
const id = boundedText(raw.id, 64, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "component.id");
|
||||
if (!/^[a-z][a-z0-9-]*$/.test(id) || ids.has(id)) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Generated component IDs must be unique lowercase slugs.");
|
||||
ids.add(id);
|
||||
const name = boundedText(raw.name, 80, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "component.name");
|
||||
const accessibleName = boundedText(raw.accessibleName, 120, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "component.accessibleName");
|
||||
if (raw.page !== "home" && raw.page !== "voice") fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Generated components may target only the public home or voice page.");
|
||||
const root = generatedNode(raw.root, 1, { value: 0 });
|
||||
if (!root.tag) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "A generated component root must be an element.");
|
||||
return { id, name, page: raw.page, accessibleName, permissions: [], actions: Object.create(null) as Record<string, never>, root };
|
||||
});
|
||||
return { schemaVersion: 3, components };
|
||||
}
|
||||
|
||||
/** Parses bounded Wasm output. Schema 4 supports broad safe HTML/SVG, data/ARIA attributes, and inert custom-element placeholders. */
|
||||
export function parseSkinExtensionUiOutput(source: string): SkinPluginDocument {
|
||||
if (typeof source !== "string" || !source.length) {
|
||||
fail("SKIN_EXTENSION_UI_OUTPUT_INVALID", "Extension UI output must be a non-empty JSON string.");
|
||||
@@ -38,6 +192,9 @@ export function parseSkinExtensionUiOutput(source: string): SkinPluginDocument {
|
||||
try { input = JSON.parse(source); }
|
||||
catch { fail("SKIN_EXTENSION_UI_OUTPUT_JSON", "Extension UI output must contain valid JSON."); }
|
||||
|
||||
if (!isRecord(input)) fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Extension UI output must be an object.");
|
||||
if (input.schemaVersion === 4) return parseGeneratedDocument(input);
|
||||
|
||||
let document: SkinPluginDocument;
|
||||
try { document = parseSkinPluginDocument(input); }
|
||||
catch { fail("SKIN_EXTENSION_UI_OUTPUT_SCHEMA", "Extension UI output does not match the safe component schema."); }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { computed, defineComponent, Fragment, h, onUnmounted, reactive, ref, Teleport, watch, type PropType, type VNodeChild } from "vue";
|
||||
import {
|
||||
SKIN_PLUGIN_COMPONENT_LIMIT,
|
||||
SKIN_PLUGIN_PERMISSIONS,
|
||||
SKIN_PLUGIN_REPEAT_LIMIT,
|
||||
parseSkinPluginDocument,
|
||||
@@ -54,10 +55,10 @@ export default defineComponent({
|
||||
if (!props.extensionOutput || document.schemaVersion !== 3) return document;
|
||||
try {
|
||||
const extensionDocument = parseSkinExtensionUiOutput(props.extensionOutput);
|
||||
return parseSkinPluginDocument({
|
||||
schemaVersion: 3,
|
||||
components: [...document.components, ...extensionDocument.components],
|
||||
});
|
||||
const ids = new Set(document.components.map((component) => component.id));
|
||||
if (document.components.length + extensionDocument.components.length > SKIN_PLUGIN_COMPONENT_LIMIT
|
||||
|| extensionDocument.components.some((component) => ids.has(component.id))) return document;
|
||||
return { schemaVersion: 3 as const, components: [...document.components, ...extensionDocument.components] };
|
||||
} catch {
|
||||
// Dynamic output is optional; an invalid or colliding result leaves the package UI intact.
|
||||
return document;
|
||||
@@ -239,7 +240,11 @@ export default defineComponent({
|
||||
}
|
||||
if (node.tag === "form" && !node.events?.submit) attrs.onSubmit = (event: Event) => event.preventDefault();
|
||||
const children = (node.children ?? []).map((child, index) => renderNode(component, child, context, state, false, `${nodePath}-${index}`));
|
||||
return h(node.tag, attrs, children);
|
||||
// Custom element names are inert host-rendered placeholders. Never instantiate a page-registered
|
||||
// custom element from generated output, since its connectedCallback would run with page privileges.
|
||||
const tag = node.tag.includes("-") ? "div" : node.tag;
|
||||
if (tag !== node.tag) attrs["data-ws-generated-element"] = node.tag;
|
||||
return h(tag, attrs, children);
|
||||
}
|
||||
|
||||
function accept(): void {
|
||||
|
||||
@@ -26,6 +26,13 @@ function outputDocument(componentId = "runtime-ui", root?: Record<string, unknow
|
||||
});
|
||||
}
|
||||
|
||||
function generatedOutput(componentId = "runtime-ui", root: Record<string, unknown> = { tag: "main", children: [{ text: "Generated by Wasm" }] }): string {
|
||||
return JSON.stringify({
|
||||
schemaVersion: 4,
|
||||
components: [{ id: componentId, name: "Runtime UI", page: "voice", accessibleName: "Runtime UI", root }],
|
||||
});
|
||||
}
|
||||
|
||||
function expectOutputError(source: string, code: string): void {
|
||||
assert.throws(() => parseSkinExtensionUiOutput(source), (error: unknown) =>
|
||||
error instanceof SkinExtensionUiOutputError && error.code === code);
|
||||
@@ -56,6 +63,48 @@ test("Wasm UI output rejects malformed, oversized, legacy, and capability-bearin
|
||||
expectOutputError(outputDocument("runtime-ui", { tag: "p", text: "{{session.status.channelName}}" }), "SKIN_EXTENSION_UI_OUTPUT_SCHEMA");
|
||||
});
|
||||
|
||||
test("generated UI supports broad safe markup, ARIA/data attributes, and inert custom-element placeholders", () => {
|
||||
const document = parseSkinExtensionUiOutput(generatedOutput("kook-rail", {
|
||||
tag: "kook-server-rail",
|
||||
attributes: { "aria-label": "Servers", "data-selected": "home", role: "navigation" },
|
||||
children: [
|
||||
{ tag: "a", attributes: { href: "#voice" }, children: [{ text: "Voice" }] },
|
||||
{ tag: "button", attributes: { type: "button", "aria-pressed": true }, children: [{ text: "Home" }] },
|
||||
],
|
||||
}));
|
||||
|
||||
assert.equal(document.schemaVersion, 3);
|
||||
assert.equal(document.components[0].root.tag, "kook-server-rail");
|
||||
assert.equal(document.components[0].root.children?.[0].tag, "a");
|
||||
assert.equal(document.components[0].root.children?.[1].tag, "button");
|
||||
});
|
||||
|
||||
test("generated UI rejects executable elements, event handlers, and network/navigation sinks", () => {
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "script" }), "SKIN_EXTENSION_UI_ELEMENT_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "iframe" }), "SKIN_EXTENSION_UI_ELEMENT_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "button", attributes: { onclick: "run" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "img", attributes: { src: "https://example.invalid/a.png" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "a", attributes: { href: "https://example.invalid/" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { style: "display:none" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { mystery: "value" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
expectOutputError(generatedOutput("runtime-ui", { tag: "div", attributes: { "data-ws-part": "spoofed" } }), "SKIN_EXTENSION_UI_ATTRIBUTE_INVALID");
|
||||
});
|
||||
|
||||
test("generated UI enforces component and per-node child limits", () => {
|
||||
const tooManyComponents = JSON.stringify({
|
||||
schemaVersion: 4,
|
||||
components: Array.from({ length: 65 }, (_, index) => ({
|
||||
id: `runtime-${index}`, name: "Runtime UI", page: "voice", accessibleName: "Runtime UI", root: { tag: "main" },
|
||||
})),
|
||||
});
|
||||
const tooManyChildren = generatedOutput("runtime-ui", {
|
||||
tag: "main",
|
||||
children: Array.from({ length: 257 }, () => ({ text: "x" })),
|
||||
});
|
||||
expectOutputError(tooManyComponents, "SKIN_EXTENSION_UI_OUTPUT_SCHEMA");
|
||||
expectOutputError(tooManyChildren, "SKIN_EXTENSION_UI_COMPLEXITY_LIMIT");
|
||||
});
|
||||
|
||||
test("SkinPluginOutlet renders validated dynamic output and preserves package UI on collisions", async () => {
|
||||
const document: SkinPluginDocument = {
|
||||
schemaVersion: 3,
|
||||
@@ -96,6 +145,33 @@ test("SkinPluginOutlet renders validated dynamic output and preserves package UI
|
||||
assert.match(collisionHtml, /Package UI/);
|
||||
});
|
||||
|
||||
test("SkinPluginOutlet renders generated custom elements as inert host nodes", async () => {
|
||||
const document: SkinPluginDocument = {
|
||||
schemaVersion: 3,
|
||||
components: [{
|
||||
id: "base-ui",
|
||||
name: "Base UI",
|
||||
page: "voice",
|
||||
accessibleName: "Base UI",
|
||||
permissions: [],
|
||||
actions: {},
|
||||
root: { tag: "p", children: [{ text: "Base" }] },
|
||||
}],
|
||||
};
|
||||
const html = await renderToString(createSSRApp(SkinPluginOutlet, {
|
||||
skinId: "community.test",
|
||||
skinVersion: "1.0.0",
|
||||
document,
|
||||
extensionOutput: generatedOutput("kook-rail", { tag: "kook-server-rail", children: [{ text: "Server" }] }),
|
||||
page: "voice",
|
||||
data: {},
|
||||
assets: {},
|
||||
actions: {},
|
||||
}));
|
||||
assert.match(html, /<div[^>]*data-ws-generated-element="kook-server-rail"/);
|
||||
assert.match(html, /Server/);
|
||||
});
|
||||
|
||||
test("skin-authored DOM nodes expose independent layout parts and retain touch bounds for controls", async () => {
|
||||
const document: SkinPluginDocument = {
|
||||
schemaVersion: 3,
|
||||
|
||||
Reference in new issue
Block a user