Cap per-tile compressed byte_count in HTTP COG reader (fixes #1536)#1538
Open
brendancol wants to merge 1 commit intomainfrom
Open
Cap per-tile compressed byte_count in HTTP COG reader (fixes #1536)#1538brendancol wants to merge 1 commit intomainfrom
brendancol wants to merge 1 commit intomainfrom
Conversation
A crafted TIFF served over HTTP can declare any TileByteCount it wants. _fetch_decode_cog_http_tiles passed those values straight into read_ranges_coalesced, so a single Range GET ended up sized by the attacker's byte counts. A forged COG with four tiles each claiming 100 MB drove the client into one 100 MB Range request. Bound per-tile compressed bytes against MAX_TILE_BYTES_DEFAULT (256 MiB) before building fetch_ranges. Override via XRSPATIAL_COG_MAX_TILE_BYTES. The local-mmap path is bounded by file size, so the cap stays HTTP-only. New tests in test_security.py::TestHTTPTileByteCountCap cover the reject path, the env override, and the local-read no-op.
There was a problem hiding this comment.
Pull request overview
This PR mitigates a network DoS vector in the HTTP Cloud-Optimized GeoTIFF (COG) read path by enforcing a configurable per-tile cap on compressed TileByteCounts before issuing HTTP Range requests.
Changes:
- Added a default 256 MiB per-tile compressed byte cap for HTTP COG reads, overridable via
XRSPATIAL_COG_MAX_TILE_BYTES, and enforced during_fetch_decode_cog_http_tiles. - Raised a clear
ValueErrorwhen a tile’s declaredTileByteCountexceeds the configured cap. - Added regression tests that forge
TileByteCountsand validate rejection behavior, env override behavior, and that local reads are unaffected.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
xrspatial/geotiff/_reader.py |
Introduces the HTTP per-tile compressed-byte cap and enforces it while building fetch ranges. |
xrspatial/geotiff/tests/test_security.py |
Adds regression tests using a mocked HTTP source and a helper to patch TileByteCounts. |
.claude/sweep-security-state.csv |
Updates the security sweep tracking entry for the geotiff module to reflect this fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # only exercise the HTTP path through a mock _HTTPSource. | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| import threading |
Comment on lines
+1343
to
+1348
| # Each tile's compressed size is bounded against MAX_TILE_BYTES BEFORE | ||
| # the fetch list is built. A crafted COG can claim arbitrarily large | ||
| # TileByteCounts; without this guard the HTTP layer would issue a | ||
| # Range request sized by the attacker's value (issue #1536). The cap | ||
| # is overridable via XRSPATIAL_COG_MAX_TILE_BYTES; the local-mmap | ||
| # path is naturally bounded by file size and does not need this check. |
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.
Summary
MAX_TILE_BYTES_DEFAULT = 256 << 20per-tile compressed-byte cap in_reader.py, overridable viaXRSPATIAL_COG_MAX_TILE_BYTES._fetch_decode_cog_http_tileswhosebyte_countexceeds the cap, with a ValueError that names the offending value.TestHTTPTileByteCountCapcover the reject path, the env override, and confirm local reads stay unaffected.Fixes #1536. Found during the May 2026 security sweep on geotiff.
Background
_fetch_decode_cog_http_tilesbuiltfetch_rangesdirectly frombyte_counts[tile_idx]with no validation. With the range coalescer from #1534 in front of it, a crafted TIFF (or a malicious server) could drive the client into arbitrarily large Range GETs. Locally, a forged COG with four tiles each claiming 100 MB drove the client into one 100 MB Range request; the math scales linearly with the attacker's claimed value.Local-mmap reads are bounded by file size (slicing past EOF silently truncates), so the cap is HTTP-only.
Test plan
pytest xrspatial/geotiff/tests/test_security.py -v-- 30 passed (5 new, 25 existing)pytest xrspatial/geotiff/tests/ -q(skipping unrelated matplotlib palette failure intest_features.py) -- 823 passed, 2 skippedtest_normal_cog_still_reads)XRSPATIAL_COG_MAX_TILE_BYTESlifts the cap (test_env_override_lifts_cap)test_local_path_unaffected_by_cap-- cap of 1 byte, local read succeeds)