Skip to content

[11.x] Do not change relative path to absolute one #46668

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

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

CmdMumm
Copy link
Contributor

@CmdMumm CmdMumm commented Apr 3, 2023

Do not change relative path to absolute if SFTP-Driver is created without root path - similiar to createFtpDiver()

Do not change relative path to absolute if SFTP-Driver is created without root path - similiar to createFtpDiver()
@driesvints driesvints changed the title Do not change relative path to absolute one [11.x] Do not change relative path to absolute one Apr 3, 2023
@driesvints
Copy link
Member

@CmdMumm will need a much more thorough explanation to let taylor know what this is about.

@CmdMumm
Copy link
Contributor Author

CmdMumm commented Apr 3, 2023

If an SFTP connection is to be established using a relative path and the root path is not set in the connection configuration, the relative path becomes an absolute path by inserting a leading "/", e.g. 'foo/bar' becomes '/foo/bar'

One of the biggest issues here is, that this behaviour is not noticed. In my case through the unnoticed path change from relative to absolute, order files were not longer distributed to the fulfillment center. But the error seen in phpseclib (from the sftp-server) never throws an exception. So the error was not recognized.

In my opinion there are two problems:

  1. The change from relative to an absolute path.
  2. A possible error from the SFTP-Server (e.g. no rights on the absolute path) isn't noticed.

In Laravel 8.83.27 everything worked as expected, so 'foo/bar' stayed 'foo/bar'.

I think the problem is in laravel/framework/src/Illuminate/Filesystem/FilesystemManger.php, method createSftpDriver():

public function createSftpDriver(array $config)
   {
       $provider = SftpConnectionProvider::fromArray($config);

       $root = $config['root'] ?? '/';
    }

If $config['root'] is not set, a slash is added.

I would rather expect a behaviour like in the createFtpDriver()-method:

public function createFtpDriver(array $config)
   {
       if (! isset($config['root'])) {
           $config['root'] = '';
       }

If $config['root'] is not set it is set empty and the relative path is preserved.

@taylorotwell
Copy link
Member

If everything worked as expected in 8.83.27, can we determine the PR or change that introduced this behavior of using / as the default root path? I would be curious to know for what reason that behavior was introduced.

@driesvints
Copy link
Member

@taylorotwell these changes were done by me mostly when we moved to Flysystem v2 in Laravel v9: #33612

Afterwards (I can't remember what triggered it) we needed to fix the FTP root config: #40939. Frank pointed out that this needed to be an empty string (like this PR is trying to do for the SFTP driver). Most likely we should have also changed it for the SFTP driver at the time.

@taylorotwell taylorotwell merged commit c8b95c9 into laravel:master Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants