We are currently operating OPS3.3.0.8 (PHP8.1).
When an author uploads a file with the .unitypackage extension among the manuscript-related files, a .txt extension is appended. Upon investigating the source code, we found the following process being executed:
File Upload Process:
The function parseFileExtension is called during the file upload.
Could you please advise on how to add the MIME type for file extensions not currently supported by OPS, such as in this case? Ideally, we would prefer a solution that does not involve modifying the OPS source files but instead uses a configuration file to add the definitions.
The unitypackage extension is pretty niche – but we are already explicitly working around generic handling of extensions for e.g. .tar.gz archives in that piece of code. If you’d like to submit a PR that explicitly handles unitypackage files as well, I’ll consider it for inclusion in the next release.
Regards,
Alec Smecher
Public Knowledge Project Team
Thank you for your response.
If I were to modify the source code and submit a pull request, I would propose the following changes:
An external file sample of allowed_extensions.txt:
unitypackage
unityweb
uproject
webmanifest
A sample of revised code:
// Read the file of allowed_extensions.txt
$allowedExtensions = file('allowed_extensions.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
// FIXME Check for evil
if (!isset($fileExtension) || stristr($fileExtension, 'php') || strlen($fileExtension) > 6 || !preg_match('/^\w+$/', $fileExtension)) {
if (!in_array(strtolower($fileExtension), $allowedExtensions)) {
$fileExtension = 'txt';
}
}
However, considering long-term operation and security risks, I believe it might be better not to allow direct uploads of diverse project files or files used in specific software environments to OPS/OJS. Instead, we could guide users to external platforms like GitHub, where they can download the necessary files. What are your thoughts on this approach?
I would appreciate hearing your opinion on this matter.
Thank you for your reply.
In the end, we decided not to directly publish .unitypackage files. Therefore, for the time being, no further action is required.
Additionally, creating a plugin solely for addressing this issue would be cumbersome, so we would prefer to wait for this to be incorporated into the OPS’s core in a future release.