Element.innerhtml the security issues involved

Source: Internet
Author: User

As we all know, the innerHTML attribute was introduced in IE4, and many browsers also supported it for a long time, and the arrival of HTML5 made it standardized.

innerHTML's explanation on the MDN is:

The property Element.innerHTML Sets or gets the HTML syntax describing the element ' s descendants.

That is, you can set and get the descendants of an element that is represented by HTML syntax, but not much, but settings can raise security issues:

Element.innerhtml= "<script>console.log (' hello ') </script>";

That is, inserting the script into the descendant of the element, which may "leave a hand" for an XSS-like attack, like the example above does not actually execute the embedded JS script, and the MDN also states "HTML5 specifies that a <script> tag inserted via innerHTML should Not execute. ".

Therefore, the industry does not recommend inserting text with innerHTML and replacing it with node.textcontent.

Element.innerhtml the security issues involved

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.