(A) Better not to create files or folders with user-supplied names. If you do not validate enough, you can have trouble. Instead create files and folders with randomly generated names like fg3754jk3h and store the username and this file or folder name in a table named, say, user_objects. This will ensure that whatever the user may type, the command going to the shell will contain values from a specific set only and no mischief can be done.
(B) The same applies to commands executed based on an operation that the user chooses. Better not to allow any part of the user's input to go to the command that you will execute. Instead, keep a fixed set of commands and based on what the user has input, and run those only.
For example, (A) Keep a table named, say, userobjects with values like: username|chosenname |actualname|fileordir --------|--------------|-----------|----------- jdoe |trekphotos |m5fg767h67 |D jdoe |notes.txt |nm4b6jh756 |F tim1997 |imp_ folder |45jkh64j56 |D
and always use the actual_name in the filesystem operations rather than the user supplied names.
You need to login to post a comment.