Denial of service (DOS) attacks

A Denial-of-Service (DoS) attack attempts to shut down (halt) servers serving an application to make it inaccessible to users. It's accomplished by flooding a server with an excess amount of traffic or triggering heavy operations that cannot be handled efficiently by the server.

DoS mitigation is usually handled on the infrastructure level by identifying suspicious traffic and throttling. However, there are cases when application knowledge is required to effectively protect against DoS attacks, and it's the developer's job to identify them and take appropriate measures. These cases are the scope of this article.

Identifying vulnerable functionality

There are several types of functionality that are especially vulnerable to DoS attacks and cannot be identified by the infrastructure level mechanisms:

Infrastructure-level anti-DoS mechanisms cannot distinguish the routes/endpoints described above from any other endpoint that is part of the application. Developers must take measures to protect the functionality on a case-by-case basis.

Protection from DoS

The following sections describe measures you can take to protect against DoS attacks.

ReCaptcha/CAPTCHA

"Are you a robot?" challenges can stop automated traffic from going through by verifying that a client is a real person. The downside of this approach is the friction created by requiring legitimate users to solve a challenge while shopping.

Google ReCaptcha is an example of a challenge provider. One of the biggest advantages of ReCaptcha is that it avoids actually presenting a user with a challenge, unless it detects suspicious behavior. Protected endpoints contains a list of forms/endpoints can be enabled for ReCaptcha out-of-the-box. You can extend the list by following the example on how to add coverage can be found in the SecurityPackage repo.

Our own CAPTCHA implementation is also available.

Limited input/output

Each endpoint or route that allows querying multiple entities or creating/updating multiple entities must have a reasonable maximum number of accepted/returned items set. You must inspect the functionality of your code to determine how many create/update are enough for legitimate users.

Configure infrastructure

Some proxies/load-balancers allow you to configure specific throttling rules on a route-by-route basis. A developer must identify especially vulnerable routes and configure the infrastructure accordingly.

When to apply these protections

Use the following guidelines to determine when to apply each protection method.

ReCaptcha (or other type of challenge)

Input/output limit

Infrastructure configuration