XSS Vulnerability in Live Preview
Question
Version: 0.16.22
Are you able to reproduce the bug from the demo?
[ x] Yes
Steps:
- Click Import HTML
- Insert
<img src="any_image_source.gif" onload="alert(1)"/> - The JS will be executed
Having proper "sandbox" attribute on iframe could probably mitigate the problem.
Answers (3)
Well if you use GrapesJS and allow the possibility to insert custom HTML, yes, Self-XSS is possible.
Unfortunately, there are few issues that do not allow me to fix this properly
- I need to access the iframe's DOM in order to add/update inner components so, the editor won't work without
sandbox="allow-same-origin". - Running JS in the editor is one of its features (Components with JS) so to make them work I'd also need
allow-scripts - Having
allow-same-originandallow-scriptsat the same time is almost like not usingsandboxas the iframe is able to access cookies and other web storage interfaces (eg. LocalStorage, SessionStorage, etc.) of the parent document.
The only valid solution I see, for now, is by default enabling only sandbox="allow-same-origin". Which means Components with JS won't work and to enable it you should change some new option, by taking the risk of Self-XSS if you also allow custom HTML import
I've seen also solutions like this https://stackoverflow.com/a/41606174 (in this case it removes the possibility to read/write cookies) but I'm not sure how is actually reliable
Any suggestion?? 😬
You are right, we thought sandbox="allow-same-origin" will do the job, but allow-scripts is also needed, and then it's like not using sandbox at all.
But, what could be helpful anyway is to provide a way for grapejs users to somehow control attributes of the iframe canvas - that way they can take the responsibility and control sandbox value or other attributes.
Thanks!
if you use content security policy http header you can get around a lot of XSS issues like this. but there is one issue with GrapesJS atm which is that it uses underscore.js, which includes a function with use of "eval" so you can't make the CSP header as secure as it should be
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1295
[Bug]: Unit select field missing on IE after click
@artf I'm currently using GrapesJS latest version (but you can reproduce this bug using the demo). Basically all you have to do is select a...
Issue #3045
BUG: Problem importing CSS and module in nodejs es6
Version: 0.16.22 Are you able to reproduce the bug from the demo? [x] Yes [ ] No What is the expected behavior? To import grapejs css and m...
Issue #4448
BUG: Error on resize image.
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Brave Browser Last version Reproducible de...
Issue #3131
BUG: Paste as plain text into Text component adds <font /> wrapper to pasted text
Version: 0.16.27 Are you able to reproduce the bug from the demo? [] Yes [X] No What is the expected behavior? Paste as plain text (text no...
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.