fix: guard HTTP buildpack download against disk exhaustion#2594
Open
fix: guard HTTP buildpack download against disk exhaustion#2594
Conversation
…sk exhaustion Signed-off-by: Joe Kutner <jpkutner@gmail.com>
Member
Author
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
c32311d to
71b0eaf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
maxDownloadBytesconstant (500 MB) topkg/blob/downloader.goContent-Lengthexceeds the limit indownloadAsStreambefore any bytes are written to disk (Option B)io.CopyinhandleHTTPwithio.LimitReaderand remove the partial cache file if the limit is hit (Option A — catches chunked/no-Content-Length responses)http.DefaultClientinNewDownloaderwith a client that has a 10-minute timeout and 30-secondResponseHeaderTimeout, closing the slow-drip attack vector (Option C)Motivation
pkg/blob/downloader.gopreviously calledio.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 passmake build— binary builds cleanlymake lint— 0 issues