Repository navigation
security: cap reconstruction memory, verify peer chunks, allowlist item CRS text - #13
Merged
Merged
Conversation
…S text H3: peer-supplied earthgrid properties sized buffers directly. Reconstruction now enforces a byte budget with checked arithmetic before any allocation, caps the chunk references across the top level and the nested band lists, rejects zero dimensions before the geotransform fallback, bounds the band-name list, and limits in-flight reconstructions so several requests cannot allocate at once. Reconstruction runs under spawn_blocking with the store locked per read instead of for the whole job. M6: the download path stored a peer chunk without checking its hash - the one path that skipped what get_chunk and replication both do. It is now hashed and a mismatch is discarded and logged. M7: spatial references were built with SpatialRef::from_definition, so an item-provided earthgrid:crs could be a URL or a path. CRS text now passes a lexical allowlist (EPSG:code, or WKT with one of six roots, with fragments that can carry an instruction refused outside quoted text), and a value that passes the gate but cannot be built is an error rather than an output silently written without a CRS.
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.
What this fixes
Cluster 2 of the security review: reconstruction allocation caps (H3), the missing hash check on the peer-chunk download path (M6), and the CRS allowlist that replaces
SpatialRef::from_definition(M7). One commit,57d0d27, on top ofmaster(b0ca845).H3 - peer properties sized buffers directly
MAX_RECONSTRUCT_BYTESbudget is enforced before allocation in the tiled, raw and NDVI paths, withchecked_mul/checked_addon u64, so the u32width * heightoverflow and the tile-offset underflow are gone. Zero dimensions are rejected before the geotransform fallback, which otherwise divides by zero in floating point. Chunk references are counted across the top level and every nestedearthgrid:band_hasheslist against one cap,earthgrid:band_namesis bounded before it is cloned, and the NDVI path requires the sample count to equal the computed pixel count before the raster buffer exists.spawn_blockingwith the store locked per chunk read rather than for the whole job, and a process-wide limit of two keeps several requests from allocating at once.M6 - one path stored a peer chunk unverified
The download handler's peer prefetch now hashes each chunk and discards a mismatch with a message naming the hash, matching what
get_chunkand replication already do.M7 - item text could choose the CRS
earthgrid:crsreachedSpatialRef::from_definition, which accepts a URL or a local path and so bypassed the outbound URL policy. CRS text now passes a lexical allowlist:EPSG:<1-6 digits>, or WKT whose first token is one of six roots, with fragments that can carry an instruction (://,+init,+proj,+nadgrids,/vsi, a backslash, a control character) refused anywhere, and@/|refused only outside quoted text so legitimate WKT names survive. A value that passes the gate but cannot be built is an error naming the value and the GDAL error, instead of an output written silently without a CRS.Verification
cargo build --releaseclean, zero warnings;cargo test208 passed, 0 failed, 1 ignored, plus 2 ignored doc-tests (21 new tests across the four correction rounds).@/|rule, which rejected valid WKT and is fixed in the fourth. Residuals are listed below./api/health200 and a real item downloads as a valid GeoTIFF -GET /api/download/sentinel-2-l2a/S2A_34SFH_20260713_1_L2A_B08returned 228,357,949 bytes ofimage/tiff; application=geotiff, read back as 10980x10980, 16 bps, deflate.Known limitations, not addressed here
+projinside quoted text is refused, and a spelling that evades a literal match is not proven harmless.OSRSetFromUserInputstays indirectly reachable through the openEO warp path, where the CRS is not item text.