Topics


Blogs


Forums


Samples


Media


Labs


Resources

 




DevCentral > Weblogs > Lori MacVittie - Two Different Socks
 I Can Has UR .htaccess File
posted on Tuesday, July 21, 2009 3:28 AM

Notice that isn’t a question, it’s a statement of fact

twitter-htaccess

Twitter is having a bad month. After it was blamed, albeit incorrectly, for a breach leading to the disclosure of both personal and corporate information via Google’s GMail and Apps, its apparent willingness to allow anyone and everyone access to a .htaccess file ostensibly protecting search.twitter.com made the rounds via, ironically, Twitter.

This vulnerability at first glance appears fairly innocuous, until you realize just how much information can be placed in an .htaccess file that could have been exposed by this technical configuration faux pas.

Included in the .htaccess file is a number of URI rewrites, which give an interesting  view of the underlying file system hierarchy Twitter is using, as well as a (rather) lengthy list of IP addresses denied access. All in all, not that exciting, because many of the juicy bits that could be configured via .htaccess for any given website are not done so in this easily accessible .htaccess file.canhashtaccess

 

Some things you can do with .htaccess, in case you aren’t familiar:

  • Create default error document
  • Enable SSI via htaccess
  • Deny users by IP
  • Change your default directory page
  • Redirects
  • Prevent hotlinking of your images
  • Prevent directory listing

.htaccess is a very versatile little file, capable of handling all sorts of security and application delivery tasks. Now what’s interesting is that the .htaccess file is in the root directory and should not be accessible. Apache configuration files are fairly straight forward, and there are plethora examples of how to prevent .htaccess – and its wealth of information – from being viewed by clients. Obfuscation, of course, is one possibility, as Apache’s httpd.conf allows you to specify the name of the access file with a simple directive:

AccessFileName .htaccess

It is a simple enough thing to change the name of the file, thus making it more difficult for automated scans to discover vulnerable access files and retrieve them. A little addition to the httpd.conf regarding the accessibility of such files, too, will prevent curious folks from poking at .htaccess and retrieving them with ease. After all, there is no reason for an access file to be viewed by a client; it’s a server-side security configuration mechanism, meant only for the web server, and should not be exposed given the potential for leaking a lot of information that could lead to a more serious breach in security.

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</Files>

Another option, if you have an intermediary enabled with network-side scripting, is to prevent access to any .htaccess file across your entire infrastructure. Changes to httpd.conf must be done on every server, so if you have a lot of servers to manage and protect it’s quite possible you’d miss one due to the sheer volume of servers to slog through. Using a network-side scripting solution eliminates that possibility because it’s one change that can immediately affect all servers.

Here’s an example using an iRule, but you should also be able to use mod_rewrite to accomplish the same thing if you’re using an Apache-based proxy:

when HTTP_REQUEST { 
    # Check the requested URI
    switch -glob [string tolower [HTTP::path]] { 
       "/.ht*" { 
             reject
          } 
       default {  
          pool bigwebpool 
       }

   }

}

However you choose to protect that .htaccess file, just do it. This isn’t rocket science, it’s a straight-up simple configuration error that could potentially lead to more serious breaches in security – especially if your .htaccess file contains more sensitive (and informative) information.

 

Follow me on Twitter View Lori's profile on SlideShare friendfeedicon_facebook AddThis Feed Button Bookmark and Share

Related blogs & articles:



 
      

Feedback


7/21/2009 5:55 AM
Gravatar Lori, they have to actively make .htaccess accessible. By default, it is not.
mike fratto

7/21/2009 6:26 AM
Gravatar @mike

Or accidentally. Either way, it shouldn't be accessible and if there's a reason it should be to *specific* clients then it needs to be restricted to just those clients.

Lori MacVittie

7/21/2009 7:43 AM
Gravatar While I can understand the use of .htaccess by people using shared hosting who can't directly access the webserver's configuration, there's no way any company (particularly a popular social networking site) should use .htaccess. Instead, everything should be set within the Apache configuration file, with specific instructions to turn off .htaccess for good. Notice how newer webservers like nginx don't even offer the use of .htaccess files? Yeah, good reason for that, just look at the data leakage caused, why would you want anything like that out there? As for all the fancy filtering done by .htaccess files, that's the wrong layer. Use something like HAProxy or Varnish whose specific job it is to handle that kind of grunt work; webservers should serve files and images and should not be required (or relied upon) to do much more.

Admins need to learn the ins and outs of every line in their config, and only then place something outside the firewall. If you're running Apache, repeat after me: AllowOverride None (http://fak3r.com/2007/06/15/apache-server-lockdown-challenge/)
fak3r

7/21/2009 7:47 AM
Gravatar @fak3r

Good point about the shared hosting, I hadn't considered that.

And I absolutely agree with the sentiment that some of the ways in which .htaccess is used is better off handled by an intermediary/other solution. URI rewriting? Why is that being done in .htaccess? Not. Relevant.

Good stuff, thanks for offering it up!
Lori MacVittie

7/29/2009 2:48 AM
Gravatar Agree with @fak3r. Everthing that can be done with .htaccess can be done in the main apache config file or a virtual host config file, so when you have full control of the server .htaccess should not be used.
Dan
 Leave Feedback
Title  
Name  
Email
Url
Comments   
Please add 7 and 8 and type the answer here: