openterm icon indicating copy to clipboard operation
openterm copied to clipboard

Limit commands to Documents folder

Open louisdh opened this issue 7 years ago • 4 comments

Currently it's possible to "escape" the documents folder and peek at the system hierarchy (e.g. cd / will bring you to the root of iOS). Apple may find this reason to remove the app from the App Store. Therefore, I was wondering if there's any way to easily limit all commands to a certain folder scope.

louisdh avatar Jan 10 '18 19:01 louisdh

@holzschu Do you have any ideas or thoughts about this?

louisdh avatar Jan 10 '18 19:01 louisdh

Another thing we might need to limit (to please Apple) is the paths that are displayed in command results. For example, pwd will currently print the full path (/private/var/mobile/...). It might be necessary to treat the app as the root of the file system. So pwd would print /Documents if you're in the documents folder.

louisdh avatar Jan 10 '18 19:01 louisdh

I have no idea on how to do the first one. There are already strong protections in place: you can cd /, but you can't list or enter any of the directories under it. Likewise, you can cd ~/.. but not list its content.

For the second, an automatic replacement on the string returned by process(), scanning all occurences of the string that is the result of getenv($HOME) and replacing them with ~ would be a simple solution. Using stringByReplacingOccurrencesOfString. It would actually improve readability.

holzschu avatar Jan 10 '18 20:01 holzschu

Going back to the first question: it would be easy to place a restriction in cd, to verify that the directory you're going to has either $HOME or $CLOUDHOME as a prefix, because cd is a simple command (and the entire source is in ios_system). It would be harder to place the same restriction on all commands, because we don't know in advance if an argument is a directory or just text. Also, I'm not sure I can detect a user typing cd $HOME/../.., but that is starting to be sophisticated.

holzschu avatar Jan 11 '18 07:01 holzschu