File uploads are a common requirement in many applications., With Oracle APEX, implementing file uploads is very straightforward, but following best practices ensures good levels of security, performance, and user experience. This blog will cover some best practices to consider when managing file uploads in Oracle APEX and beyond.
Implementing a defence-in-depth approach is essential to secure the upload process, making it more robust and tailored to the service's needs and requirements. Utilising multiple techniques is necessary and recommended, as no single method can fully safeguard the service.
Starting with the more general steps:
The Oracle APEX File upload item has a few ways to put in place some safeguarding when allowing users to upload files through your application:
After logging into the administration services for your APEX instance and selecting 'manage instance', in 'security' under the 'instance settings' section, selecting 'no' on the below setting will prevent unauthenticated users from uploading files in applications that provide file upload controls:
From the Oracle APEX builders guide, it is also worth noting it is recommended that files are uploaded directly to a table in your workspace schema or, if you need programmatic access, uploaded to APEX_APPLICATION_TEMP_FILES rather than stored in the application files table. Also, while files uploaded and stored in the Oracle database via APEX are stored as LOBs in database tables and cannot be executed on their own, the real risk arises when these files are made accessible for opening. It is essential to implement measures to prevent unauthorised access and potential execution of malicious files.
Following OWASP's advice, it is advised to only allow acceptable characters for the file name. Simple characters such as letters, digits, underscores, hyphens, spaces, and periods can be included in your basic whitelist.
Depending on how your file model works, you could implement functionality to store the files using a random string or a timestamp, which can help ensure that each file name is unique and not easily guessable, giving you control to prevent malicious file names from being stored in the system. Alternatively, you can sanitise file names by removing or replacing harmful characters, ensuring that the name does not affect your server's file system or web application.
Please be aware that blocking specific extensions is a weak protection method on its own, especially with unauthorised file uploads. Following OWASP guidelines, "only allow safe and critical extensions for business functionality. Based on the needs of the application, ensure the least harmful and the lowest risk file types to be used".
For file types:
If your application manages a high volume of file uploads, consider the following:
Scanning for malware adds an additional layer of protection, catching malicious files that might slip through the initial validation checks. The implementation of this protective measure will differ for each environment, but below are some starting points:
Along with all the above tips, it is essential to ensure compliance with local laws and regulations regarding data storage. It is also strongly recommended when managing files to have a secure backup plan in place. Implementing file uploads in Oracle APEX is made simple for developers and app users and is highly configurable, but it can open the door to security complexities. By adhering to best practices, you can develop a secure, efficient, and user-friendly file upload experience. A lot of influence for this post was taken from the OWASP file upload cheat sheet, which provides further information on the best file upload practices.
For more information, check out our Oracle APEX Services, and if you liked this blog, check out our other APEX blogs here.
Subscribe to Oracle APEX Insights if you want to stay tuned for more APEX updates.