XSS Vulnerability in Jquery.append (), jquery.html ()

Source: Internet
Author: User

When you use the Jquery.append (), jquery.html () method, it is executed if the content contains <script> scripts without any processing.

The simple example code is as follows:

1 var xssstr = ' <script>console.log (1) </script> '; 2 $ (' #test '). HTML (XSSSTR);

The console prints "1".

The same situation also exists in jquery.append (), since jquery.html () is also called Jquery.append ().

Since execution <script> scripting are present, there is a risk of XSS.

The workaround is also simple and will need to be escaped as a string of arguments:

var xssescapestr = Xssstr.replace (/</g, ' &lt; '). Replace (/>/g, ' &gt; ');

This output on the page is simply a section of a <script> string that is not executed.

But this is not a jquery bug, look at the jquery source code, Jquery.append () <script> processing seems to be intentional.

The Jquery.append () method is designed with the intention of allowing scripts to be executed, so jquery does not recommend using such things as URLs, cookies, input inputs, etc. as append () parameters.

If there is a need, then escape it.

XSS Vulnerability in Jquery.append (), jquery.html ()

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.