Following up on my last question...
This code can be exploited if an attacker has access to encodedText
:
return $('<div/>').html(encodedText).text();
e.g. $("<div/>").html('<img src="X" onerror="alert(\'hi\');" />').text()
displays an alert.
This answer recommends using a textarea
instead to avoid XSS vulnerability:
return $('<textarea/>').html(encodedText).text();
This was able to handle the previous exploit safely.
However, this answer indicates that there are still XSS vulnerabilities when using textarea
:
I suggest using a safer, more optimized function
don't use jQuery.html().text() to decode html entities as it's unsafe because user input should never have access to the DOM
My question is: Is there a way in any browser to exploit $('<textarea/>').html(encodedText);
to run XSS assuming attacker has access to encodedText
?