0

I have a VPS. There is a web-application running on this VPS. A user can log into his account, create a project (the system automatically creates a folder for this project) and then, he can create and edit PHP files via the file manager within this folder/project. He edits those files via web-application's interface.

That is a sort of, online PHP editor, where people can create, edit and run PHP files, and then download them.

My VPS runs CentOS7 and Apache.

So the problem is, when the user tests his code and runs the files, that he has created, he can get access to the system in general and to similar folders of other users. So, this way, he can write and execute a command to list all files and directories outside his folder and see, what is happening there. Or can delete/copy/create/etc... files outside his folder. That should not be permitted. And that is a security flaw.

Also, user's scripts are ran by the "apache" user.

How is it possible to restrict his files from accessing anything, outside his directory/folder/project?

Edit

I basically need something like the shared hostings have... Where all of the users are on the same server, but cant access files of each other. On a shared hosting, you can use file manager to navigate through folders and edit php files, but those php files cant access the folders/accounts of other users on the shared hosting...

5
  • This seems like something that could be solved using users and permissions at the OS level. Assuming you are running linux on your VPS, If you created a linux user for each user of your application, and created a directory for each user, and only granted r/w permissions to the folder for that user, that would prevent users from accessing other users files.
    – mti2935
    Commented May 21, 2020 at 14:18
  • @mti2935 but the user edits the files, via web-application, which operates as an apache user. How can I change permission, only for the execution of the files this way? Or how should I make the files belong to one user, and be edited by apache user.... I am confused. I am not sure if I get this right....
    – Mee
    Commented May 21, 2020 at 14:37
  • @mti2935 I mean, you are probably right, but I just dont understand, how will the web-application interface be able to edit those file, considering, that it runs under an "apache" user (if the files themselves would belong to a different user)?.. Also, if that is read and write (on the user's folder, as you say), cant the user still be able to access other directories by reading them (I mean, that is a "read" permission)?
    – Mee
    Commented May 21, 2020 at 14:51
  • Sorry, I misunderstood your question. Now, after reading your comments, I don't think the solution that I described above would work.
    – mti2935
    Commented May 21, 2020 at 14:55
  • @mti2935 but shared hostings do it some how... There is a file manager, through which you can navigate through folders and edit the php files... I basically need the same kind of solution. Because their (of the shared hostings) file manager, also runs as a web-application, but the scripts within the folders cant access accounts/folders of the other users on the shared hosting...
    – Mee
    Commented May 21, 2020 at 15:02

1 Answer 1

0

You'll need to compartmentalise where the uploaded PHP code is uploaded, for example by spinning up a docker instance for every user to serve their pages (only) and leave the management interface to only edit the code.

I know you didn't ask, but I'll leave some extra advice (feel free to ignore): allowing users to upload executable code (PHP or otherwise) is an open door to full system compromise, if it hasn't happened yet. I can't stress enough how much of a security gaping hole it is.

7
  • Ok... Never used docker before, so I'll have to look deeper into it. Thank you. But can you be a little bit more specific (if possible) on how to implement this? Also, about your second paragraph... I am very concerned about security, so I can not ignore it. But let me understand better, what you mean... If you are saying, that uploading code is an open door to full system compromise, than how do shared hostings work? I mean, they also have the same problem, but they have found a way to solve it.... Didnt they? Also there are some other websites, that offer custom code execution...
    – Mee
    Commented May 21, 2020 at 16:52
  • shared hosting (considering you are talking about website hosting) works by raising quite a few more and harder barriers to separate different customers' code and data. at the most basic level, customers have no control over the host. if done poorly, the provider is absolutely under threat of compromise and customers accessing (and changing) data from each other.
    – Pedro
    Commented May 21, 2020 at 16:55
  • And what are they ("a few more and harder barriers")? Because I am launching a pretty complicated system and that is an important question to me... Can you at least suggest some links for me to explore? Technologies like SELinux or smth of this kind?
    – Mee
    Commented May 21, 2020 at 17:00
  • from simple things like having each tenant running under its own namespace/chroot/user id to containerisation (as mentioned) or virtual machines to segregate data and processes. this is a very vast field that has no simple solutions. you need to very carefully architect your solution based on your business requirements, security assessments and business risks.
    – Pedro
    Commented May 21, 2020 at 17:05
  • ok, thank you. But as I understand, Docker is similar to VM. And I have found just now the following link (superuser.com/questions/1520189/…), where a person says, that it is not about a separate VM, but more about a distinct user account on the system. What do you think about that? Is that basically what you are saying, or this guy suggests some other approach?
    – Mee
    Commented May 21, 2020 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .