Skip to content

fix(jwks): enforce maxResponseSize while reading the response - #32

Merged
ExorTek merged 1 commit into
masterfrom
fix/jwks-response-limit
Aug 6, 2026
Merged

fix(jwks): enforce maxResponseSize while reading the response#32
ExorTek merged 1 commit into
masterfrom
fix/jwks-response-limit

Conversation

@ExorTek

@ExorTek ExorTek commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Independent of the Redis series — can merge in any order relative to it.

maxResponseSize was checked against the Content-Length header, and then again after res.text() had already resolved. A response that omits that header — any chunked reply, which the server chooses — skipped the first check, and by the time the second ran the whole body was in memory. The limit described a response we had finished buffering rather than one we refused to buffer.

readCapped now reads the body stream with a running byte count and stops at the first chunk that crosses the limit, cancelling the remainder so the connection is not left draining. Falls back to text() when the response exposes no stream.

Measured — 40 MiB streamed, 64 KiB limit configured:

before after
bytes read before giving up 40 MiB 1 MiB
heap growth ~42 MiB ~1.3 MiB

Regression test covers a chunked response with no Content-Length, and asserts the stream is cancelled rather than drained.

The size limit was applied to the `Content-Length` header and then re-checked
after `res.text()` had resolved. A response without that header — any chunked
reply, which the server chooses — skipped the first check, and by the time the
second one ran the whole body was already in memory. The limit described a
response we had finished buffering rather than one we refused to buffer.

`readCapped` reads the body stream with a running byte count and stops at the
first chunk that crosses the limit, cancelling the remainder so the connection
is not left draining. Falls back to `text()` when the response exposes no
stream.

Measured against a server streaming 40 MiB with a 64 KiB limit configured:
heap growth drops from ~42 MiB to ~1 MiB, and the client disconnects instead
of reading to completion.
Copilot AI lite review requested due to automatic review settings August 6, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ExorTek
ExorTek merged commit 8097e69 into master Aug 6, 2026
3 checks passed
@ExorTek
ExorTek deleted the fix/jwks-response-limit branch August 6, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants