Skip to content
DoS Audit finding Intermediate

Lack of Timeout leads Resource Exhaustion in API Client

The HTTP client used in the makeApiCall function had no timeout settings, so connections could hang indefinitely. An attacker could exploit this to cause resource exhaustion and denial of service by opening many long-lasting connections.

LZ_security Follow with defsec

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-06-allora-judging/issues/47

Found by

LZ_security, defsec

Summary

The absence of timeout settings in the HTTP client poses the following risks:

  1. Resource Exhaustion:

    • Connections may hang indefinitely, leading to goroutine leaks and memory overconsumption.
    • Over time, this can cause the application to crash or become unresponsive.
  2. Denial of Service (DoS) Vulnerability:

    • Attackers could exploit this to overwhelm the system by initiating numerous long-lasting connections.
    • This could render the entire application or service unavailable to legitimate users.
  3. Cascading Failures:

    • In a microservices architecture, hanging connections can lead to cascading failures across multiple services.
    • This can result in system-wide outages and difficult-to-diagnose issues.

Vulnerability Detail

The current implementation of the makeApiCall function lacks timeout configurations, introducing a severe vulnerability that could lead to resource exhaustion, denial of service, and system instability.

Impact

Implementing these timeout configurations will significantly enhance the resilience and security of the API client:

  1. Prevent Resource Exhaustion: By limiting the duration of connections, the system can maintain control over resource allocation.
  2. Mitigate DoS Vulnerabilities: Timeouts make it much harder for attackers to overwhelm the system with long-lasting connections.
  3. Improve System Stability: By avoiding hanging connections, the overall stability and predictability of the system are greatly enhanced.

Code Snippet

api.go#L166

Go
func makeApiCall(payload string) error {
	url := os.Getenv("BLOCKLESS_API_URL")
	method := "POST"

	client := &http.Client{}
	req, err := http.NewRequest(method, url, strings.NewReader(payload))
	if err != nil {
		return err
	}
	req.Header.Add("Accept", "application/json, text/plain, */*")
	req.Header.Add("Content-Type", "application/json;charset=UTF-8")

	res, err := client.Do(req)
	if err != nil {
		return err
	}
	defer res.Body.Close()

	return nil
}

Tool used

Manual Review

Recommendation

Implement comprehensive timeout settings in the HTTP client:

Go
func makeApiCall(payload string) error {
    url := os.Getenv("BLOCKLESS_API_URL")
    
    client := &http.Client{
        Timeout: 30 * time.Second,  // Overall timeout for the request
        Transport: &http.Transport{
            DialContext: (&net.Dialer{
                Timeout:   5 * time.Second,   // Connection timeout
                KeepAlive: 30 * time.Second,
            }).DialContext,
            TLSHandshakeTimeout:   10 * time.Second,  // TLS handshake timeout
            ResponseHeaderTimeout: 10 * time.Second,  // Timeout for server's response headers
            ExpectContinueTimeout: 1 * time.Second,
            IdleConnTimeout:       90 * time.Second,  // Idle connection timeout
            MaxIdleConnsPerHost:   10,                // Limit idle connections
        },
    }

    ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
    defer cancel()

    req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, strings.NewReader(payload))
    if err != nil {
        return fmt.Errorf("failed to create request: %w", err)
    }

    res, err := client.Do(req)
    if err != nil {
        if os.IsTimeout(err) {
            return fmt.Errorf("request timed out: %w", err)
        }
        return fmt.Errorf("request failed: %w", err)
    }
    defer res.Body.Close()

    // ... (rest of the function)
}

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/458

The original report as published on Sherlock, by LZ_security. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The HTTP client was created without any timeout settings, so requests could hang indefinitely.

Impact

An attacker could overwhelm the system with long-lasting connections, potentially causing a denial of service and cascading failures across services.

What the attacker needed

Ability to trigger API calls

The fix

The protocol team fixed this issue by adding timeout configurations to the HTTP client.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program makes a network request, it normally waits for a response. If the other side never responds, the program can wait forever, using up memory and processing power. This report says the code did not set a time limit, so an attacker could make many such requests and crash the service.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by LZ_security

View all

8 more disclosed reports, best first.

More from Allora

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.