1

I'm writing a plugin for a CMS that will manipulate images (resize them). How can I ensure that only certain directories are ok?

I want the user to be able to define what directory they want the script to look in (and find all images).

I know I could ask for $_POST['sub_directory_to_look_in'] and glob('galleries/' . $_POST['sub_directory_to_look_in'] . '/*.jpg'); and ensure that $_POST['sub_directory_to_look_in'] doesn't have '../', but are there any security issues with doing this?

I've looked into basedir function but not sure if that will help

slash197
  • 9,028
  • 6
  • 41
  • 70

1 Answers1

0

To be safe, do the mapping between a user and its content using an uniquely identifying key (such as a salted hash of a user id) related somehow to the destination directory.

This way your query parameters shall not even contain information about your infrastructure but only information about the data to be transferred including the kind of target destination (not where it should be located, but where it should be relatively located for instance).

P.S. : You could use realpath to resolve symbolic links of a given valid path if browsable by the system user http://www.php.net/manual/en/function.realpath.php

This question might be related to Sanitize file path in PHP

Community
  • 1
  • 1
Th. Ma.
  • 9,432
  • 5
  • 31
  • 46