Force referer filter ver. 1.2

This is a Java servlet filter (as per Servlet API 2.3). The idea behind this filter is very simple. Filter lets you stop downloading files from your site by users that are not visiting your site itself. For example, if someone try to download a file from your site: http://your_site/your_file.zip by click on that link on the another site: http://some_site/list_of_files.htm. In this case REFERER header in HTTP request points to some_site. And vice versa if your visitor clicks on the same link on your site REFERER header points to your site. So filter lets you set a mandatory value for REFERER header and redirect all the policy violated requests to some page.

How to use it:

a) download forcerefererflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml. Parameters are:

  referer describes a commas separated list of possible mandate values for REFERER header
  redirect describes a page for redirection

For example:
 


<filter>
  <filter-name>ForceRefererFilter</filter-name>
  <filter-class>com.cj.refer.ForceRefererFilter</filter-class>
  <init-param>
    <param-name>referer</param-name>
    <param-value>http://myserver/license.jsp</param-value>
  </init-param>
  <init-param>
    <param-name>redirect</param-name>
    <param-value>http://myserver/license.jsp</param-value>
  </init-param>
</filter>

c) describe a mapping for this filter in web.xml

<filter-mapping>
  <filter-name>ForceRefererFilter</filter-name>
  <url-pattern>myfile.zip</url-pattern>
</filter-mapping>

in this case filter will be on for for file myfile.zip. So for any request to this file, like this: http://your_server/myfile.zip filter will check out referer field. And users that are not coming from license.jsp file will be redirected to that page.

   For downloading:

    Force referer filter:  forcerefererflt.jar

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: