Skip to content

Local filesystem cannot serve files with urlencoded characters #59709

@j3j5

Description

@j3j5

Laravel Version

13.5.0

PHP Version

8.5

Database Driver & Version

No response

Description

When using a filesystem with the local driver and the setting serve = true, files with urlencoded characters on them cannot be served because the url gets decoded before being passed to the Filesystem's ServeFile class.

See following test that fails when it shouldn't.

#[WithConfig('filesystems.disks.local.serve', true)]
class ServeFileTest extends TestCase
{
    // ...
    public function testServingFileWithUrlEncodedCharactersWorks()
    {
        Storage::put('serve%20file%20test.txt', 'Hello World');

        $url = Storage::temporaryUrl('serve%20file%20test.txt', Carbon::now()->addMinutes(1));

        $response = $this->get($url);

        $response->assertOk();
    }
}

On src/Illuminate/Filesystem/FilesystemServiceProvider.php, when creating the route for serving the locally stored files, the $path variable that's passed to the ServeFile class, it's already urldecoded, so the file can never be found.

Steps To Reproduce

  1. Store a file with urlencoded characters (like %20) on it on a filesystem with a local driver.
  2. Try to access it through HTTP on the url returned by Storage::url($filename).
  3. Get a 404 even though the file exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions