Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSS attack in title-tag

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?

like image 564
Bv202 Avatar asked Jan 19 '23 02:01

Bv202


1 Answers

Should I escape this user input using htmlspecialchars?

Yes. Location doesn't matter. All user input should be escaped.

References:

  • What are the best practices for avoiding xss attacks in a PHP site
  • What's the best method for sanitizing user input with PHP?
  • https://stackoverflow.com/questions/tagged/php+xss
like image 134
Mike B Avatar answered Jan 24 '23 22:01

Mike B