Skip to content

Commit a2daa15

Browse files
committed
fix: Correct HTML escaping in useClipboard to prevent XSS
1 parent 2099703 commit a2daa15

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

webview-ui/src/components/ui/hooks/useClipboard.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ export function useClipboard({ timeout = 2000 }: UseClipboardProps = {}) {
2121
try {
2222
if (navigator.clipboard?.write && images.length > 0) {
2323
const limitedImages = images.slice(0, MAX_IMAGES_PER_MESSAGE)
24-
const escapedText = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"')
24+
const escapedText = text
25+
.replace(/&/g, "&amp;")
26+
.replace(/</g, "&lt;")
27+
.replace(/>/g, "&gt;")
28+
.replace(/"/g, "&quot;")
2529
const imgTags = limitedImages.map((base64) => `<img src="${base64}" />`).join("")
2630
const html = `<div><p>${escapedText}</p>${imgTags}</div>`
2731
const htmlBlob = new Blob([html], { type: "text/html" })

0 commit comments

Comments
 (0)