[Detail Bug] HTTP: Unbounded max_attempts override enables CPU DoS via C0-Config header

Open Beginner friendly
#225 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
aws, rust
Domain
backend, security

Research direction

Start with the ma parsing in src/service/routes.rs and how RequestConfig validates other C0-Config values; then check how src/object_store/config.rs applies max_attempts. Reject out-of-range values with the existing 400 response pattern and verify that zero and very large values are rejected while valid values still configure retries.

Written by the indexing model from the issue text.

Description

Detail Bug Report

https://app.detail.dev/org_89d327b3-b883-4365-b6a3-46b6701342a9/bugs/bug_e6b02b80-2874-4c10-8981-66c9f606970b

Introduced in #3 by @shikhar on Sep 7, 2025

Summary

  • Context: Cachey is a read-through HTTP cache for S3. The untrusted C0-Config request header lets a client override the AWS S3 SDK's retry/timeout configuration for each cache miss; those values are merged into per-request SDK config overrides for every backend GetObject call.
  • Bug: max_attempts (ma) is parsed from C0-Config and passed to RetryConfig::with_max_attempts with no upper (or lower) bound. A huge value drives an O(max_attempts) synchronous CPU loop inside the AWS SDK's identity-cache load-timeout computation on every S3 operation, before any network I/O — CPU work that none of the server's download deadlines can bound, because it runs inside a single non-preemptible future poll.
  • Actual vs. expected: A request like C0-Config: ma=4294967295 pins a server CPU core for ~3.7 minutes (release build) per backend operation. Expected: out-of-range values are rejected at parse time (every other malformed C0-Config value yields a 400) and the resulting SDK behavior stays within the server's bucket_timeout/download_timeout bounds as the README documents ("SDK overrides are bounded by the server's download deadlines").
  • Impact: Trivial denial of service — a ~100-byte header value burns a full core for minutes per request while holding a download admission slot and a client connection; a number of concurrent requests equal to the tokio worker count stalls the entire service for all clients.

Code with Bug

src/service/routes.rs accepts any syntactically-valid u32 for ma:

"ma" => {
    config.max_attempts = Some(value.parse().map_err(|_| {
        (
            StatusCode::BAD_REQUEST,
            "Invalid value for ma in C0-Config header",
        )
    })?);
}

src/object_store/config.rs applies it without clamping:

if let Some(max_attempts) = self.max_attempts {
    config = config.with_max_attempts(max_attempts); // <-- BUG 🔴 no clamp/range check; any u32 accepted
}

Explanation

  • Because ma is unbounded, a client can set it to a huge value (e.g. u32::MAX).
  • The AWS SDK’s default identity cache (aws-smithy-runtime) computes a pessimistic identity load timeout by summing an exponential backoff term in a loop from 0..attempts-1. This loop is O(max_attempts) and runs synchronously during future poll, before any backend HTTP request.
  • Cachey’s own download/bucket deadlines use select!/timeouts that only trigger between polls; a single poll that runs for minutes cannot be preempted. So the documented expectation that SDK overrides remain within bucket_timeout/download_timeout bounds does not hold for this input.
  • Measured cost of the loop in release: ma=u32::MAX takes ~219.6s (~3.7 min) per call.

Exploit Scenario

An attacker sends requests to any cachey endpoint with:

GET /fetch/some-kind/some-object HTTP/1.1
Range: bytes=0-15
C0-Config: ma=4294967295

Each request pins a tokio worker at 100% CPU for ~3.7 minutes before the first backend request. With roughly one concurrent request per core (tokio worker count), the async runtime is saturated and all endpoints (including health/metrics) stall.

Recommended Fix

Add semantic range validation for ma in the RequestConfig extractor and return 400 for out-of-range values (e.g., reject 0 and cap to a small maximum such as 16).

History

Introduced in commit 0a53101 ("feat: configurable timeouts & retries (#3)") when C0-Config/C0-Upstream was added: the parser accepted any u32 for ma and the retry config passed it directly to RetryConfig::with_max_attempts(...) without validation.

Dominant language
Rust
Stars
622
Forks
18
Avg merge
5h 2m
Merged PRs (30d)
33

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from s2-streamstore/cachey

All issues in s2-streamstore/cachey

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.