Skip to content

Go SDK: one wrong character in CS_CLIENT_KEY makes NewClient hang at full CPU, past its context deadline #1850

In progress

Description

@auxesis

Background

The Go SDK is in languages/golang in this repository. It encrypts values in a Go program, and gets its keys from ZeroKMS, CipherStash's key management service. In November 2026 we audited version v0.1.0-rc.7 by building programs against a dev workspace and PostgreSQL 17 with EQL (Encrypt Query Language) v4.

Problem

We changed one character at the end of a real CS_CLIENT_KEY and called NewClient with a context deadline. NewClient did not return. The process used a full CPU core, and was stopped after 10 minutes.

A typo in a deployment's secret hangs the service at start, instead of failing with a clear error.

Proposal

  1. Validate the client key's encoding before any expensive step, and return ErrConfig that names CS_CLIENT_KEY.
  2. Make sure NewClient returns when its context ends, whatever the guest is doing.
  3. Add a test with a malformed key and a short deadline.

Evidence

Verified by running code. The key with one wrong character came from a real client key.

Status

#1914 does part of this issue. It does not close it.

  • Done in fix(golang): refuse a malformed client key at once, with ErrConfig #1914: steps 1 and 3. stack-kms refuses a client key whose permutations are invalid, before any key is derived. encrypt.NewClient checks the key's encoding first, and returns the new encrypt.ErrConfig, with Help that names CS_CLIENT_KEY. A test covers a malformed key.
  • Left to do: step 2. NewClient does not yet return when its context ends while the guest is still working.

Step 2 is left because stopping a running guest needs wazero's WithCloseOnContextDone. That option was removed from the encrypt runtime on 2026-11-23, because it made decrypt cost about 4 times the CPU. The other way is to let NewClient return while the stuck step keeps running in a goroutine. That leaves a goroutine and one CPU core busy for as long as the guest runs.

#1911 tracks the same malformed-key problem in the other language SDKs.

Metadata

Metadata

Assignees

Labels

GolangSDKbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions