Repository navigation
Description
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_HOSTreplaces the CTS address.CS_ZEROKMS_HOSTreplaces the ZeroKMS address.CS_VITUR_HOSTis the old name forCS_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_HOSTgets the credential that is being swapped for a token. ForAccessKeyStrategythat is the long-lived access key. ForOidcFederationStrategyit is the user's JWT.CS_ZEROKMS_HOSTgets 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
- Refuse plain
httpnow (can ship on its own). An address from any of these variables that useshttpis refused, unless its host islocalhostor a loopback address (which local tests and mock servers use). The error names the variable and never prints its value. - 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.
- 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_HOSTorCS_VITUR_HOST. - 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. - Tests and examples in this repository that use the variables to reach a mock server set the address in code instead.
- Docs and skills stop telling users to keep the variables. That includes the migration guide and any
skills/*/SKILL.mdthat 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