Replace innerHTML() with createElement() and appendChild() for security.

This commit is contained in:
ubertao 2018-09-20 08:49:17 +08:00
parent 40725aa2a2
commit cad7debc5b

View File

@ -157,10 +157,15 @@ Module.register("compliments", {
getDom: function() {
var complimentText = this.randomCompliment();
var compliment = document.createTextNode(complimentText);
var wrapper = document.createElement("div");
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
wrapper.innerHTML = complimentText.replace(/\n/g, '<br>');
complimentText.split("\n").forEach(function(line, index) {
if (index > 0) {
wrapper.appendChild(document.createElement("br"));
}
wrapper.appendChild(document.createTextNode(line));
});
return wrapper;
},