Repository navigation
security: validate peer-supplied catalog items and bound replication chunk downloads - #11
Merged
Merged
Conversation
…eplication H2: replication stored whatever STAC item a peer returned after checking only the hash format of its chunk list, and wrote it with INSERT OR REPLACE keyed on the peer-chosen id and collection, so a peer could overwrite a locally ingested item or file data under a collection it was never allowed to write. - validate_remote_item files every peer item under the collection we asked for, checks the id, requires the earthgrid tile properties to be unsigned integers and bounds them, and caps the chunk list. Duplicate hashes, partial tile geometry and a hash count above the tile grid stay accepted, because local ingestion produces all three. - items gained an origin column (safe migration, column appended last so no positional reader shifts). add_remote_item only ever inserts remote rows or updates an existing remote row, so a local item can never be overwritten; local add_item still writes origin local. - an item already held as a non-remote row is never written by replication, and its missing chunks are repaired using its own hash list, not the peer's. H4: the item loop buffered every chunk body before hashing, with no size cap, one task per hash and no dedup, so a large item could exhaust memory. - responses above 32 MiB are refused by declared length and by a bounded read; each body is hash-verified and stored as it arrives and the buffer is dropped, with the list deduplicated and spawned in batches so live tasks stay bounded regardless of list length. A storage-limit result stops the run.
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 1 of the security review: the remote-item validation gate (H2) and the bounded chunk download (H4). One commit,
b8105bc, on top ofmaster(b0ca845).H2 - peer-supplied items were stored almost unchecked
validate_remote_itemruns before anything is stored: the item is filed under the collection we asked the peer for whatever its owncollectionfield says, the id must match^[A-Za-z0-9._:-]{1,128}$, eachearthgrid:*tile property must be an unsigned integer within sanity bounds, and the chunk list is capped. Duplicate hashes, partial tile geometry and a hash count above the tile grid are deliberately accepted, because local ingestion produces all three (identical tiles share a hash; band-level items list every band;ingest_filewrites no geometry).itemsgained anorigincolumn, appended last with aPRAGMA table_infoguarded migration so no positional reader shifts.add_remote_iteminserts remote rows and only updates an existing row that is itself remote, so a peer can never overwrite a locally ingested item; localadd_itemstill writesorigin = 'local'even when it replaces a remote row.H4 - unbounded chunk download
Content-Lengthand by a bounded read, so a lying or absent header cannot stream unbounded.Verification
cargo build --releaseclean, zero warnings;cargo test197 passed, 0 failed, 1 ignored, plus 2 ignored doc-tests (10 new tests cover the gate: collection filed as requested, duplicate hashes accepted, out-of-range and non-integer properties rejected, bad ids rejected, hash list capped but not tied to the tile grid).tile_rowslower bound, invalid local hashes reaching a request URL and a lossy catalog decode reading as a complete item. The findings that remain open are listed below./api/health200, anonymousGET /api/fetch/queue401, keyed GET 200 with 100 jobs,/dashboard200, node still registered, and a queued fetch completed1/1with no error.Known limitations, not addressed here
store.putrefuses, so up to ten capped bodies can be fetched and discarded first. The limit source is not reachable from the replicator today.resize_storageupdates the eviction limit inAppStatebut neverChunkStore.limit_bytes, so replication keeps enforcing the startup limit until restart. Pre-existing.ingest_file's caller-supplied chunk size or an unboundedingest_rastergeometry can still produce a chunk a peer will refuse.width * heightis still computed asu32and can overflow, small consistent geometry can underflow an offset,earthgrid:band_hashesnested lists escape both caps, raw concatenation has no output cap, and zero spatial dimensions reach a float divide. That is the next cluster's work.