im relatively new to php and was hoping you could help me understand why you should sanitize html when echoed, especially if the data is from a cookie ..
ie instead of
<h3>Hello, <?php echo $_COOKIE['user']; ?>!</h3>
you have to do
<h3>Hello, <?php echo htmlspecialchars($_COOKIE['user']); ?>!</h3>
This is what I understand.
cookies are stored on the client side, therefore, this is a security risk, since the data in them can be changed / modified by malicious users (lol @evil).
but since the cookie is stored on the client side, this means that the client can only change his own cookie, which means that if he adds some malicious code to $ _COOKIE ['user'], when the cookie is launched, the malicious code will be shown to only one user (who first changed the cookie) and no one else !? so what's the problem?
source share