Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat and flood protection

We are using Tomcat 7 for our web application. We provide an XML based API so that our customers can communicate with our server in a machine-to-machine way (no web browser needed). The requests are processed by a servlet.

We need to prevent users from sending too many requests in a row. Some of the services we provide involve polling for results and users may make requests in a loop without any pauses, making dozens of requests per second for nothing.

How can we protect ourselves from being flooded with useless requests? Is there a simple way to block requests at the servlet entry level when there are too many requests originating from the same IP? Is there something built-in Tomcat to deal with this problem?

like image 570
J. Volkya Avatar asked Jul 13 '12 15:07

J. Volkya


2 Answers

Assuming that you are using an apache reverse-proxy in front of tomcat (if you aren't you should be), use mod_cband on the apache layer.

like image 167
Rocky Pulley Avatar answered Sep 21 '22 14:09

Rocky Pulley


You could code your own.

Starting points for looking at this would be the Servlet API, in particular the Filter interface and the getRemoteHost() method of the SerlvetRequest interface.

Should be easy enough to write a Filter implementation which stores a count of requests from each host and takes action if a limit exceeded.

like image 38
Alan Hay Avatar answered Sep 22 '22 14:09

Alan Hay