Skip to content

ExecutableFinder generates wrong Path #19913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tschechniker opened this issue Sep 12, 2016 · 5 comments
Closed

ExecutableFinder generates wrong Path #19913

tschechniker opened this issue Sep 12, 2016 · 5 comments

Comments

@tschechniker
Copy link

Hi,

the executableFinder is generating a wrong path if you have open_basedir in action.

For example you have installed java in /usr/bin/java and your open_basedir is set to /usr/bin/ the ExecutableFinder will return /usr/bin//java. The problem is that the open_basedir restrictions now say your are not allowed to access /usr/bin//java because of the two slashes.

See: https://github.com/symfony/process/blob/master/ExecutableFinder.php#L82

/**
* $dir = /usr/bin/
* $name = java
* $suffix = '' (empty)
*/
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {

Best regards

Tobi

@xabbuh
Copy link
Member

xabbuh commented Sep 28, 2016

I can confirm the issue.

Status: Reviewed

@xabbuh
Copy link
Member

xabbuh commented Sep 28, 2016

@tschechniker Can you please check if /usr/bin/java in your case is a symlink to a file outside of your open_basedir? That's actually the only case where I was really able to reproduce your issue. Though I am not sure if we can actually avoid that then.

@xabbuh
Copy link
Member

xabbuh commented Sep 28, 2016

see #20077

fabpot added a commit that referenced this issue Sep 29, 2016
…es (xabbuh)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #20077).

Discussion
----------

[Process] silent file operation to avoid open basedir issues

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19913
| License       | MIT
| Doc PR        |

Using file operations on a symlink that points to a file outside the directories being allowed by the open_basedir setting leads to PHP warnings being raised.

Commits
-------

30c9b1e silent file operation to avoid open basedir issues
@fabpot fabpot closed this as completed Sep 29, 2016
@tschechniker
Copy link
Author

@xabbuh Yes /usr/bin/java is a symlink. This is standard on many Linux distros. But i don't see how the symlink will cause this issue. From my oppinion this is a logical issue.

So my open_basedir has the following content:

open_basedir=/var/www/;/usr/bin/

Now you are itterating over the open_basedir

$dirs[0] = "/var/www/"
$dirs[1] = "/usr/bin/"

Now you are searching for the executeable:
foreach($dirs a $dir) ...
$dir.DIRECTORY_SEPARATOR.$name.$suffix

==> "/usr/bin/".DIRECTORY_SEPARATOR."java".""

So from my side this is not a fault of the symlink

@xabbuh
Copy link
Member

xabbuh commented Sep 30, 2016

@tschechniker It is as the symlink is pointing to a location outside of your open basedir config.

Please note that PHP evaluates the symlink before trying to figure out if the path is allowed:

All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink. If the file doesn't exist then the symlink couldn't be resolved and the filename is compared to (a resolved) open_basedir .

see http://php.net/manual/en/ini.core.php#ini.open-basedir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants