Board index   FAQ   Search  
Register  Login
Board index php forum :: PHP and MySQL Security PHP & MySQL Security

XSS Problem

Security issues related to php and mysql usage. How to make your code secure? Security measures and configurations? It's all in here!

Moderators: macek, egami, gesf

XSS Problem

Postby LORDTEK » Thu Jul 28, 2011 3:42 am

Hello there,

The security guys said me that "Encode ', ", -, +, (, ), &, %, #, <, > sings when you get datas."

But I think different... The user can enter every bad content without SQL Injection. Then the system would encode them when pulling the datas to show the user.

What do you think?
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jul 28, 2011 3:33 am

Re: XSS Problem

Postby TheProdigyGuy » Sat Jan 21, 2012 3:36 pm

Of course it depends on situation(in ex: of vulnerability)
But i think if you encode that characters: in ex: htmlentities($data)
& will become &amp
< will become as &lt; > &gt; etc.
It depends on you how your script pulls it back to user.(if it is htmlentiti'ed) it is safe from XSS and user browser will not render it as it displayed on user browser:
In ex:
Code: Select all
echo $data;

It is safe for now: &lt;script&gt;alert(document.cookie);&lt;/script&gt;

WIth SQL iinjections:
Here is my custom function:D

Code: Select all
define ("INTERNAL","antisqlinjectionmodule");
function sanitize(&$string,$die=1)

if (empty($string))@header("Location: index.php");
foreach ($blacklisted as $black)
{if ($die==0){
if(strlen(str_ireplace($black,'',$string)) !==strlen($dummy) || strlen($string)==0)@header("Location: " . "/index.php");
$string=str_ireplace($black,'',$string); //sanitization

pass your string to this function by refenrence and that all it will sanitize it to you)
And it is a bit safer than using preg_* functions (theris a minimal chance to bypass that filtering)
Also use mysql_real_escape_string() when you are going to deal with MYSQL QUERIES.
If you expect to get int force it to be int
This is a just example.
Code: Select all
echo $maycomefromhacker;

Output: -999 (We prevented that malicious request using this way)
I would like to say again it depends on situation how to handle and secure your application.
Never Trust To CLient Side! Thats all)
New php-forum User
New php-forum User
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Return to PHP & MySQL Security

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.