I was trying to tighten up security on some things today and I broke a whole application when I changed the permissions on the PHP CLI scripts to 711 (execute only for group and everyone, on Debian Linux).
Part of the issue was that they were called as php script
, which requires read permissions from my understanding. However, the main script does have a shebang, and calling the script directly failed if it was not readable, as Could not read input file. This seems to contradict this answer.
The main script includes/requires a lot of other scripts, and so I tried changing the main script to be 755 (read and execute). That script was able to start running, but failed immediately because it was not able to include any of the required files.
The only way to get it to work properly is 755 on every file, including all the files that contain database passwords and privileged secrets to access things that are only supposed to be accessible through the application (and while that alone may not be best practice, I don't believe an environment file would help, because a user would be able to read that, too).
It seems PHP will not run anything, directly or not, without read permission on files, which poses a big security problem here. Is there anyway to fix this, or is this not possible without compiling everything to binary somehow? Ideally, users could launch the program, and the program could do what it needs to, but the user should not be able to, say, cat the source code and read it. Seems like a catch-22 here...