Search
Lori MacVittie - Two Different Socks
You are here: DevCentral > Weblogs

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
6/8/2010 3:41 PM
Gravatar Do you know of anyway with htaccess to disable someone from using your domain to point to their own website on the same server? Ex: they use YOURDOMAIN.com to promote their PHISHING WEBSITE.COM by using this simple URL to send users : YOURDOMAIN.COM/~phishing/file.html

Any help would be greatly appreciated. Thanks
Roch
6/9/2010 2:58 AM
Gravatar @Roch

I don't think that .htaccess itself can scan the payload, which you'd need to do on either the submit or the response to find offensive URIs and either strip them out or replace them.

However, you can use .htaccess to block access from YOURDOMAIN.com in general. Check out this article on blocking referrer spam and this one as well

HTH,
Lori
macvittie

Let Me Know What You Think


Please use the form below if you have any comments, questions, or suggestions.

Title:
 
Name:
 
Email: (so we can show your gravatar)
Website:
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
 
Please add 3 and 6 and type the answer here:

Blog Stats

Posts:979
Comments:1685
Stories:0
Trackbacks:583
  

Image Galleries

  

Application Delivery

  

Cloud Computing

  

Random

  

Security

  

Chat Catcher

82,243 Members in 102 Countries and Growing!

Join DevCentral Today!

About DevCentral

DevCentral has been a successful, thriving community for many years. We have always strived to bring you the best technical documentation, discussion forums, blogs, media and much more that we can.

So dive in, get familiar with DevCentral. We hope you like it, we hope it makes your job easier, and lets you get that much more power out of the community. To learn more, make sure to check out the Getting Started section. And if you have any problems, or think something could be easier to use, drop us a line to let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback       or