| | |
Checking for going up a Directory
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2004
Posts: 94
Reputation:
Solved Threads: 0
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:
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).
Forexample:
PHP Syntax (Toggle Plain Text)
directory/ sub1/ 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).
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.
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.
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 :-)
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
HI
I have benn working with a similiar script and i have solved this security issue doing a 'string replace' to the url:
It works like a charm.
I have benn working with a similiar script and i have solved this security issue doing a 'string replace' to the url:
php Syntax (Toggle Plain Text)
str_replace('..','',$requested_url);
It works like a charm.
•
•
Join Date: Jan 2009
Posts: 11
Reputation:
Solved Threads: 1
If you need to now something about security, read this books:
http://eu.wiley.com/WileyCDA/WileyTi...470857447.html
or
http://www.amazon.co.uk/Architects-G...2831903&sr=8-2
or
http://phpsec.org/projects/guide/
http://eu.wiley.com/WileyCDA/WileyTi...470857447.html
or
http://www.amazon.co.uk/Architects-G...2831903&sr=8-2
or
http://phpsec.org/projects/guide/
![]() |
Similar Threads
- Can JAVA create DOS directories? (Java)
- String Match Comparison (Shell Scripting)
- Google and PHP (Search Engine Optimization)
- 'can't read from drive c' problem (Storage)
Other Threads in the PHP Forum
- Previous Thread: problem
- Next Thread: HTML to PDF and print
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery network neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube







