Skip to content

SDKs send access keys and tokens to an address read from CS_CTS_HOST / CS_ZEROKMS_HOST — deprecate, then remove the environment overrides #1744

Open

Description

@coderdan

Background

CipherStash's SDKs talk to two services. CTS (CipherStash Token Service) swaps a credential for a short-lived token: an access key, a user's sign-in token (JWT) from an identity provider, or a CLI login. ZeroKMS, the CipherStash key service, takes that token and returns key material that the SDK turns into encryption keys.

The SDKs find both addresses from the workspace's region (service discovery), or from an address the program sets in code. They also read three environment variables that replace the address:

  • CS_CTS_HOST replaces the CTS address.
  • CS_ZEROKMS_HOST replaces the ZeroKMS address.
  • CS_VITUR_HOST is the old name for CS_ZEROKMS_HOST.

These variables were needed before service discovery existed. The Protect-to-Stack migration guide still says to keep them "only for a deliberately configured private or custom endpoint" (docs/migration/protect-dynamodb-to-stack.md:69).

Problem

What happens. When a program does not set an address in code, the SDK uses the variable if it is set, and service discovery only if it is not. Nothing in the program's code shows this. So whoever controls the process environment chooses where the SDK sends secrets:

  • CS_CTS_HOST gets the credential that is being swapped for a token. For AccessKeyStrategy that is the long-lived access key. For OidcFederationStrategy it is the user's JWT.
  • CS_ZEROKMS_HOST gets the token on every key request. It is a bearer token, so whoever holds it can use it against the real ZeroKMS until it expires. The client key stays in the program; ZeroKMS receives only the client id.

Both overrides accept plain http://. ZeroKmsEndpoint allows http and https (packages/stack-kms/src/endpoint.rs:95), and CS_CTS_HOST is parsed as any URL (packages/stack-auth/src/lib.rs:476). So a stale or mistyped variable can send the access key or tokens across the network unencrypted, with no attacker involved.

A wrong ZeroKMS address can lose data, silently. The SDK builds each encryption key from the key material ZeroKMS returns (DataKey::from_key_material, packages/stack-kms/src/client.rs:296). If CS_ZEROKMS_HOST points at another ZeroKMS (a test one left in an .env file, or one run by an attacker), the program encrypts data under keys the real ZeroKMS never issued. Every write succeeds. The data may never decrypt against the real ZeroKMS, and nobody finds out until they try to read it. An attacker's server would also see the metadata of every key request, such as keysets and contexts. It still could not decrypt the data, because it never receives the client key.

The variables are read by every strategy and every SDK:

Where Code
Rust stack-auth (AccessKeyStrategy, OidcFederationStrategy, the device-code and device-session strategies) cts_base_url_from_env, packages/stack-auth/src/lib.rs:474; called at access_key_strategy.rs:195, oidc_federation_strategy.rs:722, device_code/mod.rs:235, device_session_strategy.rs:247 and :313
Rust stack-kms, and so every stack-encrypt cipher over ZeroKMS base_url_from_env, packages/stack-kms/src/builder.rs:247; the names are in packages/stack-kms/src/vars.rs:8
Go SDK languages/golang/auth/strategy.go:44 (CS_CTS_HOST); languages/golang/encrypt/credentials.go:178 (CS_ZEROKMS_HOST, CS_VITUR_HOST)
@cipherstash/auth (npm) inherits the stack-auth behaviour; documented in languages/typescript/packages/auth/src/lib.rs:379

Impact. A variable can get into a process without anyone meaning it to. It can come from a shared .env file, a CI secret set for another job, a container platform's environment settings, or a dependency that sets variables. In each case the program's access key or tokens go to that address. The program still works if the address forwards requests, so nobody notices. AccessKeyStrategy checks that the token it gets back is for the expected workspace. That check does not stop the access key from being sent.

PR #1726 made reading credentials from the environment an explicit choice in stack-encrypt (StackCipher::with_detected_credentials()). The addresses those credentials are sent to are still read from the environment, even on the builder path where the caller names every credential.

Why nothing catches it. This is the documented behaviour, and tests depend on it: the Go tests and the @cipherstash/auth tests point the SDK at mock servers by setting these variables (for example languages/golang/encrypt/credentials_test.go:412).

Who may rely on it. Not verified: deployments that use a private or custom CipherStash endpoint, CipherStash's own staging and development setups, and customers who set the variables for Protect and never removed them. That is why this needs a deprecation period rather than an immediate removal.

Proposal

  1. Refuse plain http now (can ship on its own). An address from any of these variables that uses http is refused, unless its host is localhost or a loopback address (which local tests and mock servers use). The error names the variable and never prints its value.
  2. Warn (can ship on its own). When an SDK uses an address from one of these variables, it tells the program once, in that SDK's normal way of reporting. The message names the variable, says it will stop working, and says how to set the address in code. It never prints the value: a URL can contain a username and password.
  3. Then remove the overrides. The SDKs send credentials and tokens only to an address the program sets in code, or to the address service discovery gives for the workspace's region. A program that does neither never reads CS_CTS_HOST, CS_ZEROKMS_HOST or CS_VITUR_HOST.
  4. Change every SDK together: the Rust crates (stack-auth, stack-kms, stack-encrypt), the Go SDK, and @cipherstash/auth. A program must not get a different answer depending on which SDK it uses. Each removal is a breaking change, with upgrade steps in that package's changelog.
  5. Tests and examples in this repository that use the variables to reach a mock server set the address in code instead.
  6. Docs and skills stop telling users to keep the variables. That includes the migration guide and any skills/*/SKILL.md that mentions them.

Not verified: whether cipherstash-client, which @cipherstash/protect-ffi uses and which lives in another repository, reads the same variables. Check it before closing this issue, and file an issue there if it does.

Activity

  1. added
    enhancement
    rust
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SDKenhancementrust

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions