ContentRangeHeaderValue "to" must always be less than "length"
See original GitHub issueSummary
The ContentRangeHeaderValue
constructor allows the creation of an invalid (range) instance.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range
<range-start>
and <range-end>
are zero-indexed & inclusive
This means that to
must always be a maximum of length - 1
Motivation and goals
Prevent people (like me) to create invalid content range headers.
In scope
None.
Out of scope
None.
Risks / unknowns
People sending invalid requests to forgiving servers might be broken.
Examples
I think this line https://github.com/dotnet/aspnetcore/blob/fd1891536f27e959d14a140ff9307b6a21191de9/src/Http/Headers/src/ContentRangeHeaderValue.cs#L41
Should be changed from
if ((to < 0) || (to > length))
to
if ((to < 0) || (to > Math.Max(0, length-1)))
Issue Analytics
- State:
- Created a year ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Does a HTTP resource that accepts range requests always ...
A Range of e.g. 123-500 is valid even if the size of the entity is less than 500, in which case as many...
Read more >Caching with Azure Front Door
Override always: Azure Front Door always overrides with the cache duration, meaning that it caches the contents for the cache duration ignoring ...
Read more >HTTP/1.1, part 5: Range Requests and Partial Responses
If a syntactically valid byte-range-set includes at least one byte-range-spec whose first-byte-pos is less than the current length of the entity-body, or at ......
Read more >HTTP/1.1, part 5: Range Requests and Partial Responses
A cache that does not support the Range and Content-Range headers MUST NOT ... value is less than its first-byte-pos value, or whose...
Read more >Public R2 bucket doesn't handle range requests well
When accessing my files through public access with a range header, R2 always responds with the proper amount of bytes but never with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like this discussion has been quiet for a while, so I’m going to go ahead and open a PR.
I was checking the file and it looks like we have the same validation here https://github.com/dotnet/aspnetcore/blob/fd1891536f27e959d14a140ff9307b6a21191de9/src/Http/Headers/src/ContentRangeHeaderValue.cs#L421-L425
It will be useful to have a special scenario where this issue is triggered.