I have a form where users can fill in a news article. This contains a title and body.
For each page to have a unique title, I'm using the user input (title) in the <title>
-tags:
<title>$userinput</title>
I'm wondering - is it possible for the user to perform an XSS-attack this way? Should I escape this user input using htmlspecialchars
?
The same also applies to <meta>
-tags. I'm using user input for the description:
<meta name="description" content="$userinput" />
Can a user perform XSS-attacks in <title>
and <meta>
-tags?
Should I escape this user input using htmlspecialchars?
Yes. Location doesn't matter. All user input should be escaped.
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With