Skip to content

Commit 60be0f7

Browse files
DreamLab-AI Mega-Sprintruvnet
andcommitted
security: sanitize HTML in popup trusted-origins list to prevent XSS
Replace innerHTML template literal interpolation with DOM API methods (createElement, textContent, appendChild) when rendering the trusted origins list. The previous code interpolated the origin string directly into HTML, allowing an attacker who injects a malicious string into the trusted origins (e.g. <img src=x onerror="...">) to execute arbitrary JavaScript in the popup's privileged extension context, potentially exfiltrating the user's private key. Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent b83f414 commit 60be0f7

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

popup/popup.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,28 @@ async function loadTrustedSites() {
247247
return;
248248
}
249249

250-
listEl.innerHTML = origins
251-
.sort()
252-
.map(origin => `
253-
<div class="trusted-item">
254-
<span class="trusted-origin">${origin}</span>
255-
<button class="btn-remove" data-origin="${origin}">Remove</button>
256-
</div>
257-
`)
258-
.join('');
259-
260-
// Add remove button handlers
261-
listEl.querySelectorAll('.btn-remove').forEach(btn => {
250+
listEl.innerHTML = '';
251+
origins.sort().forEach(origin => {
252+
const div = document.createElement('div');
253+
div.className = 'trusted-item';
254+
255+
const span = document.createElement('span');
256+
span.className = 'trusted-origin';
257+
span.textContent = origin;
258+
259+
const btn = document.createElement('button');
260+
btn.className = 'btn-remove';
261+
btn.dataset.origin = origin;
262+
btn.textContent = 'Remove';
263+
262264
btn.addEventListener('click', async () => {
263-
const origin = btn.dataset.origin;
264265
await removeTrustedSite(origin);
265266
await loadTrustedSites(); // Reload
266267
});
268+
269+
div.appendChild(span);
270+
div.appendChild(btn);
271+
listEl.appendChild(div);
267272
});
268273
}
269274

0 commit comments

Comments
 (0)