Jump to content
MakeWebGames

mod_rewrite: Prevent XSS?


Amanda<3

Recommended Posts

Well, i know how to do it the old way, url by url by url. I was wondering if anyone could suggest a more shortcut approach to keep XSS out of the url using mod_rewrite. Also, i currently have a rewrite function that rewrites my URL's for me:

function rewriteURI($URI,$argSeperator="/"){	    $origURI = $URI;		    $requestURI = preg_replace("/^\/?([A-Z0-9_-]+)\.php(.+)?$/i","$1", $origURI);			$requestURI = '/'.$requestURI.'/';			    $params = explode("?",$origURI);                $args = explode("&", $params[1]);				$queryString = '';                    foreach($args as $arg){					    $parts = explode("=", $arg);						    $queryString .= $parts[1].$argSeperator;											   }				     				    $rewrittenURI = preg_replace("/^(.*)\\$argSeperator$/i","$1", $queryString);					$rewrittenURI = $requestURI.$rewrittenURI;					$rewrittenURI = $rewrittenURI;										    return $rewrittenURI;}

 

Basically that is what i'm using to turn this: page.php?arg1=foo&arg2=bar, into /page/foo/bar. Is this a good method?

Link to comment
Share on other sites

Well, sure you could prevent ANY kind of tag / scripts and therefore you would prevent XSS. You can find pre-made PHP library which will check if your parameters (GET, POST, COOKIES) are potentially harmful or not.

A good example of what you could use:

http://phpids.org/

demo under:

http://demo.phpids.org/

This lib prevent XSS as well as SQL injection.

However, honestly, it doesn't completely replace a well secured code.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...