Allowing PHP to change file and directory ownership and permission

10,285

Well, it certainly sounds like a dangerous idea to begin with and I'd prefer sitting down and thinking through the whole strategy of what is trying to be achieved.

The danger is privilege escalation of an executable script which a remote user could modify or upload, of course. Full chown/chmod in a web app is equivalent to just pasting your root password on the page.

What is it exactly which needs to happen?

If the chown needs to happen for some reason but not to root (we hope) then the functionality should be wrapped. I would take the user requests and queue them, then have a separate process (could be shell, php, perl, anything) running as root by cron check this queue, check to see if the request fit the allowed parameters, and make the changes.

Share:
10,285
Namrata Das
Author by

Namrata Das

Read my blog! Specialized in: REST (The hypermedia kind!) Javascript & Typescript React & Node I am looking for interesting contracts

Updated on August 21, 2022

Comments

  • Namrata Das
    Namrata Das over 1 year

    I'd like to build a simple web app, which manages some directory on a server. I want to give people the option to use chown and chmod.

    What is the safest way to give PHP this permission? The quickest thing is just running Apache and PHP as root, but that doesn't seem to be a smart idea.

    One other thing I thought of, was creating a separate script which has setuid root..

    Thanks!