+ Reply to Thread
Results 1 to 7 of 7

Thread: Restricting Directories

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Restricting Directories

    I have a very large site I am working on that has many directories that I wish to block from public viewing. These directories contain MP3 files that I do not wish to be downloaded. These files still need to be available for use in a flash media player.

    Is there a way to block access to all folders named "music". The only thing I could think of is a .htaccess redirect if they try to type it in directly, but I am not the best at .htaccess coding? Any suggestions would be greatly appreciated.

  2. #2
    farscapeone's Avatar
    farscapeone is offline Community Advocate farscapeone is on a distinguished road
    Join Date
    Dec 2008
    Location
    Србија (Serbia)
    Posts
    1,166

    Re: Restricting Directories

    Did you know that PHP ignores permissions form the server? That means if you set chmod of any folder to block everything your PHP script will still be able to access it.

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Restricting Directories

    You could do something similar to a HotLink protect in .htaccess

    Code:
    RewriteCond %{HTTP_REFERER} !^http://yourwebaddy.com/music/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.yourwebaddy.com/music/.*$      [NC]
    RewriteRule .*  http://www.yourwebaddy.com/notavailable.html[R,NC]
    all requests in dir music not sent from one of your pages get deflected (but can be spoofed).
    Last edited by descalzo; 01-21-2010 at 12:30 PM.
    Nothing is always absolutely so.

  4. #4
    slacker3 is offline x10 Sophmore slacker3 is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    146

    Re: Restricting Directories

    Spoofing the HTTP referrer is actually an pretty easy task - it's sent by the client's web browser and can contain anything (or nothing). You should never trust any user input.
    Last edited by slacker3; 01-21-2010 at 02:18 PM. Reason: :)

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Restricting Directories

    Quote Originally Posted by slacker3 View Post
    Spoofing the HTTP referrer is actually an pretty easy task - it's sent by the client's web browser and can contain anything (or nothing). You should never trust any user input.
    Then what is your suggestion for a solution to his question?
    Nothing is always absolutely so.

  6. #6
    slacker3 is offline x10 Sophmore slacker3 is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    146

    Re: Restricting Directories

    Quote Originally Posted by descalzo View Post
    Then what is your suggestion for a solution to his question?
    I'm not familiar with flash, so i can't give any suggestions.

    The mp3 files could be stored above document root - or just protect the folder with http basic auth
    using an ultra-long password (you don't have to use it anyway), which could be done with cpanel.


    But if you can play 'em, you can download 'em. ;)

  7. #7
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Restricting Directories

    Quote Originally Posted by leviathon View Post
    Did you know that PHP ignores permissions form the server? That means if you set chmod of any folder to block everything your PHP script will still be able to access it.
    PHP doesn't ignore permissions; the only processes that can ignore permissions are those running as root. What happens is PHP scripts run with your credentials, so the "owner" permissions apply. Since the owner usually has read access (and execute/search for directories), the PHP script can access all your files. Try to access someone else's files with a PHP script and you'll often be denied.

    Quote Originally Posted by slacker3 View Post
    But if you can play 'em, you can download 'em.
    This is the crux of the problem. HTTP doesn't differentiate among user agents. Since the songs have to be available to the flash player (which runs client side), the MP3s need to be publicly accessible. If you embed the MP3s in flash movies (which could be done on-the-fly), so only these flash movies are accessible, the MP3s can be extracted from the movies.

    You could add some secret information to the flash movie, either a token that the server checks before sending a song or a decryption key (either encrypt the MP3s before storage or encrypt them on-the-fly, if different clients are to have different secret keys), but this info could be extracted from the player. This is probably the best you can hope to do. Throw in Referer checking, because it's slightly simpler to implement than it is to circumvent.

    Even if you find a way to keep MP3s from opening in a browser, a user can record incoming packets and extract the MP3 stream. In short, you can make it difficult for visitors to get MP3s directly, but you can't prevent it.
    Last edited by misson; 01-21-2010 at 04:08 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 09-11-2009, 05:53 PM
  2. what are all these directories?
    By wbar8417 in forum Free Hosting
    Replies: 2
    Last Post: 06-13-2008, 11:23 AM
  3. Seo Directories
    By networker in forum Advertising
    Replies: 3
    Last Post: 04-02-2008, 09:32 AM
  4. Password Protect Directories Thread
    By swanniebroo in forum Programming Help
    Replies: 3
    Last Post: 02-07-2008, 06:57 PM
  5. Reset to original directories and files?
    By Jambu in forum Free Hosting
    Replies: 3
    Last Post: 12-10-2007, 02:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers