Skip to content

Other language SDKs may hang on a malformed client key, as the Go SDK did in #1850 #1911

In progress

Description

@auxesis

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-ffi builds its secret key from the client key bytes in languages/typescript/packages/protect-ffi/crates/protect-ffi/src/client_options.rs, at line 158. It then goes through cipherstash-client 0.42.3 and recipher 0.2.3. ClientKey::from_bytes in cipherstash-client does not check the permutations. This covers the default entry and the wasm-inline entry.
  • EQL's test crates. packages/eql/Cargo.lock also resolves cipherstash-client 0.42.3 and recipher 0.2.3.
  • The published eql-bindings crate. Its stack-encrypt feature takes stack-encrypt, and through it stack-kms, from crates.io. It gets the fix only after a stack-kms release 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

  1. 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.
  2. 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 that protect-ffi uses, or in protect-ffi before it calls them.
  3. Release stack-kms with the fix from Go SDK: one wrong character in CS_CLIENT_KEY makes NewClient hang at full CPU, past its context deadline #1850, so that the published eql-bindings gets it.
  4. Check whether recipher 0.3.1 has the same loop. The root Cargo.lock resolves that version.

Evidence

Metadata

Metadata

Assignees

Labels

JavaScriptSDKbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions