Skip to content

Commit 7ea4c7c

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

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

examples/qr-server/widget.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,17 @@
4141
const content = msg.params?.content;
4242
const img = content?.find(c => c.type === 'image');
4343
if (img) {
44-
document.getElementById('qr').innerHTML =
45-
`<img src="data:${img.mimeType};base64,${img.data}" alt="QR Code"/>`;
44+
const qrDiv = document.getElementById('qr');
45+
qrDiv.innerHTML = ''; // clear previous content
46+
47+
// Optionally allowlist mimetypes
48+
const allowedTypes = ['image/png', 'image/jpeg', 'image/gif'];
49+
const mimeType = allowedTypes.includes(img.mimeType) ? img.mimeType : 'image/png';
50+
51+
const image = document.createElement('img');
52+
image.src = `data:${mimeType};base64,${img.data}`;
53+
image.alt = "QR Code";
54+
qrDiv.appendChild(image);
4655

4756
// Report size to host
4857
window.parent.postMessage({

0 commit comments

Comments
 (0)