Audit a dynamic HTML sink
The name can be controlled by a user, but the code inserts it into an HTML parser.
function showName(container, name) {
container.innerHTML = `<p>${name}</p>`;
}
If the intended output is plain text, use a text-only DOM API rather than an HTML sink.
How should the application display an untrusted name as plain text?
The browser renders the value as text instead of parsing it as markup.
Ad hoc filtering is easy to bypass and keeps using an HTML parsing sink.
Encoding does not make the decoded value safe HTML.
Visibility does not prevent the browser from parsing inserted markup.
Why it matters: Treating untrusted text as markup can let it create executable elements in the page.