@bhxch/vviewer-sanitize 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 vviewer contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # @bhxch/vviewer-sanitize
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 不可信渲染 HTML 的唯一净化出口:DOMPurify(^3.4.16)强化净化预设——URI 白名单、
4
+ `data:` 按属性收窄、外域加载向量拦截、服务端图表 SVG 片段净化。所有不可信渲染
5
+ HTML 必须经本包出口进入 DOM,调用方不得各自直连 DOMPurify 或另设净化规则。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @bhxch/vviewer-sanitize
11
+ ```
12
+
13
+ ## 导出面
14
+
15
+ | 导出 | 用途 | 既有消费点 |
16
+ | --- | --- | --- |
17
+ | `sanitizeHtml(dirty, opts?)` | 片段/整文档净化,string 与 Document 输入统一返回字符串 | render-doc `docx.ts`、render-text `markdownRenderer.ts` / `html.ts` |
18
+ | `sanitizeDiagramFragment(root, html, opts?)` | 服务端图表 SVG 片段承接:契约壳包裹 → 净化 → 剥壳 | render-text `pipeline.ts`(server 模式与 krokiVia=server 两分支) |
19
+ | `isExternalMediaSrc(src)` | 外域加载源判定(http(s) 与协议相对) | render-text `enrich.ts` 媒体替换守卫 |
20
+ | `hostOf(url)` | URL host 提示文本(解析失败回落原串) | render-text `enrich.ts` |
21
+ | `ALLOWED_URI_REGEXP` | URI 白名单正则(html 渲染器二层复核共用同一正则) | render-text `html.ts` |
22
+ | `MARKDOWN_SANITIZE_CONFIG` | DOMPurify 基础 config(FORBID_TAGS meta、ALLOW_DATA_ATTR、ALLOWED_URI_REGEXP) | — |
23
+ | `SanitizeOptions` / `ServerDiagramContract` | 选项与契约类型 | — |
24
+
25
+ ## 选项(SanitizeOptions)
26
+
27
+ - `wholeDocument`:净化整份 HTML 文档(html/head/body 进允许表),html 渲染器
28
+ srcdoc 用。此时输入必须是完整文档字符串(Document 输入会丢 head)。
29
+ - `serverDiagram`:服务端图表容器契约,style 豁免钩子按「净化串内祖先节点带
30
+ `attr` 属性且取值为 `value`」识别豁免容器。默认 `data-vv-diagram="server"`——
31
+ 与 server 端 `compute/diagrams.rs` 及 render-text `wrapServerDiagrams` 的产出
32
+ 契约逐字一致,既有消费方零改动。自定义时 `sanitizeDiagramFragment` 的壳属性
33
+ 与钩子识别同源取自该契约,字面量不会在壳/钩两处漂移。
34
+
35
+ ## 钩子为模块级惰性注册状态——多实例/多配置语义(必读)
36
+
37
+ - 两枚钩子(`uponSanitizeElement` 的 style 上下文二分、`afterSanitizeAttributes`
38
+ 的 data: 收窄与外域向量复核)在**首次 `sanitizeHtml` 调用时**注册到 dompurify
39
+ 默认导出的单例实例上,进程内一次性(幂等闸)。模块顶层不触 DOMPurify——
40
+ SSR/Node 下默认导出是未绑定 window 的工厂(无 `addHook`/`sanitize`),顶层
41
+ 调用会让 SvelteKit SSR 求值直接 500。
42
+ - 因此本包**没有按调用隔离的多实例**:同一模块图内所有净化调用共享同一套钩子,
43
+ 钩子只注册一次。按调用的差异只能经 config 传递——`wholeDocument` 与
44
+ `serverDiagram` 契约均随当次 sanitize 的 config 走(契约经 DOMPurify 钩子第 3
45
+ 参 CONFIG 读回;3.4.16 实测 `_parseConfig` 对传入 config 全量 clone 保留自有
46
+ 键、`_executeHooks` 把当次 CONFIG 原样传给钩子),钩子侧不持模块级可变状态,
47
+ 无跨调用串扰残留。
48
+ - 若同进程另行 `DOMPurify(window)` 工厂建第二实例,本包钩子不会注册其上——
49
+ 必须统一经本包出口净化,或自行对新实例 addHook(不建议,会绕开本包策略)。
50
+ - 多配置并存的正确姿势:每次调用带上各自的 `SanitizeOptions`;不要用
51
+ `DOMPurify.setConfig`/`clearConfig` 改全局状态(会与本包的按调用 config 语义
52
+ 叠加出意外)。
53
+
54
+ ## 迁移注记
55
+
56
+ 自 `packages/vviewer-render-text/src/markdown/sanitize.ts` 迁入(零内部依赖、仅
57
+ dompurify)。过渡期原位置保留,render-text 内部消费方与 render-doc 改指
58
+ `@bhxch/vviewer-sanitize` 后移除原位置与 render-text 的 `./sanitize` 子路径导出。
59
+
60
+ ## 仓库与许可
61
+
62
+ - 仓库:[bhxch/vviewer](https://github.com/bhxch/vviewer),源码位于 `packages/vviewer-sanitize/`
63
+ - 许可:Apache-2.0;第三方依赖许可见仓库 `THIRD_PARTY_NOTICES.md`
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './sanitize.js';
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // @bhxch/vviewer-sanitize 包根——不可信渲染 HTML 的唯一净化出口。
2
+ // 导出面按既有消费点闭包聚合:sanitizeHtml(render-doc docx、render-text
3
+ // markdownRenderer / html 渲染器)、sanitizeDiagramFragment(render-text pipeline
4
+ // 服务端图表承接)、hostOf / isExternalMediaSrc(render-text enrich)、
5
+ // ALLOWED_URI_REGEXP(render-text html 渲染器 URI 二层复核)。
6
+ export * from './sanitize.js';
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@bhxch/vviewer-sanitize",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "types": "./index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "default": "./index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "LICENSE",
16
+ "README.md",
17
+ "index.d.ts",
18
+ "index.js",
19
+ "sanitize.d.ts",
20
+ "sanitize.js"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/bhxch/vviewer.git",
25
+ "directory": "packages/vviewer-sanitize"
26
+ },
27
+ "license": "Apache-2.0",
28
+ "dependencies": {
29
+ "dompurify": "^3.4.16"
30
+ },
31
+ "contentHash": "1e7901c6c9267a2a"
32
+ }
package/sanitize.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { Config } from 'dompurify';
2
+ export declare const ALLOWED_URI_REGEXP: RegExp;
3
+ /**
4
+ * 外域图片判定(BUG-17 跟踪像素防线):绝对 http(s) 与协议相对(//host/…)都会向
5
+ * 第三方发起 GET(可回传 IP/会话);相对路径、data:image、blob: 不在此列。
6
+ */
7
+ export declare function isExternalMediaSrc(src: string): boolean;
8
+ /** URL 的 host(解析失败回落原串做提示) */
9
+ export declare function hostOf(url: string): string;
10
+ /** 服务端图表容器契约(style 豁免钩子按「净化串内祖先节点带 attr 属性且取值为 value」识别豁免容器) */
11
+ export interface ServerDiagramContract {
12
+ /** 容器属性名,默认 'data-vv-diagram'(服务端契约字面量,产出对端 server/src/compute/diagrams.rs 与 render-text wrapServerDiagrams) */
13
+ attr?: string;
14
+ /** 容器属性取值,默认 'server' */
15
+ value?: string;
16
+ }
17
+ export declare const MARKDOWN_SANITIZE_CONFIG: Config;
18
+ /** sanitizeHtml 可选项 */
19
+ export interface SanitizeOptions {
20
+ /** true 时净化整份 HTML 文档(含 html/head/body 与其中的 meta/title),html 渲染器 srcdoc 用 */
21
+ wholeDocument?: boolean;
22
+ /** 服务端图表容器契约:style 豁免钩子的容器识别字面量,默认 data-vv-diagram="server"(见 ServerDiagramContract) */
23
+ serverDiagram?: ServerDiagramContract;
24
+ }
25
+ /**
26
+ * 服务端获取的图表 SVG 片段净化(spec 2026-10-23 §8.3):server 模式
27
+ * (/api/compute/diagram)与 krokiVia=server(/api/kroki 代发)两分支共用的
28
+ * 承接面——片段包进契约壳后整串走 sanitizeHtml,uponSanitizeElement 钩子按壳
29
+ * 上下文放行引擎 <style>(危险 token 全量归一化判定兜底,url(# 同文档片段引用
30
+ * 既有放行),与 compute markdown 后处理产物的 wrapServerDiagrams 承接面同一
31
+ * 豁免语义。壳须留在净化输入串内(钩子按串内祖先上下文二分),净化后剥壳取回
32
+ * 内层——敌意内容若截断壳,截出部分落容器外 → style 豁免不适用(fail-closed,
33
+ * 且整串仍经 DOMPurify 全量净化)。壳属性与钩子识别同源取自 opts.serverDiagram
34
+ * (默认 data-vv-diagram="server"),契约字面量不会在壳/钩两处漂移;attr/value
35
+ * 为调用方自有契约常量(非不可信输入),直接拼入净化输入串。
36
+ */
37
+ export declare function sanitizeDiagramFragment(root: Document, html: string, opts?: SanitizeOptions): string;
38
+ /**
39
+ * 不可信渲染 HTML 过唯一共享策略。string 与 Document 输入统一返回字符串
40
+ * (SDD Ruling:T3 管线以字符串为统一出口,自行 innerHTML 成 DOM)。
41
+ * Document 输入取 body 内容净化(DOMPurify 无法导入文档节点本身;本管线
42
+ * 的 Document 均为 body 级片段容器)。wholeDocument 时输入必须是完整文档
43
+ * 字符串(Document 输入会丢 head,此时应直接传原始字符串)。
44
+ */
45
+ export declare function sanitizeHtml(dirty: string | Document, opts?: SanitizeOptions): string;
package/sanitize.js ADDED
@@ -0,0 +1,443 @@
1
+ // sanitize.ts — 不可信渲染 HTML 的唯一净化策略(@bhxch/vviewer-sanitize 包本体)。
2
+ // 自 render-text/src/markdown/sanitize.ts 原样迁入(过渡期原位置保留,应用代码
3
+ // 改指本包后移除):移植自 markpad src/lib/utils/sanitize.ts(单一策略模块原则),
4
+ // 按 vviewer 契约调整 URI 白名单:http/https/mailto/相对路径/data:image(data: 仅限
5
+ // src/srcset,见下方钩子);FORBID_TAGS meta(style 的禁用由 uponSanitizeElement
6
+ // 钩子按服务端图表容器上下文二分承载,见 registerSanitizeHooks);ALLOW_DATA_ATTR
7
+ // 保留 mermaid/katex 管线钩子。
8
+ // BUG-40:外域拦截自 img src/srcset(BUG-17)扩展到五类等价加载向量——
9
+ // video/audio poster、SVG image/use href、行内 style url()、background 属性、
10
+ // input type=image src(见钩子内 BUG-40 各分支)。
11
+ import DOMPurify from 'dompurify';
12
+ // 仅在 DOMPurify 默认形状上收窄与放行两种方向:
13
+ // - `data:image/`:内嵌图片(其余 data: MIME 一律拒绝,如 data:text/html)
14
+ // - 删除 markpad 的盘符/asset:/tauri: 分支(无 Tauri 环境)
15
+ // 其余与 DOMPurify 默认一致:相对路径、片段、字母开头的非 scheme 串。
16
+ // `javascript:`、`vbscript:`、`data:text/html` 匹配不到任何分支,连属性一起剥除。
17
+ // 注意该正则只做值前缀匹配、不区分属性:data:image/ 也会命中 <a href>,
18
+ // data: 的属性级放行由下方 afterSanitizeAttributes 钩子收窄为 src/srcset。
19
+ export const ALLOWED_URI_REGEXP = /^(?:(?:(?:f|ht)tps?|mailto):|data:image\/|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
20
+ // data: 协议仅放行 src/srcset(内嵌图片/媒体)。ALLOWED_URI_REGEXP 按属性无关的
21
+ // 值前缀匹配,单正则难以按属性区分;DOMPurify 默认的 DATA_URI_TAGS 分支又只覆盖
22
+ // data: 前缀本身而非 data:image/。故用钩子在属性判定之后统一复核:src/srcset 之外
23
+ // 的属性一律不允许 data:*——否则 <a href="data:image/svg+xml,..."> 可通过,用户点击
24
+ // 后浏览器顶层导航至 SVG data URL,其中的脚本可执行(跳转型 XSS)。
25
+ // 惰性注册(首次 sanitizeHtml 时、幂等):模块顶层不可触 DOMPurify——SSR/Node 下
26
+ // 默认导出是未绑定 window 的工厂(无 addHook/sanitize),顶层调用会让 SvelteKit
27
+ // SSR 求值直接 500。
28
+ const DATA_URI_ATTRS = new Set(['src', 'srcset']);
29
+ /**
30
+ * 外域图片判定(BUG-17 跟踪像素防线):绝对 http(s) 与协议相对(//host/…)都会向
31
+ * 第三方发起 GET(可回传 IP/会话);相对路径、data:image、blob: 不在此列。
32
+ */
33
+ export function isExternalMediaSrc(src) {
34
+ return /^https?:/i.test(src) || src.startsWith('//');
35
+ }
36
+ /** URL 的 host(解析失败回落原串做提示) */
37
+ export function hostOf(url) {
38
+ try {
39
+ return new URL(url, 'https://vviewer.invalid').host;
40
+ }
41
+ catch {
42
+ return url;
43
+ }
44
+ }
45
+ function markBlockedExternal(el, host) {
46
+ el.setAttribute('data-vv-blocked-external', '1');
47
+ el.setAttribute('title', `已拦截外部图片:${host}`);
48
+ }
49
+ // ---------- BUG-40:五类等价加载向量的外域拦截 ----------
50
+ //
51
+ // 既有防线只覆盖 IMG 的 src/srcset 与 VIDEO/AUDIO/SOURCE 的 src;以下属性同样是
52
+ // 「元素渲染即自动加载」的外域向量(md 渲染视图把净化后 DOM 挂主文档、无 CSP 兜
53
+ // 底,属性在即真实外联,跟踪像素可回传 IP/会话):
54
+ // ① video/audio poster——poster 图随元素渲染即拉取(与 preload 无关);
55
+ // ② SVG <image>/<use> 的 href/xlink:href——SVG 引用外域文档即加载;
56
+ // ③ 行内 style 的 url()/image-set() 字符串 URL——样式应用即拉取;
57
+ // ④ background 属性(table/td/body 等遗留表现属性)——同背景图自动加载;
58
+ // ⑤ input type=image src——与 img 同等的自动加载图片。
59
+ // 策略与 IMG(BUG-17)同口径:移除加载源 + data-vv-blocked-external 标记 +
60
+ // title 域名提示;行内 style 只剥含外域引用的声明、其余声明保留。
61
+ /** SVG 命名空间(xlink:href 剥除用 removeAttributeNS,qualified name 双保险) */
62
+ const XLINK_NS = 'http://www.w3.org/1999/xlink';
63
+ /** 引号/括号感知的 style 声明切分:url("a;b")、image-set("a;b" 1x) 不误切。 */
64
+ function splitStyleDeclarations(value) {
65
+ const out = [];
66
+ let cur = '';
67
+ let depth = 0;
68
+ let quote = null;
69
+ for (const ch of value) {
70
+ if (quote !== null) {
71
+ cur += ch;
72
+ if (ch === quote)
73
+ quote = null;
74
+ continue;
75
+ }
76
+ if (ch === '"' || ch === "'") {
77
+ quote = ch;
78
+ cur += ch;
79
+ continue;
80
+ }
81
+ if (ch === '(')
82
+ depth += 1;
83
+ else if (ch === ')')
84
+ depth = Math.max(0, depth - 1);
85
+ if (ch === ';' && depth === 0) {
86
+ out.push(cur);
87
+ cur = '';
88
+ continue;
89
+ }
90
+ cur += ch;
91
+ }
92
+ if (cur.trim() !== '')
93
+ out.push(cur);
94
+ return out;
95
+ }
96
+ /**
97
+ * 单条声明中的外域引用判定:命中返回引用 URL(供 title 域名提示),无外域返回
98
+ * null。先摘 data: URL(base64 字符可能含 '//',避免误报)后查两种形态:
99
+ * url(...) 括号内(引号三态)与引号字符串字面量/无引号 //host(image-set 的
100
+ * URL 可不写 url())。content:"…" 等纯展示文本命中属可接受的误伤(剥声明不剥内容)。
101
+ */
102
+ function externalRefInDeclaration(decl) {
103
+ const withoutData = decl.replace(/data:[a-z0-9.+-]+\/[a-z0-9.+-]+(?:;[^;)'"\s]*)?/gi, '');
104
+ const urlFn = /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*?))\s*\)/gi;
105
+ for (let m = urlFn.exec(withoutData); m !== null; m = urlFn.exec(withoutData)) {
106
+ const inner = (m[1] ?? m[2] ?? m[3] ?? '').trim();
107
+ if (isExternalMediaSrc(inner))
108
+ return inner;
109
+ }
110
+ const quoted = /(["'])((?:(?!\1).)*)\1/g;
111
+ for (let m = quoted.exec(withoutData); m !== null; m = quoted.exec(withoutData)) {
112
+ const inner = (m[2] ?? '').trim();
113
+ if (isExternalMediaSrc(inner))
114
+ return inner;
115
+ }
116
+ const bare = withoutData.match(/(?:^|[\s(,])(?:https?:)?\/\/[a-z0-9][^\s)'",;]*/i);
117
+ if (bare !== null)
118
+ return bare[0].trim();
119
+ return null;
120
+ }
121
+ /** 行内 style:剥含外域引用的声明;全部被剥时整属性移除;有剥必打拦截标记。 */
122
+ function sanitizeStyleAttribute(el) {
123
+ const style = el.getAttribute('style');
124
+ if (style === null)
125
+ return;
126
+ const decls = splitStyleDeclarations(style);
127
+ const kept = [];
128
+ let blockedHost = '';
129
+ let blocked = false;
130
+ for (const decl of decls) {
131
+ const hit = externalRefInDeclaration(decl);
132
+ if (hit === null) {
133
+ kept.push(decl);
134
+ continue;
135
+ }
136
+ blocked = true;
137
+ if (blockedHost === '' && hit !== '')
138
+ blockedHost = hostOf(hit);
139
+ }
140
+ if (!blocked)
141
+ return;
142
+ if (kept.length === 0)
143
+ el.removeAttribute('style');
144
+ else
145
+ el.setAttribute('style', kept.join(';'));
146
+ markBlockedExternal(el, blockedHost);
147
+ }
148
+ let dataUriHookRegistered = false;
149
+ // ---------- 豁免 style 的安全判定(修复轮 1 H1/M1/L1) ----------
150
+ //
151
+ // 匹配在归一化副本上进行:浏览器 CSS tokenizer 对 ident/值内反斜杠转义先解码再
152
+ // 语义化——`\75 rl(`、`u\72 l(` 在浏览器里都按 url( 生效,字面串匹配会漏(hex
153
+ // 转义绕过可实现无交互外域 GET,击穿「零外域自动 GET」不变量)。归一化两步:
154
+ // hex 转义(CSS 规范语义:至多 6 位 + 恰好消费一个尾随空白)→ 码点,越界回落
155
+ // U+FFFD;字面转义(`\;` 等)→ 去反斜杠。先 hex 后字面(否则 `\75` 会被字面
156
+ // 规则截断)。归一化仅用于匹配,不改写保留节点的文本(合法 CSS 的有意转义不动)。
157
+ function cssEscapeNormalized(text) {
158
+ return text
159
+ .replace(/\\([0-9a-fA-F]{1,6})\s?/g, (_m, hex) => {
160
+ const cp = parseInt(hex, 16);
161
+ // CSS 规范:越界码点(>10FFFF)按 U+FFFD 处理——不可能是任何危险 token 的组成
162
+ return cp > 0x10ffff ? String.fromCodePoint(0xfffd) : String.fromCodePoint(cp);
163
+ })
164
+ .replace(/\\(.)/g, '$1');
165
+ }
166
+ // 危险 token 清单(不区分大小写;无 g 旗标——RegExp.test 无 lastIndex 状态):
167
+ // </style 逃逸/守卫触发向量;
168
+ // url( 外联加载主向量(转义变体由归一化拆除)——仅拒绝非片段形态
169
+ // (终审 C1):`url(` 后(可选空白+可选引号)首字符为 # 属同文档
170
+ // 片段引用,零网络放行——svgbob 引擎 style 恒含
171
+ // `marker-start: url(#arrow)` 等形态(0.7.6 实测),一刀切会把
172
+ // 全部 svgbob 服务端图的线条样式杀没;引号/绝对 URL 形态仍整杀;
173
+ // image-set( 字符串 URL 形态无 url((M1:与属性层 externalRefInDeclaration
174
+ // 的 image-set 同口径——那里逐声明剥除,这里整节点丢弃),无
175
+ // 片段语义,维持整杀;
176
+ // @import 样式表级外联;
177
+ // behavior: 遗留 IE 行为绑定(L1);
178
+ // -moz-binding: 遗留 XBL 绑定(L1);
179
+ // expression( 遗留 IE CSS 表达式;
180
+ // http(s):// 绝对 URL 兜底:引擎 CSS 无外链,任何转义伪装归一化后同此命中。
181
+ const STYLE_DEADLY = [
182
+ /<\/\s*style/i,
183
+ /url\((?!\s*['"]?#)/i,
184
+ /image-set\(/i,
185
+ /@import/i,
186
+ /behavior\s*:/i,
187
+ /-moz-binding\s*:/i,
188
+ /expression\(/i,
189
+ /https?:\/\//i,
190
+ ];
191
+ function styleTextIsDeadly(text) {
192
+ const normalized = cssEscapeNormalized(text);
193
+ return STYLE_DEADLY.some((re) => re.test(normalized));
194
+ }
195
+ // ---------- 服务端图表容器契约(拆包提取:原硬编码于 style 豁免钩子内) ----------
196
+ //
197
+ // compute markdown 的服务端图表(server/src/compute/diagrams.rs)与 render-text
198
+ // wrapServerDiagrams 产出 [data-vv-diagram="server"] 容器,style 豁免钩子按该契约
199
+ // 识别容器上下文。拆包后契约字面量提取为模块默认值 + 按调用可配选项
200
+ // (SanitizeOptions.serverDiagram),默认值与原硬编码字面量逐字一致——既有产出
201
+ // 对端零改动即可继续命中豁免。
202
+ /** 服务端图表容器契约默认属性名 */
203
+ const SERVER_DIAGRAM_ATTR = 'data-vv-diagram';
204
+ /** 服务端图表容器契约默认取值 */
205
+ const SERVER_DIAGRAM_VALUE = 'server';
206
+ /** 归一化契约:未配置字段回落服务端契约默认字面量 */
207
+ function normalizeServerDiagramContract(contract) {
208
+ return {
209
+ attr: contract?.attr ?? SERVER_DIAGRAM_ATTR,
210
+ value: contract?.value ?? SERVER_DIAGRAM_VALUE,
211
+ };
212
+ }
213
+ // DOMPurify Config 无官方自定义字段通道;契约随当次 sanitize 的 config 注入,由
214
+ // uponSanitizeElement 钩子第 3 参读回(3.4.16 实测:_parseConfig 对传入 config
215
+ // 全量 clone 保留自有键、_executeHooks 把当次 CONFIG 原样传给钩子)——逐调用
216
+ // 透传,钩子侧不持模块级可变状态。键名加 __ 前缀避免与上游未来新增键冲突。
217
+ const SERVER_DIAGRAM_CONFIG_KEY = '__vvServerDiagramContract';
218
+ /** 钩子侧读回当次契约:config 未携带(防御性兜底)时回落默认字面量 */
219
+ function hookServerDiagramContract(config) {
220
+ return (config?.[SERVER_DIAGRAM_CONFIG_KEY] ??
221
+ normalizeServerDiagramContract());
222
+ }
223
+ function registerSanitizeHooks() {
224
+ if (dataUriHookRegistered)
225
+ return;
226
+ dataUriHookRegistered = true;
227
+ DOMPurify.addHook('uponSanitizeElement', (node, data, config) => {
228
+ // ---------- 服务端图表 style 上下文豁免(spec §2.5,2026-10-19 控制器裁决) ----------
229
+ //
230
+ // compute markdown 的服务端图表(server/src/compute/diagrams.rs)产出带引擎生成
231
+ // <style> 的 SVG(layout-rs 仅字体规则;svgbob 固定描边规则 + 用户 CSS——
232
+ // `# Legend:` 语法 `name = {css}` 原样并入 style 块,0.7.6 实测);FORBID_TAGS
233
+ // 一刀切会把线条样式剥没(svgbob 线全消失)。裁决:服务端图表容器内的 style
234
+ // 经安全检查后保留;容器外维持原剥除语义(BUG-40 防线不松动)。Legend 用户
235
+ // CSS 的外泄面由下方全量归一化危险 token 判定兜住(凡含 url( 非片段形态/
236
+ // @import/绝对 URL 等即整节点丢弃),页面级样式注入与作者伪造容器同为 M2
237
+ // 口径知情接受。
238
+ //
239
+ // 拆包提取(2026-10-31):容器识别字面量不再硬编码于此——经当次 sanitize 的
240
+ // config 注入(SanitizeOptions.serverDiagram,默认即 data-vv-diagram="server"
241
+ // 服务端契约字面量),见上方契约节。
242
+ //
243
+ // 威胁模型(修复轮 1 M2 落实):该容器属性可被 markdown 作者伪造——comrak
244
+ // render.unsafe 透传作者原始 HTML 且 ALLOW_DATA_ATTR 保留 data-*,豁免并非
245
+ // 只服务端图表可达:作者可自造带属性 div 获得页面级样式注入(选择器级
246
+ // chrome 篡改,中危,知情接受);「零外域自动 GET」不变量由下方危险 token
247
+ // 判定阻断(归一化匹配 + 命中即整节点丢弃,见 styleTextIsDeadly)。
248
+ //
249
+ // 机制注(DOMPurify 3.4.16 实测语义,非旧版惯用法):FORBID_TAGS 命中在钩子
250
+ // 载荷之外短路移除(_sanitizeDisallowedNode),uponSanitizeElement 的
251
+ // data.allowed/allowedTags 均无法覆写。故 style 移出 FORBID_TAGS(回落默认
252
+ // 允许表),钩子内按节点上下文二分——容器外由钩子自行摘除节点(元素连 CSS
253
+ // 文本一并移除;DOMPurify 对钩内摘除有 _handleHookDetachedNode 正式支撑,
254
+ // 可观察输出与原 FORBID_TAGS+FORBID_CONTENTS 一致);容器内按判定放行或丢弃。
255
+ if (data.tagName !== 'style' || node.nodeType !== 1)
256
+ return;
257
+ const { attr, value } = hookServerDiagramContract(config);
258
+ const el = node;
259
+ let inServer = false;
260
+ for (let cur = el.parentNode; cur !== null; cur = cur.parentNode) {
261
+ if (cur.nodeType === 1 && cur.getAttribute(attr) === value) {
262
+ inServer = true;
263
+ break;
264
+ }
265
+ }
266
+ if (!inServer) {
267
+ el.remove(); // 容器外:维持 FORBID_TAGS 原语义(元素连内容一并移除)
268
+ return;
269
+ }
270
+ // 容器内豁免:命中任一危险 token(归一化匹配,H1/M1/L1)→ 整节点丢弃——
271
+ // 引擎生成 CSS 永不含这些 token,凡命中即敌意输入,宁降级不冒险(不做
272
+ // 删除式保留:删除防不住转义重组后的二次拼接,徒留探测面)。未命中的
273
+ // 合法引擎 CSS 原样保留、零改动。
274
+ if (styleTextIsDeadly(el.textContent ?? '')) {
275
+ el.remove();
276
+ }
277
+ });
278
+ DOMPurify.addHook('afterSanitizeAttributes', (node) => {
279
+ for (const attr of Array.from(node.attributes)) {
280
+ if (DATA_URI_ATTRS.has(attr.name.toLowerCase()))
281
+ continue;
282
+ if (/^\s*data:/i.test(attr.value))
283
+ node.removeAttribute(attr.name);
284
+ }
285
+ // BUG-17:img 的 http(s)/协议相对 src 一律移除并打拦截标记——渲染视图中不再
286
+ // 向外域发起网络请求(跟踪像素拿不到 IP);title 保留域名供占位悬停提示。
287
+ // 相对路径与 data:/blob: 不受影响(markdown 相对图片解析为 blob 的链路发生在
288
+ // 净化之后,同样不受影响);链接 <a href> 外链不拦(用户主动导航型外泄)。
289
+ if (node.nodeType === 1) {
290
+ const el = node;
291
+ const tag = el.tagName;
292
+ if (tag === 'IMG') {
293
+ const src = el.getAttribute('src');
294
+ const srcExternal = src !== null && isExternalMediaSrc(src.trim());
295
+ if (srcExternal) {
296
+ el.removeAttribute('src');
297
+ markBlockedExternal(el, hostOf(src.trim()));
298
+ }
299
+ // srcset 是同等的图片加载源(无 src 时浏览器按 srcset 加载;markdown 渲染
300
+ // 视图把净化后 DOM 挂主文档、无 CSP 兜底):逐候选过滤——srcset 语法上逗号
301
+ // 不出现在 URL 内,候选首段(首个空白前)即其 URL。外域候选移除、其余保留;
302
+ // 过滤后无任何可用加载源(src 缺失或同为外域已拦)时补拦截标记。
303
+ const srcset = el.getAttribute('srcset');
304
+ if (srcset !== null) {
305
+ const candidates = srcset.split(',').map((c) => c.trim()).filter((c) => c !== '');
306
+ const kept = [];
307
+ let firstBlockedHost = srcExternal ? hostOf(src.trim()) : '';
308
+ for (const c of candidates) {
309
+ const url = (c.split(/\s+/)[0] ?? '').trim();
310
+ if (isExternalMediaSrc(url)) {
311
+ if (firstBlockedHost === '')
312
+ firstBlockedHost = hostOf(url);
313
+ continue;
314
+ }
315
+ kept.push(c);
316
+ }
317
+ if (kept.length !== candidates.length) {
318
+ if (kept.length === 0)
319
+ el.removeAttribute('srcset');
320
+ else
321
+ el.setAttribute('srcset', kept.join(', '));
322
+ if (kept.length === 0 && (src === null || srcExternal)) {
323
+ markBlockedExternal(el, firstBlockedHost);
324
+ }
325
+ }
326
+ }
327
+ }
328
+ // BUG-17/MD-13 延伸:video/audio/source 的外域 src 同样会自动加载(Chrome
329
+ // 默认 preload=metadata 即对外域 GET 首块数据,可回传 IP)。与 img 不同:
330
+ // 不剥 src——用户点播放属主动行为(与 <a href> 外链不拦同口径),改强制
331
+ // preload="none" 并去 autoplay,保证不点不发请求;<source> 是候选列表语义
332
+ // 无法延迟加载,外域候选直接剥除 src。
333
+ else if (tag === 'VIDEO' || tag === 'AUDIO' || tag === 'SOURCE') {
334
+ const src = el.getAttribute('src');
335
+ if (src !== null && isExternalMediaSrc(src.trim())) {
336
+ if (tag === 'SOURCE') {
337
+ el.removeAttribute('src');
338
+ }
339
+ else {
340
+ el.setAttribute('preload', 'none');
341
+ el.removeAttribute('autoplay');
342
+ }
343
+ }
344
+ // BUG-40①:poster 图随元素渲染即拉取(与 preload 无关,preload=none 拦不住),
345
+ // 与 src 的「点播放才请求」语义不同权——直接移除(同 img 剥 src 口径)。
346
+ const poster = el.getAttribute('poster');
347
+ if (poster !== null && isExternalMediaSrc(poster.trim())) {
348
+ el.removeAttribute('poster');
349
+ markBlockedExternal(el, hostOf(poster.trim()));
350
+ }
351
+ }
352
+ // BUG-40②③④⑤:SVG 引用元素 / 遗留 background 属性 / input type=image / 行内
353
+ // style url()——五类等价加载向量,全部与 img src 同权(移除加载源 + 拦截标记)。
354
+ // 注:text/html 解析下 SVG 元素 tagName 为小写(image/use);<svg> 外的 <image>
355
+ // 会被 HTML 解析器改写为 img(上方 IMG 分支已覆盖)。
356
+ const svgTag = tag.toLowerCase();
357
+ if (svgTag === 'image' || svgTag === 'use') {
358
+ // SVG image/use 的 href 与 xlink:href(解析器二选一出现,双剥保险)
359
+ for (const attr of ['href', 'xlink:href']) {
360
+ const v = el.getAttribute(attr);
361
+ if (v === null)
362
+ continue;
363
+ if (isExternalMediaSrc(v.trim())) {
364
+ el.removeAttribute(attr);
365
+ el.removeAttributeNS(XLINK_NS, 'href');
366
+ markBlockedExternal(el, hostOf(v.trim()));
367
+ }
368
+ }
369
+ }
370
+ const background = el.getAttribute('background');
371
+ if (background !== null && isExternalMediaSrc(background.trim())) {
372
+ el.removeAttribute('background');
373
+ markBlockedExternal(el, hostOf(background.trim()));
374
+ }
375
+ if (tag === 'INPUT' && (el.getAttribute('type') ?? '').toLowerCase() === 'image') {
376
+ const src = el.getAttribute('src');
377
+ if (src !== null && isExternalMediaSrc(src.trim())) {
378
+ el.removeAttribute('src');
379
+ markBlockedExternal(el, hostOf(src.trim()));
380
+ }
381
+ }
382
+ sanitizeStyleAttribute(el);
383
+ }
384
+ });
385
+ }
386
+ // <style> 默认在 DOMPurify 允许表内且其 CSS 不经过滤:作者样式表注入预览文档后
387
+ // 可全局生效(隐藏 UI / background:url 外传),本应禁——现由 uponSanitizeElement
388
+ // 钩子按上下文二分承载(见 registerSanitizeHooks 内注释):服务端图表容器内豁免
389
+ // (容器契约默认 data-vv-diagram="server",经 SanitizeOptions.serverDiagram 可配),
390
+ // 容器外钩子摘除(语义同禁)。行内 style 属性仍允许。
391
+ // <meta> 当前虽不在 DOMPurify 默认允许表内,仍显式声明防上游默认变化
392
+ // (http-equiv=refresh/UVG 元信息不应出现在预览片段;沙箱文档的 CSP meta 由
393
+ // html 渲染器在净化之后自行注入,不受此禁影响)。
394
+ // 注意 style 不得留在 FORBID_TAGS:3.4.16 中 FORBID_TAGS 命中先于钩子载荷短路
395
+ // 移除,钩子将无从豁免(见钩子内机制注)。
396
+ export const MARKDOWN_SANITIZE_CONFIG = {
397
+ ALLOWED_URI_REGEXP,
398
+ FORBID_TAGS: ['meta'],
399
+ ALLOW_DATA_ATTR: true,
400
+ };
401
+ /**
402
+ * 服务端获取的图表 SVG 片段净化(spec 2026-10-23 §8.3):server 模式
403
+ * (/api/compute/diagram)与 krokiVia=server(/api/kroki 代发)两分支共用的
404
+ * 承接面——片段包进契约壳后整串走 sanitizeHtml,uponSanitizeElement 钩子按壳
405
+ * 上下文放行引擎 <style>(危险 token 全量归一化判定兜底,url(# 同文档片段引用
406
+ * 既有放行),与 compute markdown 后处理产物的 wrapServerDiagrams 承接面同一
407
+ * 豁免语义。壳须留在净化输入串内(钩子按串内祖先上下文二分),净化后剥壳取回
408
+ * 内层——敌意内容若截断壳,截出部分落容器外 → style 豁免不适用(fail-closed,
409
+ * 且整串仍经 DOMPurify 全量净化)。壳属性与钩子识别同源取自 opts.serverDiagram
410
+ * (默认 data-vv-diagram="server"),契约字面量不会在壳/钩两处漂移;attr/value
411
+ * 为调用方自有契约常量(非不可信输入),直接拼入净化输入串。
412
+ */
413
+ export function sanitizeDiagramFragment(root, html, opts = {}) {
414
+ const { attr, value } = normalizeServerDiagramContract(opts.serverDiagram);
415
+ const probe = root.createElement('div');
416
+ probe.setAttribute(attr, value);
417
+ // 先在管线期 detached doc 内解析归一(innerHTML 不执行脚本),再嵌壳净化——
418
+ // 与 sanitizeHtml 的 Document 输入两步语义一致
419
+ probe.innerHTML = html;
420
+ const holder = root.createElement('div');
421
+ holder.innerHTML = sanitizeHtml(`<div ${attr}="${value}">${probe.innerHTML}</div>`, opts);
422
+ return holder.firstElementChild?.innerHTML ?? '';
423
+ }
424
+ /**
425
+ * 不可信渲染 HTML 过唯一共享策略。string 与 Document 输入统一返回字符串
426
+ * (SDD Ruling:T3 管线以字符串为统一出口,自行 innerHTML 成 DOM)。
427
+ * Document 输入取 body 内容净化(DOMPurify 无法导入文档节点本身;本管线
428
+ * 的 Document 均为 body 级片段容器)。wholeDocument 时输入必须是完整文档
429
+ * 字符串(Document 输入会丢 head,此时应直接传原始字符串)。
430
+ */
431
+ export function sanitizeHtml(dirty, opts = {}) {
432
+ registerSanitizeHooks();
433
+ const html = typeof dirty === 'string' ? dirty : dirty.body.innerHTML;
434
+ // 每次新建 config(不回写共享的 MARKDOWN_SANITIZE_CONFIG):契约与
435
+ // wholeDocument 均为逐调用形态,经钩子第 3 参 CONFIG 透传
436
+ const config = {
437
+ ...MARKDOWN_SANITIZE_CONFIG,
438
+ ...(opts.wholeDocument ? { WHOLE_DOCUMENT: true } : {}),
439
+ [SERVER_DIAGRAM_CONFIG_KEY]: normalizeServerDiagramContract(opts.serverDiagram),
440
+ };
441
+ // 无 RETURN_DOM/RETURN_DOM_FRAGMENT 的重载返回 string
442
+ return DOMPurify.sanitize(html, config);
443
+ }