Openmrs RA provides functionality for a user to add an attachment(document or file) to a patient as a Complex Obs. However, this functionality is vulnerable.
An attacker can submit a malicious script. For example, a user can upload a .php file solong as its weight is below the maximum set size.
Actually, i even uploaded a .js file and the process executed successfully.
A possible solution is to sanitize the input from the client size by being strict on what you want. I guess this is responsible for file upload(correct me if i am wrong) in this form
Another requirement is to make sure that the user has file upload permissions. But I guess this feature is being worked upon BU @sharif
How can I restrict file upload basing their type using the client side. Or this will be better if it is implemented from the server side.
Maybe we should start by just disallowing the upload of a Window or *nix executable file. It’s difficult to predict all the different filetypes implementers might need and we should try not to break existing workflows.
Be careful about implementing filtering client-side. It’s likely that most client-side filetype upload prevention methods would be trivially circumventable by manually tampering with the POST request.
@jnsereko right at this pointfile gives you the MIME type: file.getContentType().
You could have a validation method that would take the MIME type as an argument and would decide if the upload is accepted or refused based on the MIME type.
FWIW, we would expect a wide variety of potential file types across images, documents (text, PDF, Word, etc.), and videos to support a wide variety of use cases (documentation, clinical images, scanned files, data from ancillary systems, patients uploading documentation or images for their provider, etc.).
Blocking obvious bad players (e.g., executables and scripts) would be a good place to start.