tags:

views:

63

answers:

2
+1  Q: 

Php get Navigation

Hie

I use the GET method for navigation on one of my websites. The problem is that some dirty Einstein has create a link that calls another domain:

http://www.mywebsite.com?products=http%3A//www.dirtyeinstein.com?fishform.inc

Is there a script that i can use to block this kind of abuse.

Thank you.

+6  A: 

Hi,

simply check in your script if the requested page exists, like

// allowed get parameters for product
$whiteList = array(
   'tvs',
   'toys',
);

$menu = $_GET['products'];

if (! in_array($menu, $whiteList) {
   // forward to inde
} else {
  // forward to requested page
}
ArneRie
Whitelisting shouldn't even be needed, a simple `file_exists()` or `is_file()` should do the trick, though it may depend on your server's settings.
Duroth
@Duroth that's not true, the URI can be parsed to call a function or anything else in addition to purely include a file by it's complete name.
chelmertz
A: 

Are you using navigation like that?

http://www.mywebsite.com?products=book.php

If you are not redirecting anyone out, I mean if you don't use something like

http://www.mywebsite.com?products=http%3A//www.myanotherdomain.com

Then just check the string if it starts with "http"

May help: http://nl2.php.net/manual/en/function.substr.php

Ex:

$str = $_GET['products'];
if (strlen($str) > 4 && if (substr($str, 0, 4) == "http")
{
   echo "You dirty Einstein!! Get out!";
   return;
}
JCasso
You'd also need to check if it starts with ftp, rss, ssl or any other protocol, so this isn't really a solution
adam
@adam: I provided an example. Only an example...
JCasso
This is the wrong solution, the only safe way is to check against a whitelist, not to exclude based on rules.
Ben James
blacklisting never works in such scenarios. better use a whitelist of allowed pages (see ArneRie’s answer)
knittl
thanks guys, all your responses have been useful - keep coding!
Q_the_dreadlocked_ninja