Skip to content

Commit 2bc0949

Browse files
committed
Sanitize comment content before rendering
1 parent 9824a9e commit 2bc0949

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

packages/comment-widget/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@
4848
"javascript-time-ago": "^2.5.11",
4949
"lit": "^3.3.1",
5050
"ofetch": "^1.4.1",
51+
"sanitize-html": "^2.17.0",
5152
"tiptap-extension-code-block-shiki": "^0.6.0",
5253
"ua-parser-js": "^2.0.4"
5354
},
5455
"devDependencies": {
5556
"@iconify/json": "^2.2.367",
5657
"@lit/localize-tools": "^0.8.0",
58+
"@types/sanitize-html": "^2.16.0",
5759
"@unocss/reset": "^66.4.2",
5860
"lit-analyzer": "^2.0.3",
5961
"unocss": "^66.4.1"

packages/comment-widget/src/base-comment-item.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import contentStyles from './styles/content.css?inline';
99
import { formatDate, timeAgo } from './utils/date';
1010
import './commenter-ua-bar';
1111
import { consume } from '@lit/context';
12+
import sanitizeHtml from 'sanitize-html';
1213
import { configMapDataContext } from './context';
1314
import type { ConfigMapData } from './types';
1415

@@ -120,7 +121,7 @@ export class BaseCommentItem extends LitElement {
120121
</div>
121122
122123
<div class="item-content mt-2 content">
123-
<slot name="pre-content"></slot>${unsafeHTML(this.content)}
124+
<slot name="pre-content"></slot>${unsafeHTML(sanitizeHtml(this.content))}
124125
</div>
125126
126127
<div class="item-actions mt-2 flex items-center gap-3">

pnpm-lock.yaml

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)