I am currently tightening security on my website, and I am trying to ensure that every value passed from PHP to HTML is correctly encoded.
Assigning values to a template will currently encode it, however some parts of the website are outdated and do not use templates.
I changed the functions that I use for HTML output to encode all the values. This is great for covering all old pages, but now it causes double encoding of template values.
I changed the encoding function that I use:
$textToEncode = htmlspecialchars_decode($szText); return htmlspecialchars($textToEncode, ENT_COMPAT, 'ISO-8859-1');
It worked out of what I see. By decrypting it first, it always guarantees that it will not encode twice, and I cannot think of any reason why decoding an unencoded string will cause problems. This is a good decision?
source share