Repository navigation
Description
Background
Every CipherStash SDK needs a client key. The client key contains key material and some permutations. A permutation is a list of positions. The SDK uses the permutations to derive the keys that encrypt values and build search terms.
The Go SDK and the TypeScript SDK both parse the client key in Rust. The Go SDK uses the stack-kms crate in this repository. The TypeScript SDK (@cipherstash/stack, through @cipherstash/protect-ffi) uses the cipherstash-client crate from crates.io.
Problem
In the Go SDK, one wrong character in CS_CLIENT_KEY can make a permutation list one position twice. Then NewClient runs at full CPU and does not return. #1850 describes this.
The loop is in Permutation::permute_slice_mut, in the zerokms-keyset crate (version 0.3.4, src/permutation.rs, line 57). The recipher crate, version 0.2.3, has the same loop at the same line. A position listed twice makes the loop run forever. A position out of range makes it panic.
The fix for #1850 makes stack-kms refuse a client key whose permutations are invalid. That fix covers the Go SDK only. These paths do not get it:
- The TypeScript SDK.
protect-ffibuilds its secret key from the client key bytes inlanguages/typescript/packages/protect-ffi/crates/protect-ffi/src/client_options.rs, at line 158. It then goes throughcipherstash-client0.42.3 andrecipher0.2.3.ClientKey::from_bytesincipherstash-clientdoes not check the permutations. This covers the default entry and thewasm-inlineentry. - EQL's test crates.
packages/eql/Cargo.lockalso resolvescipherstash-client0.42.3 andrecipher0.2.3. - The published
eql-bindingscrate. Itsstack-encryptfeature takesstack-encrypt, and through itstack-kms, from crates.io. It gets the fix only after astack-kmsrelease that includes it.
We have not reproduced the hang in the TypeScript SDK. A program there may hang, or it may panic, or a check we have not found may stop the bad key first.
Proposal
- Reproduce the problem in the TypeScript SDK, with a made-up client key that lists one position twice. Use no real key. Record whether the program hangs, panics, or returns an error.
- If it hangs or panics, refuse a client key whose permutations are invalid before any key is derived. Return an error that names
CS_CLIENT_KEY. The fix belongs in the crates thatprotect-ffiuses, or inprotect-ffibefore it calls them. - Release
stack-kmswith the fix from Go SDK: one wrong character inCS_CLIENT_KEYmakesNewClienthang at full CPU, past its context deadline #1850, so that the publishedeql-bindingsgets it. - Check whether
recipher0.3.1 has the same loop. The rootCargo.lockresolves that version.
Evidence
- The Go SDK hang and its cause are in Go SDK: one wrong character in
CS_CLIENT_KEYmakesNewClienthang at full CPU, past its context deadline #1850. The Go reproduction ran with a made-up key and no network. - The line numbers in
zerokms-keyset0.3.4,recipher0.2.3, andprotect-ffiwere read from the source. - The
cipherstash-clientline numbers were read from version 0.42.2, because the 0.42.3 source was not available locally. - The versions come from
languages/typescript/packages/protect-ffi/Cargo.lockandpackages/eql/Cargo.lockonmain.
Activity
fix(stack-kms): refuse a keyset that does not parse with a fixed message
test(stack): give the WASM credential test a key with real permutations
fix(protect-ffi): require p3 to have 33 entries, as recipher does