Question

I have a web app and I would like to prevent DOS attacks by blocking an IP address if it make many request in a short period of time.

For example, if the same IP address makes 100 request in a second, I can assume that it's some kind of attack and I would like to block this IP.

However, making this check in the application layer seems too expensive - what is the optimal way to make this check?

Should I make this kind of check at my:

  • firewall
  • router
  • apache config
  • someplace else entirely ...
Was it helpful?

Solution 2

Some apps for generating APIs in django implement some methods for limiting the amount of request per second. For example django-piston use throttling method to do that. django-piston throttling

Thats an easy way to solve the problem.

OTHER TIPS

If you want to block IP addresses when they make a certain number of requests, this is best done at the Network layer. This would suggest that you do this either in your host machine's network stack or using a router (which operates at the network layer).

Some things you might want to consider though are: - Are you really wanting to block access to the entire host based on an IP address, or do you want to block access to a specific application running on a specific port. - Sometimes, by using NATs, one IP address may be making requests on behalf of many real hosts.

With any security application you need to have many layers of defence, so it would be a good idea to invest in a good firewall as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top