mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): support approved Wasm plugin prototype
This commit is contained in:
1 parent
26b74c5be4
commit
7993b38eee
13 files changed
+321
-24
No files matched your search
@@ -49,9 +49,10 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖
|
||||
|
||||
### R3.3:完整自定义插件运行时(未完成,优先阶段)
|
||||
|
||||
- v4 包格式的首个节点已落地:客户端和服务端共用 `plugins.json` 描述校验器,校验插件 ID、版本、页面、模式、权限、入口/样式/素材路径与重复 surface;客户端分开缓存插件文件,服务端验证文件存在、UTF-8 和大小。
|
||||
- v4 包格式的首个节点已落地:客户端和服务端共用 `plugins.json` 描述校验器,校验插件 ID、版本、页面、模式、权限、入口/样式/素材路径与重复 surface;客户端分开缓存插件文件,服务端校验文件存在和大小,并对文本入口/样式验证 UTF-8。
|
||||
- 新增插件本地授权的安全基础:SHA-256 摘要绑定插件描述和所有声明文件,授权记录同时绑定皮肤/插件版本、API 版本、摘要与权限策略版本。任一代码、样式、素材、挂载模式或权限变化都会使旧授权不匹配。摘要不是发布者签名,亦不证明包来源可信。
|
||||
- 当前仍只校验和缓存 JS/CSS;本机持久化函数尚未接入宿主确认 UI、执行生命周期或运行时,也没有启用插件代码。此节点不能作为完整运行时完成态。
|
||||
- v4 入口支持 `.js` 与 `.wasm`;客户端对 Wasm 做固定导入/导出 ABI 预检,并按 MIME 类型分别缓存。服务端登记接受有大小上限的 Wasm 二进制,不运行它。
|
||||
- 新增开发态 v4 Wasm 适配器:启动前复核皮肤/插件版本、文件摘要和本地授权;只允许已实现的 `session.status.read` 权限,并为每次调用创建可终止的有界解释器任务。它没有接入 WebClient 的授权 UI、插件生命周期、频道/成员数据投影、动态 UI 渲染或 TeamSpeak 动作桥;普通 JS 仍不执行,生产运行时保持关闭。此节点不能作为完整运行时完成态。
|
||||
- 继续新增 opt-in 的插件协议,不给旧 v1/v2/v3 包追溯增加代码执行能力;同一皮肤可将界面分成多个独立、可排序、可显示/隐藏、可单独授权和回退的插件。
|
||||
- 插件可自定义公开界面的 DOM 结构、CSS、组件状态和普通 UI 事件,不局限于当前标签、属性、数据字段和固定动作表。宿主控件目录变成可选的兼容原生组件。
|
||||
- 尚待定义 widget 插件在宿主页面中的挂载、排序、显隐和用户自定义几何布局;当前 v4 描述只有页面与 widget/surface 模式,没有挂载或实例布局字段。应把用户布局保存在本地宿主状态,并让 CSS/插件沙箱边界保持独立。
|
||||
@@ -66,7 +67,7 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖
|
||||
|
||||
- 首个 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`。生产生命周期和能力授权桥接仍缺失,不代表完整运行时已完成。
|
||||
- 一次性 Wasm 运行先前没有宿主发回本地界面状态或交互事件的入口。现增加每次调用只读一次、8 KiB 封顶的 `ui_input_read`、输出 schema v5 命名回调,以及开发态有界 UI 重跑控制器;宿主事件只传安全字段,不信任作者可伪造的“用户手势”标记。循环尚未接入 WebClient 插件授权生命周期,也不能让插件执行 TeamSpeak 动作,不能据此打开生产开关。
|
||||
- 一次性 Wasm 运行先前没有宿主发回本地界面状态或交互事件的入口。现增加每次调用只读一次、8 KiB 封顶的 `ui_input_read`、输出 schema v5 命名回调,以及开发态有界 UI 重跑控制器;宿主事件只传安全字段,不信任作者可伪造的“用户手势”标记。当前 v4 Wasm 适配器只把摘要绑定的本地授权接到原型执行器,并只开放 `session.status.read`;循环尚未接入 WebClient 插件授权生命周期、动态 UI 渲染或 TeamSpeak 动作,不能据此打开生产开关。
|
||||
|
||||
### R3.4:声明式自定义节点布局编辑(已实施)
|
||||
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
# 更开放的皮肤系统规格
|
||||
|
||||
状态:v1/v2/v3 是兼容实现,不是“万物皆插件”目标的完成态。v4 的插件描述和包文件校验已接入客户端导入及服务端登记,但 JS/CSS 只被缓存,不会执行;components.json v3 仍限制元素/属性、数据字段、重复集合和宿主动作,Wasm UI 输出也仍未接入生产客户端。完整插件运行时尚未实现,不能把当前系统描述为完全自定义。阶段记录和问题节点见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md),当前包格式见[皮肤开发规范](./SKIN_DEVELOPMENT.md)。
|
||||
状态:v1/v2/v3 是兼容实现,不是“万物皆插件”目标的完成态。v4 的插件描述和包文件校验已接入客户端导入及服务端登记;客户端会校验 Wasm 入口的固定 ABI,但 JS/CSS/Wasm 默认只缓存、不执行。另有 Wasm 开发态适配器,会复核摘要绑定的本地授权后运行一次性有界任务,目前只支持 `session.status.read`,尚未接入 WebClient 插件生命周期或 UI/TeamSpeak 能力桥。components.json v3 仍限制元素/属性、数据字段、重复集合和宿主动作,动态 UI 输出也仍未接入生产客户端。完整插件运行时尚未实现,不能把当前系统描述为完全自定义。阶段记录和问题节点见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md),当前包格式见[皮肤开发规范](./SKIN_DEVELOPMENT.md)。
|
||||
|
||||
## 1. 目标与范围
|
||||
|
||||
完整目标中,皮肤作者可以用自己的插件组件、DOM、CSS 和本地逻辑排列、替换、隐藏或重做公开客户端界面中的任何视觉元素,也可以重建首页和完整语音工作区。连接、频道、聊天、音频、收藏/历史、共享等基础能力始终由 WebSpeak/TeamSpeak 宿主保留;皮肤能替换其展示和交互入口,但不能删除或篡改底层业务能力。宿主恢复入口、权限管理和安全提示位于皮肤之外,任何插件失效、拒绝授权或撤销后都能回到原生可用界面。
|
||||
|
||||
当前 v1/v2/v3 只能达到该目标的一部分:v3 组件依赖有限标签、属性、数据和动作白名单;v4 包协议已开始实现,但作者逻辑、沙箱执行与插件生命周期仍待接入。本规格区分已实现行为与目标行为,不以当前限制重新定义完成态。
|
||||
当前 v1/v2/v3 只能达到该目标的一部分:v3 组件依赖有限标签、属性、数据和动作白名单;v4 包协议与 Wasm 开发执行原型已开始实现,但完整沙箱生命周期、数据投影、宿主渲染和动作桥仍待接入。本规格区分已实现行为与目标行为,不以当前限制重新定义完成态。
|
||||
|
||||
适用页面为连接首页、语音工作区和公开演示页。管理员面板及其数据、管理 API 明确排除,不读取皮肤包。语音服务的运营、广告、陪玩、活动和商店等页面不属于语音客户端皮肤范围。
|
||||
|
||||
## 2. 包格式与执行模型
|
||||
|
||||
皮肤格式按版本区分:v1 保持视觉皮肤兼容;v2 提供有界布局 JSON;v3 使用 open-skin 清单、受控 CSS 和声明式 components.json;v4 在 open-skin 包中增加必需的 plugins.json 和插件专属 JS/CSS/素材路径。客户端与服务端共用 v4 插件描述校验器,并检查引用文件、UTF-8 和大小;当前不执行或加载这些代码。v1/v2 的 CSS 继续拒绝布局类声明,旧包不会因升级而获得新权限;v3/v4 才允许 CSS 控制公开页面中的布局、位置、尺寸、顺序、文字排版和显隐。
|
||||
皮肤格式按版本区分:v1 保持视觉皮肤兼容;v2 提供有界布局 JSON;v3 使用 open-skin 清单、受控 CSS 和声明式 components.json;v4 在 open-skin 包中增加必需的 plugins.json 和插件专属 JS/Wasm/CSS/素材路径。客户端与服务端共用 v4 插件描述校验器,并检查引用文件与大小;客户端额外验证 Wasm 入口的导入/导出 ABI。生产环境当前不执行或加载这些代码。v1/v2 的 CSS 继续拒绝布局类声明,旧包不会因升级而获得新权限;v3/v4 才允许 CSS 控制公开页面中的布局、位置、尺寸、顺序、文字排版和显隐。
|
||||
|
||||
v3 自定义组件不是脚本插件。components.json schema v1 是既有格式;schema v2 增加 `mode: "surface"` 与宿主控件节点;schema v3 扩大自定义节点、嵌套、重复列表和声明式交互的边界,并增加映射到现有语音功能的动作。宿主仍解析固定元素/属性白名单、固定数据集合、简单绑定与有限动作,再由 Vue 创建节点。每个自定义组件根和每个有 DOM 的节点都会作为独立本地布局项,可移动、调整尺寸、改变外观或隐藏。节点指定 `part` 后使用该标识;未指定时使用树路径,树结构调整后旧的本地覆盖可能要重新设置。可操作节点保留至少 44 px 的触控目标。作者不必使用固定宿主控件目录,但 v3 仍不足以表达任意自定义 UI 逻辑和完整插件生命周期。管理员面板和演示页不能被 surface 替换。
|
||||
|
||||
宿主控件通过固定 ID 嵌入,始终由 WebSpeak 代码运行。当前可选注册表包括 `home.connection-form`、`app.skin-switcher`、`app.language-switcher`、`voice.channel-panel`、`voice.member-cards`、`voice.chat-panel`、`voice.audio-controls`、`voice.screen-share-player`、`voice.whisper-controls`、`voice.performance-panel`、`voice.connection-controls` 和 `voice.disconnect-control`。每个控件在同一页面最多出现一次;未知 ID 或重复的有状态控件会拒绝导入。作者可以不用这些控件,自行绘制界面并将点击、双击等事件绑定到公开数据与受权限保护的动作。
|
||||
|
||||
v1-v3 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAssembly、远程脚本、任意 URL、表单导航、浏览器存储访问或网络调用。v4 可携带本地 JS/CSS 供后续沙箱运行时使用,但当前只校验和缓存,不会执行。未知字段、元素、动作、数据路径、控件和权限一律拒绝。
|
||||
v1-v3 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAssembly、远程脚本、任意 URL、表单导航、浏览器存储访问或网络调用。v4 可携带本地 JS/Wasm/CSS 供后续沙箱运行时使用;JS/CSS 默认只校验和缓存,Wasm 还会做固定 ABI 预检。开发态 Wasm 适配器会在启动前校验摘要绑定的本地授权,仅开放 `session.status.read`,仍未接入 WebClient 授权 UI、插件生命周期、动态 UI 输出或 TeamSpeak 能力桥。未知字段、元素、动作、数据路径、控件和权限一律拒绝。
|
||||
|
||||
### 2.1 完整插件目标协议(v4,运行时尚未实现)
|
||||
|
||||
已实现的 v4 包描述为 `plugins.json` schema v1:每包 1–64 个插件,每个插件指定唯一小写 ID、语义版本、API 版本 1、`home`/`voice` 页面、`widget`/`surface` 模式、`plugins/<id>/` 下入口 JS/可选 CSS、该目录中的图片/woff2 素材和现有权限表中的权限。每页至多一个 surface,且必须申请 `ui.surface.replace`。清单最多 256 KiB、插件入口最多 256 KiB、插件样式最多 512 KiB、每插件最多 32 个素材;引用文件必须存在且路径不重复。客户端与服务端复用同一解析器。另有 SHA-256 摘要与本地授权记录函数:摘要覆盖描述字段和入口、样式、全部素材;本机存储按皮肤、插件 ID 保存授权,并将授权绑定皮肤/插件版本、API 版本、文件摘要及权限策略版本。该摘要仅用于检测本机授权后包内容是否变化,不是发布者签名或来源证明。授权函数尚未接入宿主确认 UI 和执行生命周期;作者代码尚不加载或执行。
|
||||
已实现的 v4 包描述为 `plugins.json` schema v1:每包 1–64 个插件,每个插件指定唯一小写 ID、语义版本、API 版本 1、`home`/`voice` 页面、`widget`/`surface` 模式、`plugins/<id>/` 下入口 JS 或 Wasm/可选 CSS、该目录中的图片/woff2 素材和现有权限表中的权限。入口扩展名决定默认运行时,也可显式写 `runtime: "javascript"` 或 `runtime: "wasm"`,且必须匹配扩展名。每页至多一个 surface,且必须申请 `ui.surface.replace`。清单最多 256 KiB、插件入口最多 256 KiB、插件样式最多 512 KiB、每插件最多 32 个素材;引用文件必须存在且路径不重复。客户端与服务端复用同一解析器;客户端还对 Wasm 入口做固定 ABI 预检。另有 SHA-256 摘要与本地授权记录函数:摘要覆盖描述字段和入口、样式、全部素材;本机存储按皮肤、插件 ID 保存授权,并将授权绑定皮肤/插件版本、API 版本、文件摘要及权限策略版本。该摘要仅用于检测本机授权后包内容是否变化,不是发布者签名或来源证明。授权函数尚未接入宿主确认 UI 和执行生命周期;开发态 Wasm 适配器仅在摘要授权匹配后启动一次性有界任务,并只支持 `session.status.read`,尚不能视为生产插件执行。
|
||||
|
||||
当前 descriptor 没有定义 widget 的宿主挂载位置、实例顺序、显隐或几何配置。完整运行时需决定这些默认值随皮肤包分发还是由用户本地覆盖;用户布局应与作者文件分开存储,且沙箱内代码不能改动其他插件的宿主容器或恢复控件。
|
||||
|
||||
@@ -30,7 +30,7 @@ v1-v3 包不能提交 HTML 字符串、事件处理代码、JavaScript、WebAsse
|
||||
|
||||
不能把有 DOM 的 iframe 当作无网络沙箱。opaque origin 可隔离父页面 DOM、Cookie 和本地存储,但嵌入式浏览上下文仍允许自身 URL 导航;sandbox 阻止顶层导航的规则不阻止 frame 自己导航。CSP `navigate-to` 不能作为跨浏览器安全保证,因此仅关闭 `connect-src`、表单、弹窗和外部子 frame 不能阻止通过 URL 导航外带已授权的数据。若未来 iframe 只充当宿主可信的 UI 容器,作者代码必须在没有 DOM/导航能力的另一个受限执行环境中运行;iframe 内不得直接运行作者 JS。
|
||||
|
||||
当前 JavaScript 原型由 opaque-origin iframe 承载一个无 DOM 的 data Worker,CSP 阻断其常规网络接口,Worker 消息不能导航外层页面;但 JavaScript Worker 没有硬内存配额,不能作为面向不可信公开皮肤的生产边界。下一版应评估有明确内存/计算配额的解释器,并由宿主校验后创建通用 HTML 节点树和包内 CSS;作者仍需能自定义完整公开界面的结构、样式、局部状态和双击等交互,不能把安全改造变成固定宿主控件目录。
|
||||
当前 JavaScript 原型由 opaque-origin iframe 承载一个无 DOM 的 data Worker,CSP 阻断其常规网络接口,Worker 消息不能导航外层页面;但 JavaScript Worker 没有硬内存配额,不能作为面向不可信公开皮肤的生产边界。另有开发态 Wasm 原型:客户端导入器先解析受限模块结构,运行适配器再校验具体皮肤版本、插件、字节摘要和本地授权;每次运行使用可终止的有界解释器任务。当前仅开放 `session.status.read`,还没有 WebClient 生命周期集成、频道/成员数据投影、授权 UI、动态 UI 输出渲染或 TeamSpeak 动作桥,因此运行仍限于开发原型。下一版需把安全执行接入可信插件生命周期,并由宿主校验后创建通用 HTML 节点树和包内 CSS;作者仍需能自定义完整公开界面的结构、样式、局部状态和双击等交互,不能把安全改造变成固定宿主控件目录。
|
||||
|
||||
作者逻辑不得直接持有宿主 DOM、网络、持久存储、TeamSpeak SDK 或原始媒体流。宿主只向独立、有界的执行环境提供按权限筛选的结构化数据和本地 UI 事件,并通过私有消息通道收发有界协议。用户在可信宿主节点上触发双击等事件时,宿主生成一次性、短时事件票据;运行时只有在票据未使用、动作权限获批、会话及目标有效、参数通过 schema 校验时才转发 TeamSpeak 动作。不能信任作者逻辑自报“用户已点击”。桥接必须拒绝未知 message、跨插件转发、重放、过期事件票据、过大数据与未批准动作;具体事件/渲染协议仍待实现。
|
||||
|
||||
@@ -85,7 +85,7 @@ v3 CSS 和 surface 可排列、替换或遮挡公开 UI,因此可能改变麦
|
||||
|
||||
## 5. 校验与回退
|
||||
|
||||
客户端导入和服务端登记都会校验 manifest、ZIP 路径、组件协议、所引用素材和文件限额;v4 插件描述由共享解析器验证,JS/CSS 目前只作 UTF-8 和尺寸校验并缓存,不执行。现有组件运行时会再次解析持久化的组件文档;无效组件不执行。权限界面和恢复控件由宿主代码渲染。v3/v4 CSS 的作用域能降低跨应用影响,但 CSS 不是针对恶意脚本的沙箱。
|
||||
客户端导入和服务端登记都会校验 manifest、ZIP 路径、组件协议、所引用素材和文件限额;v4 插件描述由共享解析器验证,JS/CSS 目前只作 UTF-8 和尺寸校验并缓存,不执行;Wasm 入口按二进制大小限额处理,客户端另行校验其固定 ABI。开发态 Wasm 适配器仅在摘要绑定的本地授权通过后调用有界解释器原型,尚未集成生产生命周期。现有组件运行时会再次解析持久化的组件文档;无效组件不执行。权限界面和恢复控件由宿主代码渲染。v3/v4 CSS 的作用域能降低跨应用影响,但 CSS 不是针对恶意脚本的沙箱。
|
||||
|
||||
皮肤载入错误不得清除用户布局或 TeamSpeak 会话。组件树为空、权限被拒绝或皮肤无效时,宿主本身和既有功能仍可由用户恢复。v4 每个插件需有独立错误边界;单个插件崩溃不能拖垮语音会话或其余插件,撤销必须立即销毁该插件运行环境。管理员后台仍沿用自己的样式和服务端管理流程。
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# WebSpeak 皮肤开发规范
|
||||
|
||||
本文说明 v1 视觉皮肤、v2 声明式布局皮肤、v3 开放皮肤以及正在接入的 v4 插件包格式。v1/v2 保持固定 CSS 几何边界;v3 可重排公开 UI、用自定义声明式节点构建界面,并用 components.json schema v2/v3 替换首页/语音工作区的整页可见界面。v4 已加入插件清单、插件文件校验和本地缓存,但作者代码尚未执行。路线和安全边界见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md)与[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)。
|
||||
本文说明 v1 视觉皮肤、v2 声明式布局皮肤、v3 开放皮肤以及正在接入的 v4 插件包格式。v1/v2 保持固定 CSS 几何边界;v3 可重排公开 UI、用自定义声明式节点构建界面,并用 components.json schema v2/v3 替换首页/语音工作区的整页可见界面。v4 已加入插件清单、文件校验和本地缓存;客户端会预检 Wasm 固定 ABI,并有一个仅供开发验证的 Wasm 授权运行适配器。作者 JS 不执行,Wasm 适配器也没有接入生产 UI 生命周期或完整权限桥。路线和安全边界见[路线图](./OPEN_SKIN_SYSTEM_ROADMAP.zh-CN.md)与[规格](./OPEN_SKIN_SYSTEM_SPEC.zh-CN.md)。
|
||||
|
||||
KOOK 语音界面参考仅覆盖用户授权的语音频道,语音区结构记录在[参考文档](./KOOK_VOICE_REFERENCE.zh-CN.md);发现、陪玩、活动、广告、商城和管理后台不属于复刻范围。
|
||||
|
||||
当前 v3 仍限制 HTML 标签、属性、可绑定数据集合和宿主动作,不能称为“完全自定义”或“万物皆插件”。v4 插件运行时尚未实现或获安全批准;当前实现只校验并缓存清单、JS/CSS 和包内素材,不执行作者代码。完整运行时仍须支持作者自定义 DOM/CSS/本地逻辑,同时保持 TeamSpeak 功能经宿主能力桥接、皮肤后台之外可恢复。不要把 v4 包格式、v3 示例包或 Wasm 输出原型描述成已完成的全量插件系统。
|
||||
当前 v3 仍限制 HTML 标签、属性、可绑定数据集合和宿主动作,不能称为“完全自定义”或“万物皆插件”。v4 完整运行时尚未实现或获安全批准;JS/CSS 只校验、缓存,Wasm 入口增加固定 ABI 预检,开发适配器仅在本地摘要授权匹配时开放一次性有界任务,目前只支持 `session.status.read`。它还没有接入生产 UI 生命周期、频道/成员数据桥或 TeamSpeak 动作桥。完整运行时仍须支持作者自定义 DOM/CSS/本地逻辑,同时保持 TeamSpeak 功能经宿主能力桥接、皮肤后台之外可恢复。不要把 v4 包格式、v3 示例包或 Wasm 输出原型描述成已完成的全量插件系统。
|
||||
|
||||
`.wskin` 包可为公开页面定制艺术表现。v1 提供 CSS 与美术资源;v2 另外携带受校验的布局 JSON;v3 可自由安排公开组件,并用 components.json 声明由宿主渲染的安全组件。所有版本均由 WebSpeak 保留基础组件的业务逻辑和 TeamSpeak 行为。
|
||||
|
||||
@@ -32,6 +32,7 @@ assets/brand.woff2 # 可选:自带字体
|
||||
components.json # v3 可选:声明式组件或完整页面 surface
|
||||
plugins.json # v4 必需:插件入口、页面、模式、权限与包内文件
|
||||
plugins/<plugin-id>/index.js # v4 插件代码,目前只校验和缓存
|
||||
plugins/<plugin-id>/index.wasm # v4 有界 Wasm 原型入口,目前仅开发态可运行
|
||||
plugins/<plugin-id>/style.css # v4 可选:插件样式,目前只校验和缓存
|
||||
plugins/<plugin-id>/assets/ # v4 插件专属的本地图片或字体素材
|
||||
```
|
||||
@@ -157,7 +158,7 @@ components.json 顶层接受 schemaVersion 1、2 或 3 和 components 数组。s
|
||||
|
||||
### schemaVersion 4:插件包描述(运行时尚未启用)
|
||||
|
||||
v4 在 open-skin 包中增加必需的 `plugins` 路径。服务端登记和客户端导入共用 `plugins.json` schema v1 校验器;校验插件 ID、页面、模式、权限、文件归属、路径唯一性和包内文件大小,并将插件文件与普通皮肤素材分别缓存。SHA-256 授权基础会绑定插件描述、入口、样式和全部素材;本机授权记录还会绑定皮肤/插件版本、API 版本和权限策略版本。摘要只能发现已授权内容被替换,不能证明发布者身份。当前持久化函数尚未连接用户确认界面或运行生命周期。JS、CSS 和素材均不会被 WebSpeak 运行时加载或执行,因此 v4 目前不能作为可运行插件发布。
|
||||
v4 在 open-skin 包中增加必需的 `plugins` 路径。服务端登记和客户端导入共用 `plugins.json` schema v1 校验器;校验插件 ID、页面、模式、权限、文件归属、路径唯一性和包内文件大小,并将插件文件与普通皮肤素材分别缓存。客户端还会对 Wasm 入口执行固定导入/导出 ABI 预检。SHA-256 授权基础会绑定插件描述、入口、样式和全部素材;本机授权记录还会绑定皮肤/插件版本、API 版本和权限策略版本。摘要只能发现已授权内容被替换,不能证明发布者身份。当前持久化函数尚未连接用户确认界面或运行生命周期。JS、CSS 和 Wasm 文件默认只校验、缓存;另有开发态 Wasm 原型适配器,会在启动前复核摘要绑定的本地授权,但只支持 `session.status.read`,且没有接入 WebClient 生命周期或能力桥。生产运行时仍未启用,因此 v4 目前不能作为可运行插件发布。
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -174,9 +175,9 @@ v4 在 open-skin 包中增加必需的 `plugins` 路径。服务端登记和客
|
||||
}
|
||||
```
|
||||
|
||||
`plugins.json` 顶层 `schemaVersion` 当前为 `1`,并包含 1–64 个插件。每个插件声明 `id`、`name`、`version`、`apiVersion: 1`、`page`(`home` 或 `voice`)、`mode`(`widget` 或 `surface`)、必需的 `entry`、可选的 `style`、素材路径数组 `assets` 和 `permissions`。入口及样式必须位于 `plugins/<id>/`;素材必须位于该插件自己的 `assets/` 子目录,只能是本地图片或 woff2 字体。插件不能共享文件;同一公开页面最多有一个 `surface`,且必须申请 `ui.surface.replace`。其余权限只能从 `src/shared/skin-plugin.ts` 的现有权限表中选择。
|
||||
`plugins.json` 顶层 `schemaVersion` 当前为 `1`,并包含 1–64 个插件。每个插件声明 `id`、`name`、`version`、`apiVersion: 1`、`page`(`home` 或 `voice`)、`mode`(`widget` 或 `surface`)、必需的 `entry`、可选的 `runtime`、可选的 `style`、素材路径数组 `assets` 和 `permissions`。入口扩展名 `.js` 默认对应 `javascript`,`.wasm` 默认对应 `wasm`;显式 `runtime` 必须与入口扩展名一致。入口及样式必须位于 `plugins/<id>/`;素材必须位于该插件自己的 `assets/` 子目录,只能是本地图片或 woff2 字体。插件不能共享文件;同一公开页面最多有一个 `surface`,且必须申请 `ui.surface.replace`。其余权限只能从 `src/shared/skin-plugin.ts` 的现有权限表中选择。
|
||||
|
||||
`plugins.json` 不超过 256 KiB;每个入口 JS 不超过 256 KiB,每个样式 CSS 不超过 512 KiB;每个插件最多声明 32 个素材。皮肤包整体仍受通用 ZIP 文件数、展开大小、图像和字体限额约束。v1–v3 不接受插件代码。v4 的 JS/CSS 仍只校验、缓存,不执行。不要将有 DOM 的 iframe 当作网络沙箱:sandbox 不阻止 iframe 自己导航,`navigate-to` 也不能作为跨浏览器安全保证;获批数据可能被编码到导航 URL。现有无 DOM Worker 原型虽阻断常规网络 API,但没有硬内存限额,也不得生产启用。完整运行时需要同时保留自定义 UI/交互能力,并通过有资源边界的执行环境和可信宿主渲染/权限桥解决,不可退回固定原生控件目录。
|
||||
`plugins.json` 不超过 256 KiB;每个入口 JS 或 Wasm 不超过 256 KiB,每个样式 CSS 不超过 512 KiB;每个插件最多声明 32 个素材。客户端导入会拒绝不符合固定内存、导入、导出和 Wasm 模块结构限制的入口。皮肤包整体仍受通用 ZIP 文件数、展开大小、图像和字体限额约束。v1–v3 不接受插件代码。v4 的 JS/CSS/Wasm 默认仍只校验、缓存,不执行。Wasm 开发原型只在用户显式授权、摘要匹配时通过有界解释器启动一次性任务,当前唯一可用的数据权限为 `session.status.read`;尚无频道/成员数据投影、宿主动作桥或页面生命周期集成。不要将有 DOM 的 iframe 当作网络沙箱:sandbox 不阻止 iframe 自己导航,`navigate-to` 也不能作为跨浏览器安全保证;获批数据可能被编码到导航 URL。完整运行时需要同时保留自定义 UI/交互能力,并通过有资源边界的执行环境和可信宿主渲染/权限桥解决,不可退回固定原生控件目录。
|
||||
|
||||
当前描述还没有 widget 挂载点、排序、显隐或实例布局字段,完整运行时阶段需要明确这些由皮肤作者还是本地用户管理;不能让一个插件越过自身宿主节点去调整其他插件或宿主恢复控件。
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
"scripts": {
|
||||
"dev": "tsx src/index.ts",
|
||||
"build": "tsc",
|
||||
"test": "node --import tsx --test src/admin/skin-registry.test.ts web/test/admin-api.integration.test.ts web/test/admin-view.test.mjs web/src/services/admin-api.test.ts src/security/open-target-policy.test.ts src/server/visitor-count.test.ts src/server/voice-protocol.test.ts src/server/teamspeak-resolver.test.ts src/server/ts-client.test.ts src/server/join-ticket.test.ts src/server/identity-lease.test.ts src/server/session-manager.test.ts src/server/directory-sync.test.ts src/server/session-events.test.ts src/server/reconnect-policy.test.ts src/server/voice-commands.test.ts src/server/voice-bridge.test.ts src/server/session-audio.test.ts src/server/voice-bridge.integration.test.ts src/server/webrtc-audio.test.ts src/server/webrtc-config.test.ts src/server/audio-stats.test.ts src/server/directory-view.test.ts src/server/member-avatars.test.ts src/server/screen-share-coordinator.test.ts src/shared/client-commands.test.ts src/shared/skin-layout.test.ts src/shared/skin-plugin.test.ts src/shared/skin-runtime-plugins.test.ts src/shared/skin-runtime-plugin-approval.test.ts src/shared/server-messages.test.ts src/shared/webrtc.test.ts scripts/docker-healthcheck.test.mjs web/test/voice-session.test.mjs web/test/audio-controls.test.mjs web/test/connection-dialogs.test.mjs web/test/voice-performance.test.mjs web/test/screen-share.test.ts web/test/screen-share-ui.test.mjs web/test/android-gateway.test.ts web/src/services/skin-catalog.test.ts web/src/services/skin-plugin-runtime.test.ts web/src/services/skin-extension-ui.test.ts web/src/services/member-menu-placement.test.ts web/src/services/mobile-viewport.test.ts web/src/services/mobile-away.test.ts web/src/services/screen-wake-lock.test.ts web/src/services/microphone-start.test.ts web/src/services/skin-pack.test.ts web/src/services/skin-runtime-plugin-approval.test.ts web/src/services/skin-layout-storage.test.ts web/src/services/skin-layout-geometry.test.ts web/src/services/skin-layout-focus.test.ts web/test/skin-layout-runtime.test.mjs web/src/services/identity-import.test.ts web/test/identity-dialog.test.mjs web/test/skin-lifecycle.test.mjs web/src/services/local-persistence.test.ts web/src/services/quick-servers.test.ts src/server/teamspeak-alias.test.ts src/server/teamspeak-alias-integration.test.ts web/src/services/teamspeak-target.test.ts web/src/services/skin-extension-sandbox.test.ts web/src/services/skin-extension-wasm-policy.test.ts web/src/services/skin-extension-wasm-sandbox.test.ts web/src/services/skin-extension-wasm-ui-loop.test.ts web/src/services/skin-wasm-interpreter.test.ts",
|
||||
"test": "node --import tsx --test src/admin/skin-registry.test.ts web/test/admin-api.integration.test.ts web/test/admin-view.test.mjs web/src/services/admin-api.test.ts src/security/open-target-policy.test.ts src/server/visitor-count.test.ts src/server/voice-protocol.test.ts src/server/teamspeak-resolver.test.ts src/server/ts-client.test.ts src/server/join-ticket.test.ts src/server/identity-lease.test.ts src/server/session-manager.test.ts src/server/directory-sync.test.ts src/server/session-events.test.ts src/server/reconnect-policy.test.ts src/server/voice-commands.test.ts src/server/voice-bridge.test.ts src/server/session-audio.test.ts src/server/voice-bridge.integration.test.ts src/server/webrtc-audio.test.ts src/server/webrtc-config.test.ts src/server/audio-stats.test.ts src/server/directory-view.test.ts src/server/member-avatars.test.ts src/server/screen-share-coordinator.test.ts src/shared/client-commands.test.ts src/shared/skin-layout.test.ts src/shared/skin-plugin.test.ts src/shared/skin-runtime-plugins.test.ts src/shared/skin-runtime-plugin-approval.test.ts src/shared/server-messages.test.ts src/shared/webrtc.test.ts scripts/docker-healthcheck.test.mjs web/test/voice-session.test.mjs web/test/audio-controls.test.mjs web/test/connection-dialogs.test.mjs web/test/voice-performance.test.mjs web/test/screen-share.test.ts web/test/screen-share-ui.test.mjs web/test/android-gateway.test.ts web/src/services/skin-catalog.test.ts web/src/services/skin-plugin-runtime.test.ts web/src/services/skin-extension-ui.test.ts web/src/services/member-menu-placement.test.ts web/src/services/mobile-viewport.test.ts web/src/services/mobile-away.test.ts web/src/services/screen-wake-lock.test.ts web/src/services/microphone-start.test.ts web/src/services/skin-pack.test.ts web/src/services/skin-runtime-plugin-approval.test.ts web/src/services/skin-layout-storage.test.ts web/src/services/skin-layout-geometry.test.ts web/src/services/skin-layout-focus.test.ts web/test/skin-layout-runtime.test.mjs web/src/services/identity-import.test.ts web/test/identity-dialog.test.mjs web/test/skin-lifecycle.test.mjs web/src/services/local-persistence.test.ts web/src/services/quick-servers.test.ts src/server/teamspeak-alias.test.ts src/server/teamspeak-alias-integration.test.ts web/src/services/teamspeak-target.test.ts web/src/services/skin-extension-sandbox.test.ts web/src/services/skin-extension-wasm-policy.test.ts web/src/services/skin-extension-wasm-sandbox.test.ts web/src/services/skin-runtime-plugin-wasm.test.ts web/src/services/skin-extension-wasm-ui-loop.test.ts web/src/services/skin-wasm-interpreter.test.ts",
|
||||
"verify": "npm test && npm run build && npm run web:build",
|
||||
"start": "node dist/index.js",
|
||||
"web:dev": "cd web && npx vite --host",
|
||||
|
||||
@@ -229,6 +229,32 @@ test("server validates v4 plugin manifests and package files without executing a
|
||||
assert.equal(saved.id, "sample-skin");
|
||||
assert.deepEqual(await registry.readArchive("sample-skin"), archive);
|
||||
|
||||
const wasmPlugins = {
|
||||
schemaVersion: 1,
|
||||
plugins: [{
|
||||
id: "bounded-widget",
|
||||
name: "Bounded widget",
|
||||
version: "1.0.0",
|
||||
apiVersion: 1,
|
||||
runtime: "wasm",
|
||||
page: "voice",
|
||||
mode: "widget",
|
||||
entry: "plugins/bounded-widget/index.wasm",
|
||||
assets: [],
|
||||
permissions: [],
|
||||
}],
|
||||
};
|
||||
const wasmManifest = { ...manifestV4, id: "wasm-skin" };
|
||||
const wasmArchive = createZip([
|
||||
["manifest.json", Buffer.from(JSON.stringify(wasmManifest))],
|
||||
["skin.css", Buffer.from('[data-ws-part="app"] { position: fixed; }')],
|
||||
["plugins.json", Buffer.from(JSON.stringify(wasmPlugins))],
|
||||
["plugins/bounded-widget/index.wasm", Buffer.from([0, 97, 115, 109, 1, 0, 0, 0])],
|
||||
]);
|
||||
const wasmSaved = await registry.save(wasmArchive, "wasm-skin");
|
||||
assert.equal(wasmSaved.id, "wasm-skin");
|
||||
assert.deepEqual(await registry.readArchive("wasm-skin"), wasmArchive);
|
||||
|
||||
const missingEntry = createZip([
|
||||
["manifest.json", Buffer.from(JSON.stringify(manifestV4))],
|
||||
["skin.css", Buffer.from("[data-ws-part=app] { color: teal; }")],
|
||||
|
||||
@@ -257,6 +257,8 @@ function validateSkinArchive(bytes: Buffer, expectedId?: string): { manifest: Pa
|
||||
if (lowerPath.endsWith(".js")) {
|
||||
if (data.byteLength > SKIN_RUNTIME_PLUGIN_SOURCE_LIMIT_BYTES) throw new SkinRegistryError("Plugin entry files must be smaller than 256 KiB.", "SKIN_RUNTIME_PLUGIN_SOURCE_SIZE");
|
||||
decodeUtf8(data, "Plugin entry files must contain valid UTF-8.");
|
||||
} else if (lowerPath.endsWith(".wasm")) {
|
||||
if (data.byteLength > SKIN_RUNTIME_PLUGIN_SOURCE_LIMIT_BYTES) throw new SkinRegistryError("Wasm plugin entry files must be smaller than 256 KiB.", "SKIN_RUNTIME_PLUGIN_SOURCE_SIZE");
|
||||
} else if (lowerPath.endsWith(".css")) {
|
||||
if (data.byteLength > SKIN_RUNTIME_PLUGIN_STYLE_LIMIT_BYTES) throw new SkinRegistryError("Plugin style files must be smaller than 512 KiB.", "SKIN_RUNTIME_PLUGIN_STYLE_SIZE");
|
||||
decodeUtf8(data, "Plugin style files must contain valid UTF-8.");
|
||||
|
||||
@@ -79,6 +79,7 @@ export async function computeSkinRuntimePluginDigest(
|
||||
name: plugin.name,
|
||||
version: plugin.version,
|
||||
apiVersion: plugin.apiVersion,
|
||||
runtime: plugin.runtime,
|
||||
page: plugin.page,
|
||||
mode: plugin.mode,
|
||||
entry: plugin.entry,
|
||||
|
||||
@@ -33,10 +33,25 @@ test("v4 plugin descriptors accept bounded local files and freeze their parsed d
|
||||
"plugins/voice-toolbar/assets/icon.png",
|
||||
]);
|
||||
assert.equal(parsed.plugins[0].permissions[0], "session.channels.read");
|
||||
assert.equal(parsed.plugins[0].runtime, "javascript");
|
||||
assert.ok(Object.isFrozen(parsed) && Object.isFrozen(parsed.plugins) && Object.isFrozen(parsed.plugins[0]));
|
||||
assert.ok(Object.isFrozen(parsed.plugins[0].assets) && Object.isFrozen(parsed.plugins[0].permissions));
|
||||
});
|
||||
|
||||
test("v4 plugin descriptors recognize Wasm entries and reject a runtime/file mismatch", () => {
|
||||
const wasm = parseSkinRuntimePluginDocument(document([{ ...plugin, runtime: "wasm", entry: "plugins/voice-toolbar/index.wasm" }]) as never);
|
||||
assert.equal(wasm.plugins[0].runtime, "wasm");
|
||||
assert.equal(wasm.plugins[0].entry, "plugins/voice-toolbar/index.wasm");
|
||||
assert.throws(
|
||||
() => parseSkinRuntimePluginDocument(document([{ ...plugin, runtime: "wasm" }]) as never),
|
||||
(error: unknown) => error instanceof SkinRuntimePluginValidationError && error.code === "SKIN_RUNTIME_PLUGIN_PATH_INVALID",
|
||||
);
|
||||
assert.throws(
|
||||
() => parseSkinRuntimePluginDocument(document([{ ...plugin, runtime: "native" }]) as never),
|
||||
(error: unknown) => error instanceof SkinRuntimePluginValidationError && error.code === "SKIN_RUNTIME_PLUGIN_RUNTIME_INVALID",
|
||||
);
|
||||
});
|
||||
|
||||
test("surface replacement is an explicit page-scoped plugin capability", () => {
|
||||
const surface = { ...plugin, mode: "surface", permissions: ["ui.surface.replace"] };
|
||||
const parsed = parseSkinRuntimePluginDocument(document([surface]) as never);
|
||||
|
||||
@@ -9,12 +9,14 @@ export const SKIN_RUNTIME_PLUGIN_STYLE_LIMIT_BYTES = 512 * 1024;
|
||||
|
||||
export type SkinRuntimePluginPage = "home" | "voice";
|
||||
export type SkinRuntimePluginMode = "widget" | "surface";
|
||||
export type SkinRuntimePluginRuntime = "javascript" | "wasm";
|
||||
|
||||
export interface SkinRuntimePlugin {
|
||||
id: string;
|
||||
name: string;
|
||||
version: string;
|
||||
apiVersion: 1;
|
||||
runtime: SkinRuntimePluginRuntime;
|
||||
page: SkinRuntimePluginPage;
|
||||
mode: SkinRuntimePluginMode;
|
||||
entry: string;
|
||||
@@ -63,11 +65,11 @@ function text(value: unknown, field: string, maximum: number): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
function packageFile(value: unknown, field: string, pluginId: string, suffix: ".js" | ".css"): string {
|
||||
function packageFile(value: unknown, field: string, pluginId: string, suffixes: readonly (".js" | ".css" | ".wasm")[]): string {
|
||||
const result = text(value, field, 160);
|
||||
if (result.includes("\\") || result.startsWith("/") || result.split("/").some((part) => !part || part === "." || part === "..")
|
||||
|| !result.startsWith(`plugins/${pluginId}/`) || !result.toLowerCase().endsWith(suffix)) {
|
||||
invalid("SKIN_RUNTIME_PLUGIN_PATH_INVALID", `${field} must be a safe ${suffix} file inside its plugin directory.`);
|
||||
|| !result.startsWith(`plugins/${pluginId}/`) || !suffixes.some((suffix) => result.toLowerCase().endsWith(suffix))) {
|
||||
invalid("SKIN_RUNTIME_PLUGIN_PATH_INVALID", `${field} must be a safe plugin file inside its plugin directory.`);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -86,7 +88,7 @@ export function parseSkinRuntimePluginDocument(input: unknown): SkinRuntimePlugi
|
||||
const plugins: SkinRuntimePlugin[] = [];
|
||||
for (const raw of input.plugins) {
|
||||
if (!isRecord(raw)) invalid("SKIN_RUNTIME_PLUGIN_MANIFEST_INVALID", "A plugin definition must be an object.");
|
||||
onlyKeys(raw, ["id", "name", "version", "apiVersion", "page", "mode", "entry", "style", "assets", "permissions"], "Plugin definition");
|
||||
onlyKeys(raw, ["id", "name", "version", "apiVersion", "runtime", "page", "mode", "entry", "style", "assets", "permissions"], "Plugin definition");
|
||||
|
||||
const id = text(raw.id, "plugin.id", 64);
|
||||
if (!PLUGIN_ID.test(id) || ids.has(id)) invalid("SKIN_RUNTIME_PLUGIN_ID_INVALID", "Plugin IDs must be unique lowercase slugs.");
|
||||
@@ -98,8 +100,12 @@ export function parseSkinRuntimePluginDocument(input: unknown): SkinRuntimePlugi
|
||||
if (raw.page !== "home" && raw.page !== "voice") invalid("SKIN_RUNTIME_PLUGIN_MANIFEST_INVALID", "Plugins may target only the public home or voice page.");
|
||||
if (raw.mode !== "widget" && raw.mode !== "surface") invalid("SKIN_RUNTIME_PLUGIN_MANIFEST_INVALID", "Plugin mode must be widget or surface.");
|
||||
|
||||
const entry = packageFile(raw.entry, "plugin.entry", id, ".js");
|
||||
const style = raw.style === undefined ? undefined : packageFile(raw.style, "plugin.style", id, ".css");
|
||||
const runtime = raw.runtime === undefined
|
||||
? (typeof raw.entry === "string" && raw.entry.toLowerCase().endsWith(".wasm") ? "wasm" : "javascript")
|
||||
: raw.runtime;
|
||||
if (runtime !== "javascript" && runtime !== "wasm") invalid("SKIN_RUNTIME_PLUGIN_RUNTIME_INVALID", "A plugin runtime must be javascript or wasm.");
|
||||
const entry = packageFile(raw.entry, "plugin.entry", id, [runtime === "wasm" ? ".wasm" : ".js"]);
|
||||
const style = raw.style === undefined ? undefined : packageFile(raw.style, "plugin.style", id, [".css"]);
|
||||
if (!Array.isArray(raw.assets) || raw.assets.length > SKIN_RUNTIME_PLUGIN_ASSET_LIMIT) {
|
||||
invalid("SKIN_RUNTIME_PLUGIN_ASSET_INVALID", "A plugin must declare a bounded asset list.");
|
||||
}
|
||||
@@ -141,6 +147,7 @@ export function parseSkinRuntimePluginDocument(input: unknown): SkinRuntimePlugi
|
||||
name,
|
||||
version,
|
||||
apiVersion: 1,
|
||||
runtime,
|
||||
page: raw.page,
|
||||
mode: raw.mode,
|
||||
entry,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { strToU8, zipSync } from "fflate";
|
||||
import { importSkinPack, resolveSkinCssAssets, SkinPackError } from "./skin-pack.js";
|
||||
import { scopeBuiltinThemeForCustomSkin } from "./skin-cascade.js";
|
||||
import type { SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import { createSkinExtensionWasmPrefixByteImmediateProbe } from "../../test/skin-extension-wasm-fixture.js";
|
||||
|
||||
const manifest = {
|
||||
schemaVersion: 1,
|
||||
@@ -416,6 +417,39 @@ test("the distributable KAAK v3 package validates end to end", async () => {
|
||||
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-members-sidebar.member-row-content"'));
|
||||
});
|
||||
|
||||
test("v4 skin packages validate Wasm entry ABI and cache it as application/wasm", async () => {
|
||||
const wasmPlugin = {
|
||||
schemaVersion: 1,
|
||||
plugins: [{
|
||||
id: "voice-toolbar",
|
||||
name: "Voice toolbar",
|
||||
version: "1.0.0",
|
||||
apiVersion: 1,
|
||||
runtime: "wasm",
|
||||
page: "voice",
|
||||
mode: "widget",
|
||||
entry: "plugins/voice-toolbar/index.wasm",
|
||||
style: "plugins/voice-toolbar/style.css",
|
||||
assets: ["plugins/voice-toolbar/assets/icon.png"],
|
||||
permissions: [],
|
||||
}],
|
||||
};
|
||||
const skin = await importSkinPack(makeSkinV4(wasmPlugin, {
|
||||
entryPath: "plugins/voice-toolbar/index.wasm",
|
||||
entryBytes: createSkinExtensionWasmPrefixByteImmediateProbe(),
|
||||
}));
|
||||
assert.equal(skin.runtimePlugins?.plugins[0].runtime, "wasm");
|
||||
assert.equal(skin.runtimePluginFiles?.["plugins/voice-toolbar/index.wasm"]?.type, "application/wasm");
|
||||
|
||||
await assert.rejects(
|
||||
importSkinPack(makeSkinV4(wasmPlugin, {
|
||||
entryPath: "plugins/voice-toolbar/index.wasm",
|
||||
entryBytes: new Uint8Array([0, 1, 2, 3]),
|
||||
})),
|
||||
(error: unknown) => error instanceof SkinPackError && error.code === "SKIN_RUNTIME_PLUGIN_WASM_INVALID",
|
||||
);
|
||||
});
|
||||
|
||||
test("the full voice surface example packages home, voice, and host-owned controls", async () => {
|
||||
const archive = await readFile(new URL("../../../docs/examples/open-voice-surface.wskin", import.meta.url));
|
||||
const file = new File([archive], "open-voice-surface.wskin", { type: "application/octet-stream" });
|
||||
@@ -478,7 +512,7 @@ function makeSkinV4(
|
||||
permissions: ["session.channels.read"],
|
||||
}],
|
||||
},
|
||||
options: { includeEntry?: boolean; entryBytes?: Uint8Array; extra?: Record<string, Uint8Array> } = {},
|
||||
options: { includeEntry?: boolean; entryBytes?: Uint8Array; entryPath?: string; extra?: Record<string, Uint8Array> } = {},
|
||||
): File {
|
||||
const packageFiles: Record<string, Uint8Array> = {
|
||||
"manifest.json": strToU8(JSON.stringify({ ...manifest, schemaVersion: 4, packageType: "open-skin", plugins: "plugins.json" })),
|
||||
@@ -488,7 +522,8 @@ function makeSkinV4(
|
||||
"plugins/voice-toolbar/assets/icon.png": new Uint8Array([1, 2, 3, 4]),
|
||||
...options.extra,
|
||||
};
|
||||
if (options.includeEntry !== false) packageFiles["plugins/voice-toolbar/index.js"] = options.entryBytes ?? strToU8("export const render = () => document.createElement('button');");
|
||||
const entryPath = options.entryPath ?? "plugins/voice-toolbar/index.js";
|
||||
if (options.includeEntry !== false) packageFiles[entryPath] = options.entryBytes ?? strToU8("export const render = () => document.createElement('button');");
|
||||
const bytes = zipSync(packageFiles);
|
||||
return new File([bytes.slice().buffer as ArrayBuffer], "skin-v4.wskin", { type: "application/octet-stream" });
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import valueParser from "postcss-value-parser";
|
||||
import { unzipSync } from "fflate";
|
||||
import { parseSkinLayoutJson, type SkinLayoutDocument } from "../../../src/shared/skin-layout.js";
|
||||
import { listSkinPluginAssetPaths, parseSkinPluginJson, type SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import { validateSkinExtensionWasmBytes, validateSkinExtensionWasmImportsAndExports } from "./skin-extension-wasm-policy.js";
|
||||
import {
|
||||
listSkinRuntimePluginFilePaths,
|
||||
parseSkinRuntimePluginJson,
|
||||
@@ -191,6 +192,17 @@ export async function importSkinPack(file: File): Promise<InstalledSkin> {
|
||||
if (bytes.byteLength > SKIN_RUNTIME_PLUGIN_SOURCE_LIMIT_BYTES) throw new SkinPackError("Plugin entry files must be smaller than 256 KiB.", "SKIN_RUNTIME_PLUGIN_SOURCE_SIZE");
|
||||
try { decoder.decode(bytes); } catch { throw new SkinPackError("Plugin entry files must contain valid UTF-8.", "SKIN_RUNTIME_PLUGIN_ENCODING_INVALID"); }
|
||||
runtimePluginFiles[pluginPath] = new Blob([bytes], { type: "text/javascript" });
|
||||
} else if (lowerPath.endsWith(".wasm")) {
|
||||
if (bytes.byteLength > SKIN_RUNTIME_PLUGIN_SOURCE_LIMIT_BYTES) throw new SkinPackError("Wasm plugin entry files must be smaller than 256 KiB.", "SKIN_RUNTIME_PLUGIN_SOURCE_SIZE");
|
||||
const plugin = runtimePlugins?.plugins.find((candidate) => candidate.entry === pluginPath);
|
||||
if (!plugin || plugin.runtime !== "wasm") throw new SkinPackError("A Wasm entry must be declared as a Wasm plugin runtime.", "SKIN_RUNTIME_PLUGIN_WASM_INVALID");
|
||||
try {
|
||||
validateSkinExtensionWasmBytes(bytes);
|
||||
validateSkinExtensionWasmImportsAndExports(bytes, plugin.permissions);
|
||||
} catch (error) {
|
||||
throw new SkinPackError(`The Wasm plugin entry is invalid: ${error instanceof Error ? error.message : "unknown validation error"}`, "SKIN_RUNTIME_PLUGIN_WASM_INVALID");
|
||||
}
|
||||
runtimePluginFiles[pluginPath] = new Blob([bytes], { type: "application/wasm" });
|
||||
} else if (lowerPath.endsWith(".css")) {
|
||||
if (bytes.byteLength > SKIN_RUNTIME_PLUGIN_STYLE_LIMIT_BYTES) throw new SkinPackError("Plugin style files must be smaller than 512 KiB.", "SKIN_RUNTIME_PLUGIN_STYLE_SIZE");
|
||||
try { decoder.decode(bytes); } catch { throw new SkinPackError("Plugin style files must contain valid UTF-8.", "SKIN_RUNTIME_PLUGIN_ENCODING_INVALID"); }
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import {
|
||||
computeSkinRuntimePluginDigest,
|
||||
createSkinRuntimePluginApproval,
|
||||
} from "../../../src/shared/skin-runtime-plugin-approval.js";
|
||||
import { parseSkinRuntimePluginDocument } from "../../../src/shared/skin-runtime-plugins.js";
|
||||
import { createSkinExtensionWasmPrefixByteImmediateProbe } from "../../test/skin-extension-wasm-fixture.js";
|
||||
import {
|
||||
createSkinRuntimePluginWasmSandboxPrototype,
|
||||
SkinRuntimePluginWasmError,
|
||||
} from "./skin-runtime-plugin-wasm.js";
|
||||
|
||||
const plugin = parseSkinRuntimePluginDocument({
|
||||
schemaVersion: 1,
|
||||
plugins: [{
|
||||
id: "bounded-widget",
|
||||
name: "Bounded widget",
|
||||
version: "1.0.0",
|
||||
apiVersion: 1,
|
||||
runtime: "wasm",
|
||||
page: "voice",
|
||||
mode: "widget",
|
||||
entry: "plugins/bounded-widget/index.wasm",
|
||||
assets: [],
|
||||
permissions: [],
|
||||
}],
|
||||
}).plugins[0];
|
||||
|
||||
async function approvedFiles(source = createSkinExtensionWasmPrefixByteImmediateProbe()) {
|
||||
const files = { [plugin.entry]: new Blob([source]) };
|
||||
const digest = await computeSkinRuntimePluginDigest(plugin, files);
|
||||
return { files, digest, approval: createSkinRuntimePluginApproval("community.sample", "2.0.0", plugin, digest) };
|
||||
}
|
||||
|
||||
test("Wasm plugin startup rechecks the exact digest approval before creating a Worker", async () => {
|
||||
const { files, approval } = await approvedFiles();
|
||||
const staleApproval = { ...approval, digest: "0".repeat(64) };
|
||||
await assert.rejects(createSkinRuntimePluginWasmSandboxPrototype({
|
||||
skinId: "community.sample",
|
||||
skinVersion: "2.0.0",
|
||||
plugin,
|
||||
approval: staleApproval,
|
||||
files,
|
||||
readSessionStatus: () => ({ connected: false, channelName: null, memberCount: 0 }),
|
||||
prototypeOnly: true,
|
||||
}), (error: unknown) => error instanceof SkinRuntimePluginWasmError && error.code === "SKIN_EXTENSION_WASM_APPROVAL_INVALID");
|
||||
});
|
||||
|
||||
test("Wasm prototype refuses v4 capabilities it does not implement", async () => {
|
||||
const channelPlugin = parseSkinRuntimePluginDocument({
|
||||
schemaVersion: 1,
|
||||
plugins: [{ ...plugin, permissions: ["session.channels.read"] }],
|
||||
}).plugins[0];
|
||||
const files = { [channelPlugin.entry]: new Blob([createSkinExtensionWasmPrefixByteImmediateProbe()]) };
|
||||
const digest = await computeSkinRuntimePluginDigest(channelPlugin, files);
|
||||
const approval = createSkinRuntimePluginApproval("community.sample", "2.0.0", channelPlugin, digest);
|
||||
await assert.rejects(createSkinRuntimePluginWasmSandboxPrototype({
|
||||
skinId: "community.sample",
|
||||
skinVersion: "2.0.0",
|
||||
plugin: channelPlugin,
|
||||
approval,
|
||||
files,
|
||||
readSessionStatus: () => ({ connected: false, channelName: null, memberCount: 0 }),
|
||||
prototypeOnly: true,
|
||||
}), (error: unknown) => error instanceof SkinRuntimePluginWasmError
|
||||
&& error.code === "SKIN_EXTENSION_WASM_PERMISSION_UNSUPPORTED");
|
||||
});
|
||||
|
||||
test("approved Wasm entries run as disposable workers with bounded interpreter output", async () => {
|
||||
const { files, approval } = await approvedFiles();
|
||||
const previousWorker = Object.getOwnPropertyDescriptor(globalThis, "Worker");
|
||||
const previousWindow = Object.getOwnPropertyDescriptor(globalThis, "window");
|
||||
let terminated = 0;
|
||||
class FakeWorker {
|
||||
onmessage: ((event: MessageEvent<unknown>) => void) | null = null;
|
||||
onmessageerror: (() => void) | null = null;
|
||||
onerror: (() => void) | null = null;
|
||||
postMessage(): void {
|
||||
queueMicrotask(() => {
|
||||
this.onmessage?.({ data: { type: "running" } } as MessageEvent<unknown>);
|
||||
this.onmessage?.({ data: {
|
||||
type: "complete", result: 7, linearMemoryBytes: 65_536, statusReadCount: 0, uiInputReadCount: 0, uiOutput: null,
|
||||
} } as MessageEvent<unknown>);
|
||||
});
|
||||
}
|
||||
terminate(): void { terminated += 1; }
|
||||
}
|
||||
Object.defineProperty(globalThis, "Worker", { configurable: true, value: FakeWorker });
|
||||
Object.defineProperty(globalThis, "window", { configurable: true, value: { setTimeout, clearTimeout } });
|
||||
try {
|
||||
const handle = await createSkinRuntimePluginWasmSandboxPrototype({
|
||||
skinId: "community.sample",
|
||||
skinVersion: "2.0.0",
|
||||
plugin,
|
||||
approval,
|
||||
files,
|
||||
readSessionStatus: () => ({ connected: false, channelName: null, memberCount: 0 }),
|
||||
prototypeOnly: true,
|
||||
});
|
||||
assert.deepEqual(await handle.result, {
|
||||
result: 7,
|
||||
linearMemoryBytes: 65_536,
|
||||
statusReadCount: 0,
|
||||
uiInputReadCount: 0,
|
||||
uiOutput: null,
|
||||
});
|
||||
assert.equal(handle.closeReason, "completed");
|
||||
assert.equal(terminated, 1);
|
||||
} finally {
|
||||
if (previousWorker) Object.defineProperty(globalThis, "Worker", previousWorker);
|
||||
else Reflect.deleteProperty(globalThis, "Worker");
|
||||
if (previousWindow) Object.defineProperty(globalThis, "window", previousWindow);
|
||||
else Reflect.deleteProperty(globalThis, "window");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
createSkinExtensionApproval,
|
||||
parseSkinExtensionManifest,
|
||||
type SkinExtensionSessionStatus,
|
||||
} from "../../../src/shared/skin-extension.js";
|
||||
import {
|
||||
computeSkinRuntimePluginDigest,
|
||||
isSkinRuntimePluginApproved,
|
||||
parseSkinRuntimePluginApproval,
|
||||
type SkinRuntimePluginApproval,
|
||||
} from "../../../src/shared/skin-runtime-plugin-approval.js";
|
||||
import { parseSkinRuntimePluginDocument, type SkinRuntimePlugin } from "../../../src/shared/skin-runtime-plugins.js";
|
||||
import {
|
||||
createSkinExtensionWasmSandboxPrototype,
|
||||
type SkinExtensionWasmSandboxHandle,
|
||||
} from "./skin-extension-wasm-sandbox.js";
|
||||
|
||||
export class SkinRuntimePluginWasmError extends Error {
|
||||
constructor(readonly code: string, message: string) {
|
||||
super(message);
|
||||
this.name = "SkinRuntimePluginWasmError";
|
||||
}
|
||||
}
|
||||
|
||||
export interface SkinRuntimePluginWasmOptions {
|
||||
skinId: string;
|
||||
skinVersion: string;
|
||||
plugin: SkinRuntimePlugin;
|
||||
approval: unknown;
|
||||
files: Readonly<Record<string, Blob>>;
|
||||
uiInput?: unknown;
|
||||
readSessionStatus: (signal: AbortSignal) => SkinExtensionSessionStatus | Promise<SkinExtensionSessionStatus>;
|
||||
prototypeOnly: true;
|
||||
}
|
||||
|
||||
const WASM_PROTOTYPE_PERMISSIONS = new Set(["session.status.read"]);
|
||||
|
||||
/** Starts a Wasm entry only after rechecking the exact package digest and local approval. */
|
||||
export async function createSkinRuntimePluginWasmSandboxPrototype(
|
||||
options: SkinRuntimePluginWasmOptions,
|
||||
): Promise<SkinExtensionWasmSandboxHandle> {
|
||||
if (options.prototypeOnly !== true) throw new SkinRuntimePluginWasmError("SKIN_EXTENSION_WASM_PROTOTYPE_ONLY", "The Wasm runner is a development-only security prototype.");
|
||||
const plugin = parseSkinRuntimePluginDocument({ schemaVersion: 1, plugins: [options.plugin] }).plugins[0];
|
||||
if (plugin.runtime !== "wasm") throw new SkinRuntimePluginWasmError("SKIN_EXTENSION_WASM_ENTRY_INVALID", "Only a Wasm plugin entry can use the bounded Wasm runner.");
|
||||
|
||||
const unsupportedPermission = plugin.permissions.find((permission) => !WASM_PROTOTYPE_PERMISSIONS.has(permission));
|
||||
if (unsupportedPermission) {
|
||||
throw new SkinRuntimePluginWasmError("SKIN_EXTENSION_WASM_PERMISSION_UNSUPPORTED", `The Wasm prototype does not implement ${unsupportedPermission}.`);
|
||||
}
|
||||
|
||||
const digest = await computeSkinRuntimePluginDigest(plugin, options.files);
|
||||
let approval: SkinRuntimePluginApproval;
|
||||
try { approval = parseSkinRuntimePluginApproval(options.approval); }
|
||||
catch { throw new SkinRuntimePluginWasmError("SKIN_EXTENSION_WASM_APPROVAL_INVALID", "The Wasm plugin does not have a valid local approval."); }
|
||||
if (!isSkinRuntimePluginApproved(approval, options.skinId, options.skinVersion, plugin, digest)) {
|
||||
throw new SkinRuntimePluginWasmError("SKIN_EXTENSION_WASM_APPROVAL_INVALID", "The Wasm plugin approval does not match this skin, version, plugin, or package digest.");
|
||||
}
|
||||
|
||||
const entry = options.files[plugin.entry];
|
||||
if (!(entry instanceof Blob)) throw new SkinRuntimePluginWasmError("SKIN_EXTENSION_WASM_ENTRY_INVALID", "The approved Wasm entry is unavailable.");
|
||||
const wasmBytes = new Uint8Array(await entry.arrayBuffer());
|
||||
const manifest = parseSkinExtensionManifest({
|
||||
schemaVersion: 1,
|
||||
packageType: "extension",
|
||||
id: plugin.id,
|
||||
name: plugin.name,
|
||||
version: plugin.version,
|
||||
apiVersion: plugin.apiVersion,
|
||||
permissions: [...plugin.permissions],
|
||||
});
|
||||
|
||||
// This legacy approval object is created only after the v4 digest-bound host approval above.
|
||||
return createSkinExtensionWasmSandboxPrototype({
|
||||
manifest,
|
||||
approval: createSkinExtensionApproval(manifest),
|
||||
wasmBytes,
|
||||
uiInput: options.uiInput,
|
||||
readSessionStatus: options.readSessionStatus,
|
||||
prototypeOnly: true,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user