Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The HTML escape helper imports an internal markdown-it module path that may fail strict TypeScript builds and should be replaced with a local or typed wrapper.
1 open issue
1 file not reviewed
pnpm-lock.yaml: Generated file
What changed in this PR
This pull request prevents HTML injection in Live2D tip messages by escaping dynamic values and sanitizing ordinary tip HTML while preserving AI Markdown rendering.
Changes:
- Adds DOMPurify sanitization with a restricted formatting allowlist.
- Escapes page titles, selector substitutions, and Hitokoto response fields.
- Adds documentation, dependency updates, and regression tests.
| File | Description |
|---|---|
README.md |
Documents supported ordinary-tip formatting and sanitization behavior. |
pnpm-lock.yaml |
Locks the new DOMPurify dependency. |
packages/live2d/src/live2d/tools/hitokoto.ts |
Escapes Hitokoto content, source, and creator values. |
packages/live2d/src/live2d/tools/__tests__/hitokoto.test.ts |
Tests safe Hitokoto message rendering. |
packages/live2d/src/helpers/renderTipMessage.ts |
Sanitizes ordinary tip HTML and provides a safe fallback. |
packages/live2d/src/helpers/escapeHtml.ts |
Provides HTML escaping for dynamic text. |
packages/live2d/src/helpers/__tests__/renderTipMessage.test.ts |
Tests sanitizer fallback behavior. |
packages/live2d/src/events/tip-events.ts |
Escapes page titles, referrer domains, and selector substitutions. |
packages/live2d/src/events/__tests__/tip-events.test.ts |
Tests safe dynamic-text interpolation. |
packages/live2d/src/components/Live2dTips.tsx |
Applies ordinary-tip sanitization while retaining Markdown rendering. |
packages/live2d/src/components/__tests__/Live2dTips.test.ts |
Tests ordinary and streamed message rendering. |
packages/live2d/package.json |
Adds DOMPurify as a runtime dependency. |
Review effort: Lite
| @@ -0,0 +1 @@ | |||
| export { escapeHtml } from "markdown-it/lib/common/utils.mjs"; | |||
Owner
Author
There was a problem hiding this comment.
已在 e1ca0e6 改用公开的 new MarkdownIt().utils.escapeHtml,继续复用库实现。当前锁定的 @types/markdown-it@14.1.2 实际包含原路径的类型声明,原代码构建也能通过;此次调整消除了对内部路径的依赖。244 项前端测试及生产构建通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What this PR does / why we need it:
页面标题、选择器提示中的
{text}、一言内容及来源/作者此前直接进入提示语 HTML,可能创建 iframe 等活动元素。现在复用 markdown-it 转义动态文本,并使用 DOMPurify 过滤普通提示语,保留基础排版。AI Markdown 渲染保持现有行为。自定义普通提示语不再支持嵌入内容、事件和样式属性,支持的排版标签已在 README 中说明。
{text}会替换全部占位符,并保持$&等文字原样显示。Which issue(s) this PR fixes:
Fixes #86
Does this PR introduce a user-facing change?