Protecting your content and bandwidth

Published: {ts '2011-04-02 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/protecting-your-content-and-bandwidth/

There are many things to consider when setting up a website. Design, content, seo, security, speed etc etc. One thing that I have noticed which often gets overlooked is the subject of content theft.

Content theft can take two forms, both of which are very unpleasant.

  1. Copyright violation: Either the copying of textual content or copying of media such as images.
  2. Bandwidth theft: Where the resources of a site are used by another without authorization.

Note: I am not a legal expert on copyright violation so I suggest you look elsewhere for advise if you are considering taking legal action over a suspected copyright violation.

Preventing Copyright Theft

While copyright violations are very serious, beyond protecting a site behind a user authentication system there is very little we can do (from a technical standpoint) to prevent someone copying our content. After all the whole purpose of a website is to publish content for public consumption.

There are two forms of copyright violation we can handle on a technical basis. The first type of copyright violation uses framing where another website uses a frame to present your content as their own. This can easily be prevented with a little javascript.

Prevent Framing With Javascript

This little code snippet tells a users browser to break out of any frames it detects. When someone visits a site which is framing your content the javascript will automatically redirect them to your own site. This turns the content thief into a referer. Simple place this code snippet on your pages.

Note: If a user has disabled javascript this technique wont work, but I dont know many users who disable javascript anymore.

Prevent Image Theft with Watermarking

A watermark is an image overlay which you add to your images declaring it is copyrighted by you. You can do this manually or with an automatic tool. Many modern web scripting languages have this ability. At some later stage I will demonstrate how to do this using coldfusion.

Take care where and how you place the watermark so that it does not negatively affect your legitimate visitors.

Prevent Bandwidth Theft

Bandwidth theft is when another websites presents your material as there own and also uses your website to host the stolen resources. The framing method I discussed earlier is anexample of this.

While I dislike copyright violations I think of bandwidth theft as an even more serious crime. Not only are your intelectual property rights being violated, but you are also being made to pay for the theft of your resources by increased bandwidth usage charges.

Prevent Hotlinking With Mod_Rewrite

In addition to the framing example above, there is a second type of bandwidth theft known as hotlinking. Hotlinking is when a site other than your own links to an images (and other files) hosted on your site. This normally happens when someone has scraped your site and stolen your content. By hotlinking to your images/files they are presenting it as their own content, while at the same time using your site as a resource host so that you pay for the bandwidth being used and not them.

To combat this we can use a little mod_rewrite magic. Create a .htaccess file and place it in your assets directory (i.e. where you keep all your images etc) and paste in the following code. Also create an image file in the same directory which display a message such as "Potential Copyright Violation. This image is the property of x".

I have tried to explain each step in the code, but in essence what this code does is try to see if a request for a resource in this directory is coming from our site, or a select number of friendly sites (such as google) we want to give access to our resources. If none of the coditions are met a the file requested is of the listed type, we substitute it with our copyright violation image.

RewriteEngine On RewriteCond %{HTTP_REFERER} !^$ #Stop execution if this request comes from my site (including all different domain names for it) RewriteCond %{HTTP_REFERER} !^http://neiland.net/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://www.neiland.net/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://neiland.dyndns.org/.*$ [NC] #Stop execution if this request is from google (we do trust google dont we) RewriteCond %{HTTP_REFERER} !google\. [NC] #Stop execution if this request is from a search cache RewriteCond %{HTTP_REFERER} !search\?q=cache [NC] #If we got this far then this is likely a case of hotlinking #So for any of the listed file types we substitute in our copyright violation image RewriteRule .*\.(jpe?g|gif|bmp|png|txt|swf|flv)$ /myassetsdir/copyrightViolation.png [NC,L]

Further Reading

So there you have it, some simple ways of protecting your your intelectual property. There is alot more on this subject so I suggest some googling "copyright law for bloggers" if you want a more in depth analysis. One resource on the subject is http://www.copyright.gov/laws/