Checking for going up a Directory

Reply

Join Date: Mar 2004
Posts: 94
Reputation: Ragnarok is an unknown quantity at this point 
Solved Threads: 0
Ragnarok Ragnarok is offline Offline
Junior Poster in Training

Checking for going up a Directory

 
0
  #1
May 28th, 2004
I have been working on flatfile and directory system in PHP and not that I have got the script working I want to make it more secure. What I have is one directory with sub-directorys insided them and insided the subdirectorys are about 20 files each.

Forexample:

  1. directory/
  2. sub1/
  3. sub2/

When the script is working out what directory to open it works like this:

directory/$subNum/$filename

What I want to be able to do is stop people from going down directorys (../../filename) because this could be a big security risk. What I want to know is if there is a better way than !preg_match('../',$filename).
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,036
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Checking for going up a Directory

 
0
  #2
Jun 5th, 2004
I would think that would suffice. Does anyone here think that it would still be a security risk? The only thing I could see still being a problem is that someone could still manually enter the directory URL into their browser for access to the files.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 118
Reputation: Arizona Web is an unknown quantity at this point 
Solved Threads: 2
Arizona Web's Avatar
Arizona Web Arizona Web is offline Offline
Junior Poster

Re: Checking for going up a Directory

 
0
  #3
Jun 6th, 2004
Don't do that. Put the flat file above the web root. I'm not sure of your hosting environment, but most linux set ups allow you to access files above the web root with your scripts.

If there is no way to do that in your situation, then yes, block them with your script since it is already written. But also, change the file perms so only your scripts can access it, and use .htaccess to block access to those files from everybody except your scripts and/or the owner of the files.
Need a website designer? arizona web design : phoenix web design : MCP Media intelligent web design and web development solutions. MCP Media is owned and operated by Chris Hooley - who happens to be a real nerd... on purpose :-)
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 94
Reputation: Ragnarok is an unknown quantity at this point 
Solved Threads: 0
Ragnarok Ragnarok is offline Offline
Junior Poster in Training

Re: Checking for going up a Directory

 
0
  #4
Jun 6th, 2004
there is a slight problem with that fact that I am making it an open source script
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: ciberwing is an unknown quantity at this point 
Solved Threads: 0
ciberwing ciberwing is offline Offline
Newbie Poster

Re: Checking for going up a Directory

 
-1
  #5
Jan 22nd, 2009
HI
I have benn working with a similiar script and i have solved this security issue doing a 'string replace' to the url:

  1. str_replace('..','',$requested_url);

It works like a charm.

Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 11
Reputation: Yayo_SK is an unknown quantity at this point 
Solved Threads: 1
Yayo_SK Yayo_SK is offline Offline
Newbie Poster

Re: Checking for going up a Directory

 
0
  #6
Jan 24th, 2009
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC