Forum Moderators: coopster

Message Too Old, No Replies

Protecting Dyanmic Urls?

How would I go about protecting dynamic urls from crackers / hackers

         

jordonbedwell

7:02 am on Aug 16, 2004 (gmt 0)

10+ Year Member



I have a question and nobody seems to want to help me. I want to make dynamic urls for my site [example.com...]

however if i do it the easy way hackers can put in (http://www.example of a bad site.com) for example. (http://www.example.com/index.php?module=http://www.example of a bad site.com)

I dont want that to be possible so how would I go about preventing that on my server so I dont have problems with my Network Admin.

I dont want to have to have a list, I just want to beable to check for specifc characters like http:// and then have them removed and then it try and display the page but cause a 404 error or tell them NO DIRTY SITES. It would be much better to have the 404 but anwayz, how would i go about checking for and removing http:// from the query!?

Thank you ahead of time

Jordon Bedwell

[edited by: coopster at 3:19 pm (utc) on Aug. 16, 2004]
[edit reason] examplified urls as per TOS [webmasterworld.com] [/edit]

Lord Majestic

9:03 am on Aug 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not sure I fully understand what are you actually trying to achieve - ensure that no "dirty" requests are in your log file?

Netizen

11:25 am on Aug 16, 2004 (gmt 0)

10+ Year Member



How about just having a list of allowed modules and checking the $_GET['module'] against that?

For example:

$allowedModules=array('staff','friends','family');

if (in_array($_GET['module'],$allowedModules)) {
// do the code
} else {
// output error
}

henry0

11:39 am on Aug 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Moderators: please edit - I do not have the link to bag o'tricks - olny do I get the content!

This come from WebmasterWorld bag o'trick
Credit goes to: Andreas

Validating an URI [webmasterworld.com]

#############OTHER###########

Resolving a relative URI [webmasterworld.com]

[edited by: coopster at 3:26 pm (utc) on Aug. 16, 2004]
[edit reason] linked up Bag-O-Tricks for PHP II as per henry0 request [/edit]

Warboss Alex

11:45 am on Aug 16, 2004 (gmt 0)

10+ Year Member



If you want my opinion, your script shouldn't allow hackers to do what you describe.

Protect yourself with a switch statement, some thing like this.

switch($_GET['page']) {
case 'home':
$file = 'home.php';
break;

case 'forum':
$file = 'forum.php';
break;

default:
die('Have at you, vile hacker!');
break;

}

You wouldn't have to worry about http:// or anything else, since only by match the exact options in the switch statement will anything actually be done. Otherwise, the page just stops executing, giving the wannabe hacker a message.

Or, as has already been suggested, check the page parameter against an array, and then include it/process/whatever. :)

Alex ...