BUG: Closing `</script>` tag not escaped for script properties
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Chrome Version 107.0.5304.122 (64-bit)
Reproducible demo link
https://jsfiddle.net/j5khz1gm/
Describe the bug
How to reproduce the bug?
-
Create a custom component type with the following default properties:
{ someText: "<\/script><svg onload='alert(1)'>", "script-props": ["someText"], script: function() { this.innerHTML = ""; } } -
Add the custom component to the canvas
-
Get the page HTML with
editor.getHtml() -
Insert the HTML into a div outside of the editor
What is the expected behavior? Expected the closing script tag to be escaped in the generated HTML. No alert dialog should appear.
What is the current behavior?
The script tag is not escaped. The svg tag is displayed in the document. Using the code below in a local HTML file will always execute alert(1). For whatever reason, the alert dialog does not always appear in JSFiddle.
If is necessary to execute some code in order to reproduce the bug, paste it here below:
<link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
<script src="https://unpkg.com/grapesjs"></script>
<div id="grapes"></div>
<div id="html"></div>
<script>
const editor = grapesjs.init({
container: "#grapes",
fromElement: true,
storageManager: false
});
editor.DomComponents.addType("my-component", {
model: {
defaults: {
someText: "<\/script><svg onload='alert(1)'>",
"script-props": ["someText"],
script: function() {
this.innerHTML = "";
}
}
}
});
editor.on("load", () => {
editor.addComponents({
type: "my-component"
});
document.getElementById("html").innerHTML = editor.getHtml();
});
</script>
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (1)
@jasonliang-dev any update on this? i facing same issue.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3939
BUG: Disabled drag and drop in preview
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? v95Reproducible demo link https://codesandbo...
Issue #4015
BUG: Drag and drop not working well in case of RTL
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v96 Reproducible demo link https://...
Issue #4294
BUG: Unable to drop textable components into small text areas
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v100 Reproducible demo link https:/...
Issue #4592
BUG: Textable Component becomes Noneditable when dropped in a Text Block
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? 104.0.5112.102 Reproducible demo link http...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.