diff --git a/SECURITY.md b/SECURITY.md index f3d73f7e..c4e06d20 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -26,7 +26,7 @@ This policy covers the `@cachekit-io/cachekit` and `@cachekit-io/cachekit-core-t This SDK does not implement LZ4. `ByteStorage.unpack` in both bindings — `cachekit-core-ts` (NAPI, native) and `cachekit-core-wasm` (Workers) — is a thin -wrapper over cachekit-core's `ByteStorage::retrieve` → `StorageEnvelope::extract`, +wrapper over cachekit-core's `ByteStorage::retrieve_data` → `StorageEnvelope::extract`, which bounds the decompressed output at `min(512 MiB, 1000 × compressed_len)` _before_ decompressing. The envelope's self-declared `original_size` is not trusted, and the xxHash3-64 checksum is unkeyed so it does not gate a forging diff --git a/packages/cachekit-core-ts/Cargo.lock b/packages/cachekit-core-ts/Cargo.lock index cb55978b..ebfe9129 100644 --- a/packages/cachekit-core-ts/Cargo.lock +++ b/packages/cachekit-core-ts/Cargo.lock @@ -83,9 +83,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cachekit-core" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9217fe47d4024d7b0d1dda460bbcfc0f613bd80fb94c4fbbc4e7e6d829d7342" +checksum = "5f41b00d71075d124321101c2091902f428b7861cc12202177bd1dd510646016" dependencies = [ "aes", "aes-gcm", diff --git a/packages/cachekit-core-ts/Cargo.toml b/packages/cachekit-core-ts/Cargo.toml index 3cb098ba..c8c39f37 100644 --- a/packages/cachekit-core-ts/Cargo.toml +++ b/packages/cachekit-core-ts/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib"] # binding runs every call on the JS thread and needs none of napi4's features. napi = { version = "3", default-features = false, features = ["napi3", "dyn-symbols"] } napi-derive = "3" -cachekit-core = { version = "0.7.0", features = ["encryption"] } +cachekit-core = { version = "0.7.5", features = ["encryption"] } # Cache-key BLAKE2b-256 (blake2b256Hex). The 0.10 line builds on the digest 0.10 # that cachekit-core's sha2 and hmac already bring in, so it adds this one crate; # 0.11 would add a second digest stack. It is also the line cachekit-core's own diff --git a/packages/cachekit-core-ts/src/lib.rs b/packages/cachekit-core-ts/src/lib.rs index c8ca770f..af4975f5 100644 --- a/packages/cachekit-core-ts/src/lib.rs +++ b/packages/cachekit-core-ts/src/lib.rs @@ -160,9 +160,9 @@ impl ByteStorage { env: &'env Env, packed: Uint8Array, ) -> Result> { - let (data, _format) = self + let data = self .inner - .retrieve(&packed) + .retrieve_data(&packed) .map_err(|e| Error::new(Status::GenericFailure, e.to_string()))?; copy_to_js(env, &data) } diff --git a/packages/cachekit-core-wasm/Cargo.lock b/packages/cachekit-core-wasm/Cargo.lock index 43d6ee3c..26d8bf97 100644 --- a/packages/cachekit-core-wasm/Cargo.lock +++ b/packages/cachekit-core-wasm/Cargo.lock @@ -71,9 +71,9 @@ checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" [[package]] name = "cachekit-core" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9217fe47d4024d7b0d1dda460bbcfc0f613bd80fb94c4fbbc4e7e6d829d7342" +checksum = "5f41b00d71075d124321101c2091902f428b7861cc12202177bd1dd510646016" dependencies = [ "aes", "aes-gcm", diff --git a/packages/cachekit-core-wasm/Cargo.toml b/packages/cachekit-core-wasm/Cargo.toml index eac781b9..11661912 100644 --- a/packages/cachekit-core-wasm/Cargo.toml +++ b/packages/cachekit-core-wasm/Cargo.toml @@ -22,7 +22,7 @@ wasm-bindgen = "=0.2.121" # accept Uint8Array[] (previous master keys) across the boundary. Exact-pinned # to the release paired with wasm-bindgen 0.2.121 above. js-sys = "=0.3.98" -cachekit-core = { version = "0.7.0", features = ["encryption"] } +cachekit-core = { version = "0.7.5", features = ["encryption"] } # Wipes the owned previous-master-key staging buffers and the cache-key hash # input on drop (the NAPI crate borrows and never copies; this crate must copy # out of JS memory). Already in the tree transitively via cachekit-core — same diff --git a/packages/cachekit-core-wasm/src/lib.rs b/packages/cachekit-core-wasm/src/lib.rs index ba6cfb23..d30f88da 100644 --- a/packages/cachekit-core-wasm/src/lib.rs +++ b/packages/cachekit-core-wasm/src/lib.rs @@ -124,8 +124,7 @@ impl ByteStorage { /// Unpack data, verifying xxHash3-64 integrity and decompressing LZ4. pub fn unpack(&self, packed: &[u8]) -> Result, JsError> { self.inner - .retrieve(packed) - .map(|(data, _format)| data) + .retrieve_data(packed) .map_err(|e| JsError::new(&e.to_string())) } diff --git a/packages/cachekit/test/protocol/decode-bounds.protocol.test.ts b/packages/cachekit/test/protocol/decode-bounds.protocol.test.ts index 59e37bca..f81dfee7 100644 --- a/packages/cachekit/test/protocol/decode-bounds.protocol.test.ts +++ b/packages/cachekit/test/protocol/decode-bounds.protocol.test.ts @@ -7,8 +7,9 @@ * invalidation-event decoder. Spec: protocol/spec/interop-mode.md#decode-bounds. * The bounds themselves are `assertDecodeDepth`. The * ByteStorage envelope is decoded in Rust instead: `unpack` reaches - * cachekit-core's `ByteStorage::retrieve`, which pre-scans the envelope bytes - * before decoding them (cachekit-core 0.7.0 and later). The envelope entry + * cachekit-core's `ByteStorage::retrieve_data`, which checks every length the + * envelope declares against its bytes before reading them, and pre-scans any + * envelope its one-pass decode declines (cachekit-core 0.7.5). The envelope entry * point is covered in both lanes: the NAPI `unpack` here, and the wasm * `unpack` inside workerd in test/workers/decode-bounds.workers.test.ts. Both * share their assertions through test/fixtures/decode-bounds-vectors.ts.