Secure Static Files TG2

8 views
Skip to first unread message

KMCB

unread,
Jun 27, 2009, 1:49:45 PM6/27/09
to TurboGears
Hello,

I'll reiterate my noob status for web development as well as TG. Can
any provide or point me to a recipe for Securing and Serving static
files that can be included in a dynamic template? So for example, if
you want a private blog or cms including images that can be viewed by
multiple authenticated and authorized users (friends).

I looked at tgext.pages, but may have missed it.

1) So, should I store the files in a DB and then how do I return them
with TG?
2) Should give everyone a file folder on the server, but then how do I
secure it?

By the looks of it, My wife's Facebook page private images seem to be
secured by using a complex path. I would prefer something better.

Any thoughts are appreciated,

Thanks,
KMCB

Sergei Beilin

unread,
Jun 27, 2009, 3:01:18 PM6/27/09
to TurboGears
Hi, KMCB!

I'll have to solve the same problem rather soon.

My suggestions:
1. Store all files in the filesystem, not accessible directly by the
front-end webserver.
2. Store somne kind of index in a DB (UserID, filename, description,
etc.)
3. Serve files via TG: upon request, open the file, send appropriate
headers (content-type, etc.) to the client and then send the
bytestream.

--
Sergei

Alice Zoë Bevan-McGregor

unread,
Jun 27, 2009, 7:12:08 PM6/27/09
to turbo...@googlegroups.com
> 1) So, should I store the files in a DB and then how do I return
> them with TG?

Storing files in the DB is a recipe for disaster. Depending on your
front-end web server and back-end DB engine, DB storage is fraught
with timeout errors, database locking issues, query time issues, etc.
etc. It can be done, but it's a bad idea.

> 2) Should give everyone a file folder on the server, but then how do
> I secure it?

We use Amazon S3 and the Boto Python Library to upload files to the S3
DHT distribution network with an ACL marking the files private, then
use Boto to generate signed URLs that timeout after a few minutes.

This secures the files from general snooping, and secures them from
being accessed at a time not of your choosing.

> By the looks of it, My wife's Facebook page private images seem to
> be secured by using a complex path. I would prefer something better.

DHT names on Amazon S3 can be any ASCII text. Slashes (indicating
directory separation to most people) mean nothing to S3, allowing you
to use them if you really want to. (The entire system is treated as a
dictionary of name/value pairs.)

Additionally, you can store 4KB (I'm guessing here, we've never
encountered a limit) of arbitrary name/value pair metadata against
each object in the S3 DHT, which can be very handy.

— Alice.

KMCB

unread,
Jun 27, 2009, 10:57:09 PM6/27/09
to TurboGears
Sergei,

Thanks for your thoughts, I found this on Pylons-Discuss. If you have
not seen it, you might find it helpful.

http://groups.google.com/group/pylons-discuss/browse_thread/thread/70fb565a909c72f0/e6adf4ff23302285?q=#e6adf4ff23302285

Regards,
KMCB
Reply all
Reply to author
Forward
0 new messages