views:

179

answers:

2

How would I only allow users authenticated via Python code to access certain files on the server?

For instance, say I have /static/book.txt which I want to protect. When a user accesses /some/path/that/validates/him, a Python script deems him worthy of accessing /static/book.txt and redirects him to that path.

How would I stop users who bypass the script and directly access /static/book.txt?

+4  A: 

Lighttpd has mod_secdownload for this. Basically, it won't serve the static content directly unless you generate a short-lived static URL for it.

Note that you can do similar things on S3 for static content. It's a quite useful feature.

Dustin
Dustin, can you point me towards the docs for doing this with s3?
enobrev
There's example python code in the S3 developer guide under "Query String Authentication Example"
Dustin
+4  A: 

You might want to just have your Python script open the file and dump the contents as its output if the user is properly authenticated. Put the files you want to protect in a folder that is outside of the webserver root.

bobwienholt