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, '&')
 .replace(/\</g, '<')
 .replace(/\>/g, '>')
 .replace(/\"/g, '"')
 .replace(/\'/g, ''')
 .replace(/\`/g, '`')
 .replace(/\(/g, '(')
 .replace(/\)/g, ')')
 .replace(/\{/g, '{')
 .replace(/\}/g, '}')
 .replace(/\//g, '/');
}
Is there some safer way to do this? Or is this the only way? I would be grateful if someone could tell me.
