Skip to content

fix: guard HTTP buildpack download against disk exhaustion#2594

Open
jkutner wants to merge 1 commit intomainfrom
fix/http-download-disk-exhaustion
Open

fix: guard HTTP buildpack download against disk exhaustion#2594
jkutner wants to merge 1 commit intomainfrom
fix/http-download-disk-exhaustion

Conversation

@jkutner
Copy link
Copy Markdown
Member

@jkutner jkutner commented May 7, 2026

Summary

  • Add maxDownloadBytes constant (500 MB) to pkg/blob/downloader.go
  • Reject responses whose declared Content-Length exceeds the limit in downloadAsStream before any bytes are written to disk (Option B)
  • Wrap io.Copy in handleHTTP with io.LimitReader and remove the partial cache file if the limit is hit (Option A — catches chunked/no-Content-Length responses)
  • Replace http.DefaultClient in NewDownloader with a client that has a 10-minute timeout and 30-second ResponseHeaderTimeout, closing the slow-drip attack vector (Option C)
  • Two new unit tests cover the Content-Length rejection and timeout paths

Motivation

pkg/blob/downloader.go previously called io.Copy(fh, reader) with no size bound when caching HTTP buildpack downloads. A malicious endpoint referenced via --buildpack, project.toml, or a builder config could stream an arbitrarily large response to fill the victim's disk partition. The default cache location (~/.pack/download-cache) shares the home partition on typical systems, so exhaustion disrupts unrelated processes. Reported by bugbunny.ai, CVSS 3.1: 6.5 (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H).

Test plan

  • go test ./pkg/blob/... -v — all 9 cases pass
  • make build — binary builds cleanly
  • make lint — 0 issues

…sk exhaustion

Signed-off-by: Joe Kutner <jpkutner@gmail.com>
@jkutner jkutner requested review from a team as code owners May 7, 2026 01:16
@github-actions github-actions Bot added the type/enhancement Issue that requests a new feature or improvement. label May 7, 2026
@github-actions github-actions Bot added this to the 0.41.0 milestone May 7, 2026
@jkutner
Copy link
Copy Markdown
Member Author

jkutner commented May 7, 2026

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.56%. Comparing base (5cdc8bf) to head (71b0eaf).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2594      +/-   ##
==========================================
+ Coverage   60.51%   60.56%   +0.06%     
==========================================
  Files         256      256              
  Lines       19513    19525      +12     
==========================================
+ Hits        11806    11824      +18     
+ Misses       6879     6874       -5     
+ Partials      828      827       -1     
Flag Coverage Δ
os_linux 60.21% <73.34%> (+0.05%) ⬆️
os_macos-arm64 57.37% <73.34%> (+0.06%) ⬆️
os_windows 57.19% <73.34%> (+0.06%) ⬆️
unit 60.56% <73.34%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jkutner jkutner force-pushed the fix/http-download-disk-exhaustion branch from c32311d to 71b0eaf Compare May 7, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement Issue that requests a new feature or improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant