|
| 1 | +A4:2019 Lack of Resources & Rate Limiting |
| 2 | +========================================= |
| 3 | + |
| 4 | +| Threat agents/Attack vectors | Security Weakness | Impacts | |
| 5 | +| - | - | - | |
| 6 | +| API Specific : Exploitability **2** | Prevalence **3** : Detectability **3** | Technical **2** : Business Specific | |
| 7 | +| Exploitation requires simple API requests. No authentication is required. Multiple concurrent requests can be performed from a single local computer or by using cloud computing resources. | It’s common to find APIs that do not implement rate limiting or APIs where limits are not properly set. | Exploitation may lead to DoS, making the API unresponsive or even unavailable. | |
| 8 | + |
| 9 | +## Is the API Vulnerable? |
| 10 | + |
| 11 | +API requests consume resources such as network, CPU, memory and storage and the |
| 12 | +amount of resources required to satisfy a request greatly depends on the user |
| 13 | +input and endpoint business logic. Also consider that requests from multiple API |
| 14 | +clients compete for resources. An API is vulnerable if at least one of the |
| 15 | +following limits is missing or set inappropriately (i.e. too low/high) |
| 16 | + |
| 17 | +* Execution timeouts |
| 18 | +* Max allocable memory |
| 19 | +* Number of file descriptors |
| 20 | +* Number of processes |
| 21 | +* Request payload size (e.g. uploads) |
| 22 | +* Number of requests per client/resource |
| 23 | + |
| 24 | +## Example Attack Scenarios |
| 25 | + |
| 26 | +### Scenario #1 |
| 27 | + |
| 28 | +An attacker uploads a large image by issuing a POST request to `/api/v1/images`. |
| 29 | +When the upload is complete, the API creates multiple thumbnails with different |
| 30 | +sizes. Due to the size of the uploaded image, available memory is exhausted |
| 31 | +during the creation of thumbnails and the API becomes unresponsive. |
| 32 | + |
| 33 | +### Scenario #2 |
| 34 | + |
| 35 | +An attacker starts the password recovery workflow by issuing a POST request to |
| 36 | +`/api/system/verification-codes` and by providing the username in the request |
| 37 | +body. Next an SMS token with 6 digits is sent to the victim’s phone. Because the |
| 38 | +API does not implement a rate limiting policy the attacker can test all possible |
| 39 | +combinations using a multi-thread script, against the |
| 40 | +`/api/system/verification-codes/{smsToken}` endpoint to discover the right token |
| 41 | +within a few minutes. |
| 42 | + |
| 43 | +## How To Prevent |
| 44 | + |
| 45 | +* Docker makes it easy to limit [memory][1], [CPU][2], [number of restarts][3], |
| 46 | + [file descriptors and processes][4]. |
| 47 | +* Implement a limit on how often a client can call the API within a defined |
| 48 | + timeframe. |
| 49 | +* Notify the client when the limit is exceeded by providing the limit number and |
| 50 | + the time at which the limit will be reset. |
| 51 | + |
| 52 | +## References |
| 53 | + |
| 54 | +### OWASP |
| 55 | + |
| 56 | +* [Blocking Brute Force Attacks][5] |
| 57 | +* [Docker Cheat Sheet - Limit resources (memory, CPU, file descriptors, |
| 58 | + processes, restarts)][6] |
| 59 | +* [REST Assessment Cheat Sheet][7] |
| 60 | + |
| 61 | +### External |
| 62 | + |
| 63 | +* [CWE-307: Improper Restriction of Excessive Authentication Attempts][8] |
| 64 | +* [CWE-770: Allocation of Resources Without Limits or Throttling][9] |
| 65 | +* “_Rate Limiting (Throttling)_” - [Security Strategies for Microservices-based |
| 66 | + Application Systems][10], NIST |
| 67 | + |
| 68 | +[1]: https://docs.docker.com/config/containers/resource_constraints/#memory |
| 69 | +[2]: https://docs.docker.com/config/containers/resource_constraints/#cpu |
| 70 | +[3]: https://docs.docker.com/engine/reference/commandline/run/#restart-policies---restart |
| 71 | +[4]: https://docs.docker.com/engine/reference/commandline/run/#set-ulimits-in-container---ulimit |
| 72 | +[5]: https://www.owasp.org/index.php/Blocking_Brute_Force_Attacks |
| 73 | +[6]: https://github.com/OWASP/CheatSheetSeries/blob/3a8134d792528a775142471b1cb14433b4fda3fb/cheatsheets/Docker_Security_Cheat_Sheet.md#rule-7---limit-resources-memory-cpu-file-descriptors-processes-restarts |
| 74 | +[7]: https://github.com/OWASP/CheatSheetSeries/blob/3a8134d792528a775142471b1cb14433b4fda3fb/cheatsheets/REST_Assessment_Cheat_Sheet.md |
| 75 | +[8]: https://cwe.mitre.org/data/definitions/307.html |
| 76 | +[9]: https://cwe.mitre.org/data/definitions/770.html |
| 77 | +[10]: https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-204-draft.pdf |
0 commit comments