0

I created a web chat using socket.io, it is end-to-end encrypted chat. I am encrypting data using AES-GCM. The data is encrypted on the client side and decrypted on the other client side. And so I have a question, how to safely escape html characters? This cannot be done on the server because the server does not have a secret. The only solution is to escape the html characters before displaying the text on the client side where the secret is, but is it safe?

let decryptedData = decrypt(message, iv);
$(`<div class='message_user'>${valitadeMessage(decryptedData)}</div>`).appendTo(".messages_container");


function valitadeMessage(message){
 return message.replace(/\&/g, '&amp;')
 .replace(/\</g, '&lt;')
 .replace(/\>/g, '&gt;')
 .replace(/\"/g, '&quot;')
 .replace(/\'/g, '&#x27')
 .replace(/\`/g, '&#96;')
 .replace(/\(/g, '&#40;')
 .replace(/\)/g, '&#41;')
 .replace(/\{/g, '&#123;')
 .replace(/\}/g, '&#125;')
 .replace(/\//g, '&#x2F');
}

Is there some safer way to do this? Or is this the only way? I would be grateful if someone could tell me.

Sergei Hronov
  • 29
  • 1
  • 6

0 Answers0