Conversation
Requestor read entire response bodies into memory with no size limit, so a compromised upstream, misbehaving proxy, or MITM returning a very large body could exhaust the JVM heap. Response bodies are now capped at 10 MB. A Content-Length above the cap is rejected before anything is read, and the cap is also enforced while streaming in case the header is missing or wrong. Oversized responses throw an HttpError with a descriptive message. The App Engine fallback path applies the same cap. SEC-787 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 of 4 tasks
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.
Description
Fixes SEC-787 (pentest finding, Medium).
Requestorread whole HTTP response bodies into memory with no size limit (Scanner(...).useDelimiter("\\A")). A compromised upstream, a misbehaving proxy, or a MITM sending a very large body could exhaust the JVM heap.Changes:
getResponseBody(InputStream, long contentLength)reads in 8 KB chunks and stops atConstants.Http.MAX_RESPONSE_BODY_BYTES(10 MB).HttpErrorwith a descriptive message (Constants.ErrorMessages.RESPONSE_BODY_TOO_LARGE), not an OOM.HttpErroris not anIOException, so the generic "could not connect" wrapper doesn't swallow it.nullerror stream (a 4xx/5xx with no body) now returns""instead of throwing an NPE.available() == 0short-circuit, which could wrongly return""for a real stream that just had no bytes buffered yet.makeAppEngineRequest).ReferralCustomerService.createStripeToken. That code was already removed onmasterin chore: remove deprecated, unused addCreditCardToUser function #381 (addCreditCardToUserremoval), so nothing is left to patch here.No unbounded reads remain in
src/main.Release plan: no backport to 8.8.x. Both halves of SEC-787 ship together in the next release from
master: the Stripe-path removal from #381 and this cap. Users get both by upgrading to that version. Note that the release includes the breakingaddCreditCardToUserremoval, so its version number should be chosen accordingly.Testing
New
RequestorTest(it extendsRequestorto reach the protected helper, the same patternErrorTestuses):client.address.retrieve(...)with a mockedHttpsURLConnection(viaEasyPost._vcrUrlFunction): a normal response deserializes, and both oversized cases throwHttpErrorPull Request Type
Please select the option(s) that are relevant to this PR.
🤖 Generated with Claude Code