Jump to content

XSS (Cross-site Scripting) and Javascript Injection?


random1

Recommended Posts

Hi All,

 

I've got the following code for XSS and JS Injection filtering:

 

/**

* Validator::filterJavascriptInjection()

* Filters a string to prevent Javascript Injection attacks.

* @param mixed $data

* @return $outputdata

*/

function filterJavascriptInjection($data)

{

// Source: http://www.avengex.com/tutorials/115/Preventing_XSS/

return $outputdata = preg_replace("#<script#is","<//script",$data);

}

 

/**

* Validator::filterJavascriptInjection()

* Filters a string to prevent Cross-site Scripting (XSS) attacks.

* @param mixed $data

* @return $outputdata

*/

function filterXSS($data)

{

// Source: http://www.avengex.com/tutorials/103/Simple_but_effective_user_input_securing/

 

$outputdata = htmlspecialchars($data);

//$input will now contain the ascii equivalents to all html chars like <

$outputdata = addslashes($outputdata);

//this will add slashes to negate the effect of an sql injection

$outputdata = stripslashes($outputdata);

//this now removes all the funny slashes. BUT the code is still safe for a browser

return $outputdata;

}

 

This doesn't seem to be working properly. Also how do I protect my app against SQL Injection?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.