Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use DOMParse in pasteHTML to protect against dangerous html #990

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ class Clipboard extends Module {

convert(html) {
const DOM_KEY = '__ql-matcher';
let container = this.container;
if (typeof html === 'string') {
this.container.innerHTML = html;
let parser = new DOMParser();
let doc = parser.parseFromString(html, "text/html");
container = doc.body;
}
let textMatchers = [], elementMatchers = [];
this.matchers.forEach((pair) => {
Expand All @@ -80,7 +83,7 @@ class Clipboard extends Module {
elementMatchers.push(matcher);
break;
default:
[].forEach.call(this.container.querySelectorAll(selector), (node) => {
[].forEach.call(container.querySelectorAll(selector), (node) => {
// TODO use weakmap
node[DOM_KEY] = node[DOM_KEY] || [];
node[DOM_KEY].push(matcher);
Expand Down Expand Up @@ -110,13 +113,13 @@ class Clipboard extends Module {
return new Delta();
}
};
let delta = traverse(this.container);
let delta = traverse(container);
// Remove trailing newline
if (deltaEndsWith(delta, '\n') && delta.ops[delta.ops.length - 1].attributes == null) {
delta = delta.compose(new Delta().retain(delta.length() - 1).delete(1));
}
debug.log('convert', this.container.innerHTML, delta);
this.container.innerHTML = '';
debug.log('convert', container.innerHTML, delta);
container.innerHTML = '';
return delta;
}

Expand Down