Safeguard
Security Guides•

What should a self-hosted Nx remote cache server get right?

Nx lets you build your own remote cache from an OpenAPI spec. A checklist for tokens, read only access, TLS and one variable you must never set.

Safeguard Security Team
3 min read

A self-hosted Nx cache must authenticate every request, separate read tokens from write tokens, serve over HTTPS and never be run with TLS validation disabled. Nx hands you the API contract but leaves storage, retrieval and authentication to you, so those controls are your job.

What Nx gives you and what it does not

The Nx documentation describes two options: a managed service, or building your own server to an OpenAPI specification. The server manages storage, retrieval and authentication, and may be written in any language as long as it matches the spec. The endpoints transfer tar archives as binary data.

The spec defines two operations: upload a task output, and download one, keyed by task hash. It uses bearer token authentication. Its responses include missing or invalid token, access forbidden (for example a read only token used to write), a conflict when you try to override an existing record, and not found.

Those response codes already describe a sound model: write once per hash, and distinguish read from write permissions.

Checklist

ControlWhat to do
AuthenticationRequire the bearer token on every request, both reads and writes
Read vs writeIssue read only tokens to developers and PR builds, write tokens to protected CI
ImmutabilityHonor the conflict response: never overwrite an existing hash
TransportHTTPS only, with a certificate trusted by clients
StorageEncrypt at rest, restrict who can read the bucket or disk
RetentionExpire old entries, keep a way to wipe the cache quickly
LoggingRecord writer identity, hash and time
NetworkReach the server from build networks only

The environment variables

Nx uses an environment variable to point at your server and another for its access token. A third is documented as able to turn off TLS certificate validation, by setting it to zero. Do not set it. It disables certificate checks for the whole Node process, not just the cache connection, so a network attacker could impersonate your cache or other services. If your certificate is internal, install your certificate authority in the runner instead.

Token handling

  1. Create separate tokens for read and write.
  2. Store write tokens in a secret manager and expose them only to protected branch jobs.
  3. Rotate on a schedule and after any suspected leak.
  4. Never print tokens. Nx stores terminal output in cache entries, so a printed token can be saved and replayed.

Recovery plan

Decide before you need it how to wipe the cache. A poisoned entry is keyed by a hash that real builds will compute, so you cannot fix it by waiting. Plan for clearing storage, rotating tokens and rebuilding release artifacts from source.

When to choose managed instead

If you cannot staff the checklist above, a managed service shifts some of it to the provider. Evaluate it with the same questions: who can write, how are tokens scoped, what is the deletion process, and where is data stored.

Quick check

Does Nx verify cache entries against a signature?

The spec describes hash keyed storage and bearer tokens. It does not describe artifact signing, so enforce integrity with your server design and access control.

Is an internal certificate a reason to disable TLS validation?

No. Install your internal certificate authority on the build machines instead.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.