Repository navigation
Conversation
… CSP nonce nonceResponseWriter forwarded WriteHeader to the client right away, while http.FileServer had already set Content-Length to the size of index.html. The nonce meta tag then made the page longer than announced, net/http refused the write with ErrContentLength and the browser got an empty body. The status and headers are now held until flush, which sets Content-Length to the rewritten page. Range is dropped from wrapped requests, since a byte range of the file on disk does not match the rewritten page.
This branch has not been deployed
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 #32169.
Since 2.2.0,
/ui/and every UI route without a dot answer 200 with the headers only: the browser gets an empty body and the web UI does not load.handleUIwraps those requests innonceResponseWriterto add the CSP nonce meta tag toindex.html. The wrapper buffered the body but passedWriteHeaderthrough immediately, afterhttp.FileServerhad setContent-Lengthto the size of the file. The rewritten page is longer than that, sonet/httprejected the single write inflush()withErrContentLengthand nothing was sent.Changes:
nonceResponseWriterkeeps the status code and sends it fromflush(), after settingContent-Lengthto the length of the rewritten page. Responses that are not rewritten (empty body, HEAD, 304) keep their headers as they are.Rangeis removed from wrapped requests. Without that,ServeContentanswered 206 with a byte range of the file on disk, and the nonce was injected into that partial content.TestHandleUI_NonceContentLengthgoes throughhttptest.NewServer, sincehttptest.ResponseRecorderdoes not enforceContent-Lengthand does not show the bug. On the currentmaincode it fails withunexpected EOFfor the full page and a 206 for the range request; with this change both cases return the whole page with the nonce and a matchingContent-Length.I could not run the test from the repository itself: building
./httpneedsgithub.com/hashicorp/releases-api, which is private (#32164). I ran it againsthandleUIandnonceResponseWritercopied into a standalone module, before and after the change, with Go 1.27.2.