fix: prevent XSS via innerHTML injection in link edit prompt

Replace innerHTML with DOM API calls in inputPrompt.ts. The oldValue
parameter (sourced from a link's href attribute in the TipTap editor)
was interpolated directly into an HTML string, allowing stored XSS if
an attacker crafted a malicious href. Using document.createElement and
setting .value as a property ensures the value is never parsed as HTML.
This commit is contained in:
kolaente
2026-02-25 11:11:36 +01:00
parent a42b4f37bd
commit 111ac9c726

View File

@@ -18,7 +18,14 @@ export default function inputPrompt(pos: ClientRect, oldValue: string = ''): Pro
popupElement.style.borderRadius = '4px'
popupElement.style.padding = '8px'
popupElement.style.boxShadow = 'var(--shadow-md)'
popupElement.innerHTML = `<div><input class="input" placeholder="URL" id="${id}" value="${oldValue}"/></div>`
const wrapperDiv = document.createElement('div')
const inputElement = document.createElement('input')
inputElement.className = 'input'
inputElement.placeholder = 'URL'
inputElement.id = id
inputElement.value = oldValue
wrapperDiv.appendChild(inputElement)
popupElement.appendChild(wrapperDiv)
document.body.appendChild(popupElement)
// Create a local mutable copy of the position for scroll tracking