Partially incorrect MIME type detection for files newly uploaded to the cloud
Yesterday I stumbled across an issue relating to websites and file handling in the cloud.
I created a stylesheet in a CSS file (
shtml01.css) and uploaded it to the "stylesheets" folder within my channel's cloud directory. I then incorporated this stylesheet into the "Websites" app using
The stylesheet is being ignored and the webpage is not styled accordingly. The following error message appears in the browser console
The stylesheet https://klacker.org/cloud/zumtesten/stylesheets/shtml01.css was not loaded because its MIME type, "text/plain", is not "text/css".
which, of course, explains why the stylesheet is not being applied.
I then visited a webpage on the channel that I created last September. This uses a CSS file in the same directory (
mycss.css), which was also uploaded in September. This stylesheet is correctly recognised and applied when I visit the webpage. There is also no error message in the browser console.
To test this, I then copied the working CSS file (
mycss.css) to the same folder under a new name (
mycss1.css) and, as a test, included it in the webpage that had previously been working. Now the stylesheet was no longer being applied, and the error message appeared again in the browser console
The stylesheet https://klacker.org/cloud/zumtesten/stylesheets/mycss1.css could not be loaded because its MIME type, "text/plain", is not "text/css".
Including the original CSS file (
mycss.css) works again.
Apparently, newly created or uploaded CSS files are no longer recognised as "
text/css" but as "
text/plain", which prevents them from being applied.
I cannot pinpoint exactly when this error first occurred, as September was the last time I uploaded a CSS file (and then today, with the error).
I had a look at the changelog, but only came across "
Use finfo class to determine MIME type in attach_store()", which seems to refer only to photo files uploaded as attachments (or could this cause a side effect that also affects other files?).
In any case, it's currently no longer possible to use stylesheet files in the "Websites" app.
Note:
In fact, it appears that for files of type CSS (I cannot comment on other files of type text/???), after uploading (or copying from another location in the cloud), the value of the 'filetype' field in the 'attach' table is incorrectly set to 'text/plain' instead of the correct 'text/css'.
The bug appears to be from
902 // Until here we either used the provided mime type or set mimetype by extension.
903 // Both variants are inherently unsafe hence try to find and set the real mimetype before storage.
904
905 if (class_exists('finfo') && is_file($os_basepath . $os_relpath)) {
906 $finfo = new finfo(FILEINFO_MIME_TYPE);
907 $mimetype = $finfo->file($os_basepath . $os_relpath);
908
909 if ($mimetype === false) {
910 $mimetype = 'application/octet-stream';
911 }
912 }
in the file include/attach.php, which was not yet present in the code in version 10.x.
@Mario Vavti @Harald Eilertsen