Skip to content

fix(range-requests): return 416 when the range starts at or past the end of the body - #3608

Open
0z5a wants to merge 1 commit into
GoogleChrome:v7from
0z5a:fix/range-start-past-end-416
Open

0z5a wants to merge 1 commit into
GoogleChrome:v7from
0z5a:fix/range-start-past-end-416

Conversation

@0z5a

@0z5a 0z5a commented Nov 15, 2026

Copy link
Copy Markdown

Fixes #3607

calculateEffectiveBoundaries() rejected an end past the end of the blob and a negative start, but never checked whether start itself was past the end. A request such as Range: bytes=256- (or bytes=300-) against a 256-byte cached response therefore produced a 206 Partial Content with an empty body and an invalid Content-Range: bytes 256-255/256 (or bytes 300-255/256; see RFC 9110 §14.4).

Per RFC 9110 §14.1.2 / §14.2 (formerly RFC 7233 §2.1) a byte range whose first-pos is not less than the length of the representation is unsatisfiable and should get a 416 Range Not Satisfiable, which is what createPartialResponse() already returns for other unsatisfiable ranges. This change adds a start >= blobSize check next to the existing ones, so these requests now go through the same range-not-satisfiable path. Ranges that start inside the body (including bytes=0-, open-ended and suffix ranges) are unchanged.

Tests: added a case to test-calculateEffectiveBoundaries.mjs (start equal to and larger than the blob size throws range-not-satisfiable) and a case to test-createPartialResponse.mjs (bytes=256- and bytes=257- return 416). Both fail without the change and pass with it; the other range-requests tests still pass.

I don't have Chrome on this machine, so I could not use the browser-based service worker test runner. I ran the workbox-range-requests SW tests in Node 24 with mocha against the sw-bundle.js served by the repo's test server, in both development and production builds: without the change the two new tests fail (19 passing / 2 failing in development, 17 passing / 2 pending / 2 failing in production), and with it everything passes (21 passing; 19 passing / 2 pending). Please treat CI as authoritative.

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

…end of the body

calculateEffectiveBoundaries() rejected an end past the blob and a
negative start, but not a start at or past the end of the blob, so
"bytes=256-" on a 256-byte response produced a 206 with an empty body
and "Content-Range: bytes 256-255/256". Treat such ranges as
unsatisfiable, like the other out-of-range cases.

This branch has not been deployed

No deployments
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.

workbox-range-requests: Range starting at or after the end of the body returns an empty 206 with an invalid Content-Range

1 participant