CWE-400: Uncontrolled Resource Consumption

Description:
The product does not properly control the allocation and maintenance of a limited resource.

Affected languages: Not Language-Specific
Affected technologies: Not Technology-Specific, AI/ML
Parent weaknesses: CWE-664

Consequences:
  - Availability: DoS: Crash, Exit, or Restart
  - Access Control: Bypass Protection Mechanism

Detection methods:
  - Automated Static Analysis: Automated static analysis typically has limited utility in recognizing resource exhaustion problems, except for program-independent system resources such as files, sockets, and processes. For system r
  - Automated Dynamic Analysis: Certain automated dynamic analysis techniques may be effective in spotting resource exhaustion problems, especially with resources such as processes, memory, and connections. The technique may involve
  - Fuzzing: While fuzzing is typically geared toward finding low-level implementation bugs, it can inadvertently find resource exhaustion problems. This can occur when the fuzzer generates a large number of test 

Mitigations:
  - [Architecture and Design] Design throttling mechanisms into the system architecture. The best protection is to limit the amount of resources that an unauthorized user can cause to be expended. A strong authentication and access control model will help prevent such attacks from occurring in the first place. The login applicat
  - [Architecture and Design] Mitigation of resource exhaustion attacks requires that the target system either: 
                      
                         recognizes the attack and denies that user further access for a given amount of time, or 
                         uniformly throttles all requests in order to make it m
  - [Architecture and Design] Ensure that protocols have specific limits of scale placed on them.
  - [Implementation] Ensure that all failures in resource allocation place the system into a safe posture.

Demonstrative examples:
The following example demonstrates the weakness.
There are no limits to runnables. Potentially an attacker could cause resource problems very quickly.
class Worker implements Executor { 
                         ... public void execute(Runnable r) { 
                               
                                  try { ... } catch (InterruptedException ie) { 
                                     
                                        
                                        // postpone response 
                                        Thread.currentThread().interrupt(); 
                                  } 
                            } 
                            public Worker(Channel ch, int nworkers) { ... } 
                            protected void activate() { 
                

This code allocates a socket and forks each time it receives a new connection.
The program does not track how many connections have been made, and it does not limit the number of connections. Because forking is a relatively expensive operation, an attacker would be able to cause the system to run out of CPU, processes, or memory by making a large number of connections. Alternatively, an attacker could consume all available connections, preventing others from accessing the system remotely.
sock=socket(AF_INET, SOCK_STREAM, 0); while (1) { newsock=accept(sock, ...); printf("A connection has been accepted\n"); pid = fork(); }

Real-world examples:
  - CVE-2019-19911: Chain: Python library does not limit the resources used to process images that specify a very large number of bands (CWE-1284), leading to excessive memory consumption (CWE-789) or an integer overflow
  - CVE-2020-7218: Go-based workload orchestrator does not limit resource usage with unauthenticated connections, allowing a DoS by flooding the service
  - CVE-2020-3566: Resource exhaustion in distributed OS because of "insufficient" IGMP queue management, as exploited in the wild per CISA KEV.
  - CVE-2009-2874: Product allows attackers to cause a crash via a large number of connections.
  - CVE-2009-1928: Malformed request triggers uncontrolled recursion, leading to stack exhaustion.