Skip to content

Commit 9a16f13

Browse files
Potential fix for code scanning alert no. 37: Client-side cross-site scripting
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent b5b5910 commit 9a16f13

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

client/public/sandbox_proxy.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
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 =
@@ -36,12 +37,21 @@
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
}

0 commit comments

Comments
 (0)