Browse Source

fix(api): sanitize html for security

charlie 4 years ago
parent
commit
c34c9184e2
3 changed files with 11 additions and 7 deletions
  1. 0 7
      libs/src/LSPlugin.core.ts
  2. 11 0
      libs/src/helpers.ts
  3. 0 0
      resources/js/lsplugin.core.js

+ 0 - 7
libs/src/LSPlugin.core.ts

@@ -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,

+ 11 - 0
libs/src/helpers.ts

@@ -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 it is too large
+ 0 - 0
resources/js/lsplugin.core.js


Some files were not shown because too many files changed in this diff