Skip to content

Commit 3bdd050

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

File tree

1 file changed

+13
-2
lines changed
  • Windows Simulation/components/apps/browser

1 file changed

+13
-2
lines changed

Windows Simulation/components/apps/browser/App.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ interface BrowserAppProps {
88
initialFilePath?: string
99
}
1010

11+
// Utility to escape HTML special characters
12+
function escapeHtml(str: string): string {
13+
return str
14+
.replace(/&/g, "&amp;")
15+
.replace(/</g, "&lt;")
16+
.replace(/>/g, "&gt;")
17+
.replace(/"/g, "&quot;")
18+
.replace(/'/g, "&#39;")
19+
.replace(/\//g, "&#x2F;");
20+
}
21+
1122
export default function BrowserApp({ initialFilePath }: BrowserAppProps) {
1223
const [filePath, setFilePath] = useState(initialFilePath || "C:\\My Documents\\index.html")
1324
const [htmlContent, setHtmlContent] = useState("")
@@ -31,11 +42,11 @@ export default function BrowserApp({ initialFilePath }: BrowserAppProps) {
3142
setHtmlContent(content)
3243
api.info(`Loaded HTML from ${path}`)
3344
} else {
34-
setHtmlContent(`<!-- Content of ${path} -->\n<pre>${content}</pre>`)
45+
setHtmlContent(`<!-- Content of ${escapeHtml(path)} -->\n<pre>${escapeHtml(content)}</pre>`)
3546
api.warn("File is not an HTML file, displaying as plain text.")
3647
}
3748
} catch (error: any) {
38-
setHtmlContent(`<!-- Error loading ${path} -->\n<pre>Error: ${error.message}</pre>`)
49+
setHtmlContent(`<!-- Error loading ${escapeHtml(path)} -->\n<pre>Error: ${escapeHtml(error.message)}</pre>`)
3950
api.error(`Failed to load file: ${error.message}`)
4051
}
4152
}

0 commit comments

Comments
 (0)