Closed
Bug 1413667
Opened 9 years ago
Closed 9 years ago
Encode HTML content is executed as unencoded format when it is assigned to element.innerHTML
Categories
(Core :: DOM: Core & HTML, defect, P2)
Tracking
()
RESOLVED
INVALID
People
(Reporter: dyang, Unassigned)
Details
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36
Steps to reproduce:
When encoded html content is assigned to element.innerHTML, the encoded content will be rendered and executed as unencoded context.
Here is an example
<!DOCTYPE html>
<html>
<body>
<div>
<p id="demo" onclick="myFunction()">Click Here to get value of the input field</p>
</div>
<input id="test" value ="S"><img src=x onerror=confirm(2)>"></input>
<script>
function myFunction() {
document.getElementById("demo").innerHTML ="</p>"+document.getElementById("test").value;
}
</script>
</body>
</html>
Once you execute myFunction(), the html encoded value of the test input field is assign to innerHTML attribute to element demo and then, the browser renders the innnerHTML as unencoded html context. As a consequence, the JavaScript functions is executed as well.
Expected results:
JavaScript function should be suppressed when encoded HTML context is passed to innerHTML.
Updated•9 years ago
|
Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Summary: Encode HTML content is executed as unencoded format it is assigned to element.innerHTML → Encode HTML content is executed as unencoded format when it is assigned to element.innerHTML
Comment 1•9 years ago
|
||
Anne (sorry, two in one day): is what Gecko is doing here to spec?
Flags: needinfo?(annevk)
Priority: -- → P2
Comment 2•9 years ago
|
||
Yeah, I don't understand the expected results. The first time the HTML parser runs and builds up that attribute value the entities will have been decoded. If you then pass the attribute value to innerHTML it will be parsed, as you would expect from innerHTML.
Status: UNCONFIRMED → RESOLVED
Closed: 9 years ago
Flags: needinfo?(annevk)
Resolution: --- → INVALID
Hi Anne,
Thanks for your reply and clarification. But I have one more questions regarding the following instance.
For example,
1. A ajax request get the following response, HTML encoded context ><img src=x onerror=confirm(2)>
2. The parent page triggering the ajax request is consuming the ajax response in the following way
document.getElementById("demo").innerHTML = req.responseText;
*NOTE* req.responseText is the response of the ajax request
3. Under this situation, the ajax response is not parsed even it is assigned to innerHTML
My questions is what are the cause for the difference behavior regarding this situation and the original instance for the bug.
Thanks
Daniel
Comment 4•8 years ago
|
||
Well, the HTML is not parsed twice.
Thanks Anne. That helps a lot for understanding it. Basically, the html encoded value will be decoded once when the html parser parsed it for rendering/display it. Then the decoded value will be executed when it is assign to innderHTML.
You need to log in
before you can comment on or make changes to this bug.
Description
•