Cross-Site Scripting

Your rating: None Average: 5 (1 vote)

One of the most frequent vulnerabilities in modern PHP applications is cross-site scripting(XSS). As with most security concerns, proper data filtering can practically eliminate the risk of cross-site scripting. However, in this case, the real risk is when foreign data is used in your output and thereby potentially displayed to other users.This is fairly typical for applications such as Webmail, forums, wikis, and even 404 handlers.

The best defense of cross-site scripting is to use functions such as htmlspecialchars() or htmlentities() on data prior to displaying it. Of these two functions, htmlentities() is better for this purpose because it is more inclusive in
terms of what entities it encodes.

This is a blacklist approach, but because there are a finite number of well documented characters that have a special meaning within HTML, it is actually a pretty
strong approach in this case. Of course, it is still best to be strict in your data filtering. If you are expecting a person’s first name, should valid JavaScript make it through your data filtering? Hopefully you agree that this is not desirable.

Other functions such a strip_tags() (that attempts to remove all valid HTML and PHP) can also help in preventing cross-site scripting vulnerabilities, but this is an example
of a somewhat weaker blacklist approach than what htmlentities() provides.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

I love work environment which is:

Informal yet professional
Demanding yet rewarding
Challenging yet inspiring
Mediocrity is not an option
Having fun is serious business
Making mistakes is human
Forgiveness is Company Policy

Travelling Sucks