Using jQuery HTML decoding using textarea

Following my last question ...

This code can be used if an attacker has access to encodedText :

 return $('<div/>').html(encodedText).text(); 

eg. $("<div/>").html('<img src="X" onerror="alert(\'hi\');" />').text() displays a warning.

This answer recommends using textarea instead to avoid the XSS vulnerability:

 return $('<textarea/>').html(encodedText).text(); 

This allowed us to safely handle the previous exploit.

However, this answer indicates that when using textarea , XSS vulnerabilities still exist:

I suggest using a safer, more optimized function

do not use jQuery.html (). text () to decode html objects as it is unsafe because user input should never have access to the DOM

My question is: is there a way in any browser to use $('<textarea/>').html(encodedText); to run XSS, assuming the attacker has access to encodedText ?

+6
source share
1 answer

I would not risk being honest, it would be much safer if you processed everything that is necessary for encryption or the unencrypted server side.

0
source

All Articles