473,473 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How would one protect against XSS - HTML injection?

118 New Member
Hi all,

I've noticed on my friend's site www.sheepeep.com/index.php?p=1 that is easy to manipulate with XSS, I don't mean it in a malicious way at all, just to give an idea as to what people can do.

As an example of such http://www.sheepeep.com/index.php?p=...E%3C/script%3E

With PHP (or any other language, come to that) how would one protect against that?

Sam
Nov 25 '07 #1
2 4347
pbmods
5,821 Recognized Expert Expert
Heya, Sam.

The easiest way to protect against HTML injection is to escape your input using htmlentities().

My recommendation would be to create a validation class and add an escapeHTML() method:

Expand|Select|Wrap|Line Numbers
  1. class Validation
  2. {
  3.     public static function escapeHTML( $str )
  4.     {
  5.         return htmlentities($str, ENT_COMPAT, 'UTF-8');
  6.  
  7.         // For PHP 5.2.3 or greater:
  8.         // return htmlentities($str, ENT_COMPAT, 'UTF-8', false);
  9.     }
  10. }
  11.  
Then, whenever you output anything the User input (including $_SERVER['PHP_SELF']):
Expand|Select|Wrap|Line Numbers
  1. echo Validation::escapeHTML($_GET['value']);
  2. echo Validation::escapeHTML($_SERVER['PHP_SELF']);
  3.  
etc.
Nov 26 '07 #2
coffear
20 New Member
what pbmods says is 100% correct another thing that should be done is proper validation of user input. If for example you ask someone their age then ensure they provide you with an int.
Nov 26 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Doc | last post by:
I keep reading about various websites being hacked into and wonder, how is this done? Not for any nefarious reasons, but to take measures to protect mine. Apparently this has been done to some high...
15
by: Fady Anwar | last post by:
Hi while browsing the net i noticed that there is sites publishing some software that claim that it can decompile .net applications i didn't bleave it in fact but after trying it i was surprised...
5
by: Garry Jones | last post by:
I need to create a page with a password where I show photos. How do I stop people from accessing the jpgs directly without going through the password function. I am using Windows XP and have a...
2
sashi
by: sashi | last post by:
hi everyone, Below is a simple function that will give you some protection against an SQL Injection attempt. what is SQL injection? SQL injection is a security vulnerability that occurs in...
0
by: Bank of America | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
16
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I protect my javascript code? ----------------------------------------------------------------------- ...
4
by: JBiggsCC | last post by:
I have a very simple login page which takes an ID number via a HTML form GET. What is easiest way to check that ID number against an Access DB to see if it exists? I want to redirect with the...
1
by: yawnmoth | last post by:
Say I have the following in a PHP script of mine: $sr=ldap_search($ds, "", "(& (sn=$_GET) (givenName= $_GET*))"); If $_GET contains a ), an attacker could escape out of the first part of the...
4
by: kkshansid | last post by:
i have a database as table name school field name location eg in location column data green school,tagore garden,chink road,jammu i want to make search on location such that when user enter ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.