Laravel Valet serving jpeg files with no extension with wrong size and changed checksum of course.
I'm posting information about an example file, the file with .0
at the end is downloaded through valet.
$ls -la
f2b40f33d19b147bc8d0e88f4b8c489e35c165dd
-rw-r--r-- 23905
f2b40f33d19b147bc8d0e88f4b8c489e35c165dd.0
-rw-r--r-- 23750
$ls -la
$ md5 f2b40f33d19b147bc8d0e88f4b8c489e35c165dd
MD5 (f2b40f33d19b147bc8d0e88f4b8c489e35c165dd) = 9b5d3e104764e4b4c2b9e942704091f1
$ md5 f2b40f33d19b147bc8d0e88f4b8c489e35c165dd.0
MD5 (f2b40f33d19b147bc8d0e88f4b8c489e35c165dd.0) = 944e47ce0ccd4da18b7761af0e5f0226
I tried adding a mime to CaddyFile but it seems caddy does not support mime for files with no extension. I tried the following:
mime . image/jpeg
mime .* image/jpeg
mime * image/jpeg
Same file with a .jpeg
extension is OK, what's wrong?
Valet uses mimes.php
in ValetDriver.php
to determine the right content type based on the file extension:
...
"jpeg" => "image/jpeg",
"jpg" => "image/jpeg",
"jpe" => "image/jpeg",
...
you can add the empty extension there, to serve everything without extension as image/jpeg
"" => "image/jpeg"
However, Valet isn't supposed to server files with empty extension, you get the notice which breaks the image
Notice: Undefined index: extension in ...cli\drivers\ValetDriver.php on line 121
As a quick hack you can change the line #121 in ~/.composer/vendor/cli/drivers/ValetDriver.php
to suppress the notice
@$extension = pathinfo($staticFilePath)['extension'];