File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616 </ head >
1717 < body >
1818 < div id ="root "> </ div >
19+ < script src ="https://cdn.jsdelivr.net/npm/dompurify@3.1.6/dist/purify.min.js "> </ script >
1920 < script >
2021 ( function ( ) {
2122 const SANDBOX_PROXY_READY_METHOD =
3637 // Listen for the app resource (HTML) from the host
3738 window . addEventListener ( "message" , ( event ) => {
3839 const message = event . data ;
39- if ( message && message . method === SANDBOX_RESOURCE_READY_METHOD ) {
40+ if (
41+ message &&
42+ typeof message === "object" &&
43+ message . method === SANDBOX_RESOURCE_READY_METHOD &&
44+ message . params &&
45+ typeof message . params . html === "string"
46+ ) {
4047 const { html } = message . params ;
4148 if ( html ) {
42- // Write the HTML to the document
49+ // Sanitize the HTML before writing it to the document
50+ const safeHtml = window . DOMPurify
51+ ? window . DOMPurify . sanitize ( html )
52+ : html ;
4353 document . open ( ) ;
44- document . write ( html ) ;
54+ document . write ( safeHtml ) ;
4555 document . close ( ) ;
4656 }
4757 }
You can’t perform that action at this time.
0 commit comments