How Can We Help?
Whenever you offer a file upload on your WordPress website, the question is where these files are uploaded to. In WordPress, the uploaded files typically end up in a subfolder in the /wp-content/upload/ directory.
The problem with file uploads is the security aspect. “As is” the files would be accessible to anybody as they are unprotected. Therefore, if unauthorized people know the file path and file name, they can easily download the files from your WordPress directory. This poses a significant security threat as you do not want anyone unauthorized to enter your website and steal important files. This is even more critical, if you run a digital web store by using Easy Digital Downloads where you rely on selling downloadable files.
The same is true for the Freelancer Marketplace plugin. Files uploaded by users need to be protected against unauthorized file access.
Security Concept
The solution is to implement security measures which first checks if somebody indeed is duly authorized to access the files. This can only be done when cross-checking the user’s privileges inside the WordPress user database. This means, every user needs to run through a specific php script which checks this and we need protection from users which are trying to access files from the web without authorization.
Depending on the server type, we either need to use .htaccess files or server rules to prevent unauthorized file access.
Apache Servers
One solution for Apache-powered websites is to deny access to the file download directory of Freelancer Marketplace Plugin in WordPress by using an .htaccess file in /wp-content/uploads/freelancer_marketplace/ folder which contains rules to prevent access by unauthorized users. The contents of the .htaccess file can be as follows:
Options -Indexes
deny from all
NGINX Servers
Like Apache, Nginx is a contemporary and quick web server software and is mostly used by advanced users which require faster performance than Apache servers can offer. .htaccess files do not work when using Freelancer Marketplace Plugin on a WordPress website powered by NGINX.
What we need to do here is to define a server redirect rule within the NGINX server configuration. Please note, you might need to contact your web hosting provider to get help implementing such a rule.
These are the steps to follow:
- Define a list of File Types such as docc, pptx, pdf, zip, which need to be protected against unauthorized download
- Setup a redirect rule in the NGINX Server such as the following:
Rewrite ^./wp-content/uploads/freelancer_marketplace/(.).(docx|pptx|ppt|zip|csv|pdf)$ / permanent;
What the rule will do is to rewrite the file path whenever somebody tries to access a file matching on these file types via browser access. This now also means, files can only be accessed when using a php function. In Freelancer Marketplace Plugin, we are exactly
doing this, checking every time if a user has the rights and privileges to access certain files.
Check out the Freelancer Marketplace Plugin pages below: