Is jQuery .text() method XSS safe?

后端 未结 6 1984
陌清茗
陌清茗 2020-12-24 00:48

I have unescaped data from users.

So is it safe to use like this:

var data = \'a&f\"#\'; // example data from ajax resp         


        
6条回答
  •  借酒劲吻你
    2020-12-24 01:07

    Unlike the .html() method, .text() can be used in both XML and HTML documents. The result of the .text() method is a string containing the combined text of all matched elements. (Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.)

    .text(data) would strip the away and leave you with a&f#

提交回复
热议问题