Attachment foo - files security


I am using attachment_foo for sharing files between users. Everything
works fine but I am worry about the security.

All files are stored in the public rails folder so any browser can
easily access these files!!
I know that the folder path is specific but probably I could write a
simple script that could find some common file names.

Guys, did you think about that during development?

Is there any way to serve files by rails app. So that I could avoid
storing files in public directory?

Is database good idea? Is it efficient way?

Thank you.

On 16 Apr 2009, at 12:27, Zirael wrote:

Guys, did you think about that during development?

Use X-sendfile, X-Accel-redirect or generate hard to guess filenames
(ie /1ea39e7eacd783eda093223aebdcdf234/myfile)


I had the same problem with some of my projects, where some images or
files had to be accessible only to logged users.

The solution is easy (I’m using file_column but the idea is the same),
when you declare has_attachment you can also select where to save your
files using :path_prefix .

You can set something like :path_prefix => “resources/#{table_name}” or
some other non public directory to avoid accessing the files directly by
passing a url.

To access the files, you call a method in a controller that serves back
the file using the send_file function. Check the api for better info
about it, you can send back the file inline (to be used in an image_tag
for instance) or as a download.

Since the file is sent by a method, it’s easy to prevent its download
from non authorized user

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs