mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-30 17:52:48 +00:00
fix: Markdown editor xss attack (#4578)
This commit is contained in:
parent
159997c529
commit
7230daa5ec
|
|
@ -12,7 +12,8 @@ import i18n from '@/locales'
|
|||
import Components from '@/components'
|
||||
import directives from '@/directives'
|
||||
|
||||
import { config } from 'md-editor-v3'
|
||||
import { getDefaultWhiteList } from 'xss'
|
||||
import { config, XSSPlugin } from 'md-editor-v3'
|
||||
import screenfull from 'screenfull'
|
||||
|
||||
import katex from 'katex'
|
||||
|
|
@ -43,6 +44,50 @@ config({
|
|||
instance: mermaid,
|
||||
},
|
||||
},
|
||||
markdownItPlugins(plugins) {
|
||||
return [
|
||||
...plugins,
|
||||
{
|
||||
type: 'xss',
|
||||
plugin: XSSPlugin,
|
||||
options: {
|
||||
xss() {
|
||||
return {
|
||||
whiteList: Object.assign({}, getDefaultWhiteList(), {
|
||||
video: ['src', 'controls', 'width', 'height', 'preload', 'playsinline'],
|
||||
source: ['src', 'type'],
|
||||
input: ['class', 'disabled', 'type', 'checked'],
|
||||
iframe: [
|
||||
'class',
|
||||
'width',
|
||||
'height',
|
||||
'src',
|
||||
'title',
|
||||
'border',
|
||||
'frameborder',
|
||||
'framespacing',
|
||||
'allow',
|
||||
'allowfullscreen',
|
||||
],
|
||||
}),
|
||||
onTagAttr: (tag: string, name: any, value: any) => {
|
||||
if (tag === 'video') {
|
||||
// 禁止自动播放
|
||||
if (name === 'autoplay') return ''
|
||||
|
||||
// 限制 preload
|
||||
if (name === 'preload' && !['none', 'metadata'].includes(value)) {
|
||||
return 'preload="metadata"'
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
})
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
|
|
|
|||
Loading…
Reference in New Issue