Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most Secure Way to Store Uploaded Files

Tags:

symfony

I store uploaded files in the web directory:

//src/Acme/CocoBundle/Entity/CocoFromTheNorth.php
/**
 * @ORM\Column(type="string", length=255, nullable=true)
 */
public $path;

protected function getUploadRootDir()
{
    return __DIR__.'/../../../../web/'.$this->getUploadDir();
}

protected function getUploadDir()
{

    return 'uploads/documents';
}

Is this a good practice? Wouldn't it be better to keep uploaded files outside the web directory so that they cannot be directly accessed by the users?

Am I right to think that the best way would be to store uploaded files outside of the web root? Where would it be the best then? Or how could I configure the web server to deny access to the uploads directory?

like image 419
Mick Avatar asked Jun 11 '12 06:06

Mick


People also ask

What is the most secure file transfer?

Top secure file transfer protocols include SFTP, FTPS, and AS2. Each of these offers stronger encryption than standard FTP, as well as additional safeguards, including keys, passwords, and certificates to authenticate users or connections.

How will you prefer to store a private file securely for yourself?

Store files in the cloud You can keep them safe in the cloud, but first, you have to know about the security of your storage service. Many popular file-sharing services, such as Dropbox, encrypt your data—but this doesn't make them completely private.


1 Answers

It's preferred to keep uploaded files outside of the web directory and use X-SendFile to serve those files after you established the access permissions using PHP.

I've outlined something similar here: How to securely store files on a server

And here: Caching HTTP responses when they are dynamically created by PHP

like image 108
Ja͢ck Avatar answered Oct 17 '22 21:10

Ja͢ck