fix(api): sanitize html for security

This commit is contained in:
charlie
2021-10-08 17:02:58 +08:00
committed by Tienson Qin
parent e1c39de9ce
commit c34c9184e2
3 changed files with 13 additions and 9 deletions

View File

@@ -244,13 +244,6 @@ function initProviderHandlers (pluginLocal: PluginLocal) {
pluginLocal.on(_('ui'), (ui: UIOptions) => {
pluginLocal._onHostMounted(() => {
// safe template
ui.template = DOMPurify.sanitize(
ui.template, {
ADD_TAGS: ['iframe'],
ALLOW_UNKNOWN_PROTOCOLS: true,
ADD_ATTR: ['allow', 'src', 'allowfullscreen', 'frameborder', 'scrolling']
})
pluginLocal._dispose(
setupInjectedUI.call(pluginLocal,

View File

@@ -2,6 +2,7 @@ import { StyleString, UIOptions } from './LSPlugin'
import { PluginLocal } from './LSPlugin.core'
import { snakeCase } from 'snake-case'
import * as nodePath from 'path'
import DOMPurify from 'dompurify'
interface IObject {
[key: string]: any;
@@ -255,6 +256,16 @@ export function setupInjectedUI (
let el = document.querySelector(`#${id}`) as HTMLElement
if (ui.template) {
// safe template
ui.template = DOMPurify.sanitize(
ui.template, {
ADD_TAGS: ['iframe'],
ALLOW_UNKNOWN_PROTOCOLS: true,
ADD_ATTR: ['allow', 'src', 'allowfullscreen', 'frameborder', 'scrolling']
})
}
if (el) {
el.innerHTML = ui.template
return

File diff suppressed because one or more lines are too long