Validate a tar upload instead of storing it unread - #28947
Open
arpitjain099 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Arpit Jain <[email protected]>
Contributor
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
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.
Fixes #28913.
postFilechecks theContent-Typeheader and, for zip, validates the archive withzip.NewReaderbefore converting it. A tar is stored unread, so a gzipped tar sent asapplication/x-taris accepted, hashed and returned as a valid file id. The failure then surfaces much later in whatever first reads the filesystem back, which in the report is preview, reported as "Unable to parse workspace tags" with a nil dereference underneath. As the reporter says, an empty template panics too, because the template content is never reached.The upload path now walks the tar headers and rejects an archive it cannot read, so the mistake gets a 400 where it was made. Only headers are walked, so the cost is proportional to the number of entries rather than their contents. A gzip magic check gives that case its own message, since sending
tar czfoutput is the easy way to hit this and the CLI accepts it.This is the first of the three suggestions in the issue. I did not touch the reader on the preview side, and I did not add gzip support: accepting gzip changes what the endpoint means and is worth deciding separately, though the asymmetry with
coder templates pushis the part that cost the reporter the most time.Tests:
TestValidateTarcovers a real tar, the all-zero block form that current uploads already use, a gzipped tar and non-archive bytes.TestPostFilesgains aGzippedTarcase asserting a 400 whose detail mentions gzip, and anUnreadableTarcase.On what I ran:
go test ./coderd/ -run TestValidateTarpasses. I could not run theTestPostFilescases locally,coderdtest.Newdoes not come up in my sandbox and the run sat atfiles_test.go:46until the timeout, so those two are unverified by me and rely on CI.