Skip to content

Commit 4305941

Browse files
Potential fix for code scanning alert no. 1821: DOM text reinterpreted as HTML
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent feb6494 commit 4305941

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/pages/LiveEditor/BasicEditor.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ const BasicEditor = () => {
2626
}
2727

2828
const iframe = iframeRef.current;
29-
const document = iframe.contentDocument;
30-
31-
if (!document) {
32-
alert("iframe contentDocument is not available");
33-
return;
34-
}
3529

3630
const documentContents = `
3731
<!DOCTYPE html>
@@ -46,9 +40,7 @@ const BasicEditor = () => {
4640
</html>
4741
`;
4842

49-
document.open();
50-
document.write(documentContents);
51-
document.close();
43+
iframe.srcdoc = documentContents;
5244
}, [html, css, js]);
5345

5446
return (
@@ -210,7 +202,12 @@ const BasicEditor = () => {
210202
</div>
211203
</div>
212204

213-
<iframe ref={iframeRef} className="output_container" id="preview" />
205+
<iframe
206+
ref={iframeRef}
207+
className="output_container"
208+
id="preview"
209+
sandbox="allow-scripts"
210+
/>
214211
</div>
215212
</div>
216213
);

0 commit comments

Comments
 (0)