fix: Markdown editor xss attack (#4553)

This commit is contained in:
shaohuzhang1 2025-12-23 18:53:36 +08:00 committed by GitHub
parent b39ecf691b
commit d8d15c8902
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 7 deletions

View File

@ -45,6 +45,7 @@
"nprogress": "^0.2.0",
"pinia": "^3.0.1",
"recorder-core": "^1.3.25011100",
"sanitize-html": "^2.17.0",
"screenfull": "^6.0.2",
"sortablejs": "^1.15.6",
"svg2pdf.js": "^2.5.0",

View File

@ -1,5 +1,5 @@
<template>
<MdEditor :language="language" noIconfont noPrettier v-bind="$attrs">
<MdEditor :language="language" noIconfont noPrettier v-bind="$attrs" :sanitize="sanitize">
<template #defFooters>
<slot name="defFooters"> </slot>
</template>
@ -13,14 +13,17 @@ import { getBrowserLang } from '@/locales/index'
import './assets/markdown-iconfont.js'
//
import ZH_TW from '@vavt/cm-extension/dist/locale/zh-TW'
import sanitizeHtml from 'sanitize-html'
defineOptions({ name: 'MdEditor' })
const language = computed(() => localStorage.getItem('MaxKB-locale') || getBrowserLang() || '')
config({
editorConfig: {
languageUserDefined: {
'zh-Hant': ZH_TW
}
}
'zh-Hant': ZH_TW,
},
},
})
const sanitize = (html: any) => {
return sanitizeHtml(html)
}
</script>

View File

@ -1,5 +1,12 @@
<template>
<MdPreview :language="language" noIconfont noPrettier :codeFoldable="false" v-bind="$attrs" />
<MdPreview
:language="language"
noIconfont
noPrettier
:sanitize="sanitize"
:codeFoldable="false"
v-bind="$attrs"
/>
</template>
<script setup lang="ts">
@ -9,7 +16,7 @@ import { getBrowserLang } from '@/locales/index'
import useStore from '@/stores'
//
import ZH_TW from '@vavt/cm-extension/dist/locale/zh-TW'
import sanitizeHtml from 'sanitize-html'
defineOptions({ name: 'MdPreview' })
const emit = defineEmits(['clickPreview'])
@ -23,6 +30,9 @@ config({
},
},
})
const sanitize = (html: any) => {
return sanitizeHtml(html)
}
</script>
<style lang="scss" scoped>