Referer
cannot be trusted, as it is sent by the browser and very easily guessed (or easily disabled, which would break things annoyingly). Indeed, if you're implementing this the way I think you're implementing it, someone need only know the URL to the secure page to get access to the secured files. Probably not good. Two better alternatives:
1) Make the files subject to the website's access controls, somehow. Depending on how your application stores authentication credentials, Apache might be able to work with it, or you can set up a second set of usernames/passwords (
see here). However, if your application uses cookie-based login, this would result in the dreaded, annoying double-sign-in.
2) Use some sort of secure token for providing access. lighttpd's
mod_secdownload is a good example of this approach; Amazon S3's
query string authentication is another. The gist is that your application and web server have a secret that only they know; based on this, your application tells the user's web browser "psst, tell the web server that it's a half past midnight and the blue cow leaps over the dingo's kidney"... the browser does so and the web server hands over the secret documents after consulting its codebook.
I don't know of a way to implement this with Apache, but someone's probably done it!
_________________
Code:
/* TODO: need to add signature to posts */