Skip to content

Commit 017a51e

Browse files
committed
fix: Markdown editor xss attack
1 parent b39ecf6 commit 017a51e

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"nprogress": "^0.2.0",
4646
"pinia": "^3.0.1",
4747
"recorder-core": "^1.3.25011100",
48+
"sanitize-html": "^2.17.0",
4849
"screenfull": "^6.0.2",
4950
"sortablejs": "^1.15.6",
5051
"svg2pdf.js": "^2.5.0",

ui/src/components/markdown/MdEditor.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<MdEditor :language="language" noIconfont noPrettier v-bind="$attrs">
2+
<MdEditor :language="language" noIconfont noPrettier v-bind="$attrs" :sanitize="sanitize">
33
<template #defFooters>
44
<slot name="defFooters"> </slot>
55
</template>
@@ -13,14 +13,17 @@ import { getBrowserLang } from '@/locales/index'
1313
import './assets/markdown-iconfont.js'
1414
// 引入公共库中的语言配置
1515
import ZH_TW from '@vavt/cm-extension/dist/locale/zh-TW'
16-
16+
import sanitizeHtml from 'sanitize-html'
1717
defineOptions({ name: 'MdEditor' })
1818
const language = computed(() => localStorage.getItem('MaxKB-locale') || getBrowserLang() || '')
1919
config({
2020
editorConfig: {
2121
languageUserDefined: {
22-
'zh-Hant': ZH_TW
23-
}
24-
}
22+
'zh-Hant': ZH_TW,
23+
},
24+
},
2525
})
26+
const sanitize = (html: any) => {
27+
return sanitizeHtml(html)
28+
}
2629
</script>

ui/src/components/markdown/MdPreview.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<template>
2-
<MdPreview :language="language" noIconfont noPrettier :codeFoldable="false" v-bind="$attrs" />
2+
<MdPreview
3+
:language="language"
4+
noIconfont
5+
noPrettier
6+
:sanitize="sanitize"
7+
:codeFoldable="false"
8+
v-bind="$attrs"
9+
/>
310
</template>
411

512
<script setup lang="ts">
@@ -9,7 +16,7 @@ import { getBrowserLang } from '@/locales/index'
916
import useStore from '@/stores'
1017
// 引入公共库中的语言配置
1118
import ZH_TW from '@vavt/cm-extension/dist/locale/zh-TW'
12-
19+
import sanitizeHtml from 'sanitize-html'
1320
defineOptions({ name: 'MdPreview' })
1421
1522
const emit = defineEmits(['clickPreview'])
@@ -23,6 +30,9 @@ config({
2330
},
2431
},
2532
})
33+
const sanitize = (html: any) => {
34+
return sanitizeHtml(html)
35+
}
2636
</script>
2737

2838
<style lang="scss" scoped>

0 commit comments

Comments
 (0)