views:

127

answers:

3

One guy tried to exploit it using this script

http://www.searchr.us/web-search.phtml?search=%22%3E%3Cscript%3Ealert%28String.fromCharCode%2872%29+String.fromCharCode%28105%29%29;%3C/script%3E

How do i stop it ?

And he also said that it is vulnerable to XSS and LPI...Please help me stop it.

Thanking You,

+6  A: 

You need to HTML-encode all user-entered data that you output, including the user's search string.

To be safe, HTML-encode all values that are not explicitly meant to be HTML code.

RedFilter
A: 

Seeing as how that is a search query string, I'm guessing you're pulling the value directly from the query string and re-displaying it to the user?

Something along the lines of "Your search of 'something' returned 0 results"?

You need to encode any user entered data before displaying it.

Brandon
Yah thats exactly what I'm doing !! So is it safe ?? And how to counter it ?
5416339
No, it's not safe. Anytime you're displaying a value that is user entered, you need to encode it. You can't trust them to enter in harmless data. See Novikovs answer for an easy way to fix your problem.
Brandon
+3  A: 

The quick solution is to:

<?php echo htmlspecialchars($blah); ?>

instead of

<?php echo $blah; ?>

The long solution is to read a book on web site security.

Novikov
I did that..but still it is vulnerable right ?
5416339