How does using htmlspecialchars()
stop XSS attacks?
Based on everything I researched, using this function allows you to render user input. According to my understanding, this means that if a user entered some html code into a form (or other input source), then you'll actually execute that code instead of simply displaying it. Again, how does this stop an attack?
If you look at the difference between using the function and not using it, clicking View Source gives you the following (on a call to `exec("dir") on a windows machine): Using htmlspecialchars() Not using it
As you can see, the difference is that <DIR>
turned into <DIR>
after using the function. So all it's doing is escaping all HTML characters? So it doesn't actually render anything? Would love a comprehensive answer to this.