Bug fix for issue #724; XSS issue when importing through getHTML() function; remove usage of innerHTML and pre-parse the string using native JS DOMParser

This commit is contained in:
John Nguyen 2020-07-01 14:01:31 -07:00
parent 4954f8297c
commit 5d17f68c0c

View File

@ -52,20 +52,13 @@ export default class Editor extends Emitter {
dropCursor: {},
parseOptions: {},
injectCSS: true,
onInit: () => {
},
onTransaction: () => {
},
onUpdate: () => {
},
onFocus: () => {
},
onBlur: () => {
},
onPaste: () => {
},
onDrop: () => {
},
onInit: () => {},
onTransaction: () => {},
onUpdate: () => {},
onFocus: () => {},
onBlur: () => {},
onPaste: () => {},
onDrop: () => {},
}
this.events = [
@ -110,8 +103,7 @@ export default class Editor extends Emitter {
}
this.events.forEach(name => {
this.on(name, this.options[camelCase(`on ${name}`)] || (() => {
}))
this.on(name, this.options[camelCase(`on ${name}`)] || (() => {}))
})
this.emit('init', {
@ -283,7 +275,6 @@ export default class Editor extends Emitter {
const htmlString = `<div>${content}</div>`;
const parser = new window.DOMParser;
const element = parser.parseFromString(htmlString, "text/html").body.firstChild;
return DOMParser.fromSchema(this.schema).parse(element, parseOptions)
}
@ -293,12 +284,8 @@ export default class Editor extends Emitter {
createView() {
return new EditorView(this.element, {
state: this.createState(),
handlePaste: (...args) => {
this.emit('paste', ...args)
},
handleDrop: (...args) => {
this.emit('drop', ...args)
},
handlePaste: (...args) => { this.emit('paste', ...args) },
handleDrop: (...args) => { this.emit('drop', ...args) },
dispatchTransaction: this.dispatchTransaction.bind(this),
})
}